prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Unknown stemmer language: 

What it means

stem(varchar, varchar) applies a Snowball stemmer for a specific two-character language code. The engine keeps a fixed map (STEMMERS) of supported languages; if the supplied language string is not a key in that map, it throws INVALID_FUNCTION_ARGUMENT. The language argument must be one of the supported ISO-639-1 codes (e.g. 'en', 'de', 'fr', 'es', 'it', 'ru').

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/WordStemFunction.java:95

    @Description("returns the stem of a word in the English language")
    @ScalarFunction
    @LiteralParameters("x")
    @SqlType("varchar(x)")
    public static Slice wordStem(@SqlType("varchar(x)") Slice slice)
    {
        return wordStem(slice, new EnglishStemmer());
    }

    @Description("returns the stem of a word in the given language")
    @ScalarFunction
    @LiteralParameters("x")
    @SqlType("varchar(x)")
    public static Slice wordStem(@SqlType("varchar(x)") Slice slice, @SqlType("varchar(2)") Slice language)
    {
        Supplier<SnowballStemmer> stemmer = STEMMERS.get(language);
        if (stemmer == null) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Unknown stemmer language: " + language.toStringUtf8());
        }
        return wordStem(slice, stemmer.get());
    }

    private static Slice wordStem(Slice slice, SnowballStemmer stemmer)
    {
        stemmer.setCurrent(slice.toStringUtf8());
        return stemmer.stem() ? utf8Slice(stemmer.getCurrent()) : slice;
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use a supported two-letter lowercase code, e.g. stem('running', 'en').
  2. Normalize the input: lower(substr(lang, 1, 2)) before calling stem.
  3. Check the supported language list in WordStemFunction (the STEMMERS map) and pick from it.
  4. For unsupported languages (e.g. Chinese), use a different tokenization/analysis path rather than stem().

Example fix

// before
SELECT stem('running', 'ENGLISH');
// after
SELECT stem('running', 'en');
Defensive patterns

Strategy: validation

Validate before calling

-- restrict language to supported 2-letter codes
SELECT CASE WHEN lang IN ('en','de','fr','es','it','pt','ru','nl','sv','da','no','fi','hu','ro','tr') THEN stem(txt, lang) ELSE stem(txt, 'en') END;

Type guard

boolean isSupportedStemmerLanguage(String lang) {
    return lang != null && lang.length() == 2 && lang.equals(lang.toLowerCase(java.util.Locale.ROOT));
}

Try / catch

try { stemmed = stem(txt, lang); } catch (PrestoException e) { if (e.getErrorCode().getName().equals("INVALID_FUNCTION_ARGUMENT")) { stemmed = txt; } else { throw e; } }

Prevention

When it happens

Trigger: Calling stem(text, 'english'), stem(text, 'EN'), stem(text, 'xx'), or any code not in the STEMMERS map — including full language names, wrong case, or codes for languages without a registered Snowball stemmer.

Common situations: Users pass human-readable language names instead of 2-letter codes; country-vs-language code mix-ups (e.g. 'us' instead of 'en'); uppercase codes from config files; unsupported languages like 'zh' that have no Snowball stemmer in the map.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/30eb4e4db4f6c509. Report an issue: GitHub.