prestodb/presto · error · IllegalArgumentException
Expected 0, 1 or 2 parameters for DECIMAL type constructor.
Error message
Expected 0, 1 or 2 parameters for DECIMAL type constructor.
What it means
DecimalParametricType.createType only accepts 0, 1, or 2 parameters for DECIMAL; declaring the type with 3+ parameters (or otherwise reaching the default branch) throws IllegalArgumentException('Expected 0, 1 or 2 parameters for DECIMAL type constructor.'). Note this IAE is NOT converted to a PrestoException — only InvalidFunctionArgumentException is.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DecimalParametricType.java:51
@Override
public String getName()
{
return StandardTypes.DECIMAL;
}
@Override
public Type createType(List<TypeParameter> parameters)
{
try {
switch (parameters.size()) {
case 0:
return DecimalType.createDecimalType();
case 1:
return DecimalType.createDecimalType(parameters.get(0).getLongLiteral().intValue());
case 2:
return DecimalType.createDecimalType(parameters.get(0).getLongLiteral().intValue(), parameters.get(1).getLongLiteral().intValue());
default:
throw new IllegalArgumentException("Expected 0, 1 or 2 parameters for DECIMAL type constructor.");
}
}
catch (InvalidFunctionArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Remove extra parameters: use DECIMAL, DECIMAL(p), or DECIMAL(p,s) forms only
- Fix the code that generates the type string to cap at 2 parameters
- Catch/pre-validate the parameter count before invoking the type constructor
Example fix
// before CREATE TABLE t (x DECIMAL(10,2,0)); // after CREATE TABLE t (x DECIMAL(10,2));
Defensive patterns
Strategy: validation
Validate before calling
if (parameters != null && parameters.size() > 2) { throw new IllegalArgumentException("DECIMAL accepts at most 2 parameters"); } Type guard
boolean isValidDecimalSignature(int paramCount) { return paramCount >= 0 && paramCount <= 2; } Try / catch
try { type = DecimalParametricType.createType(symbols); } catch (IllegalArgumentException e) { type = DecimalType.createDecimalType(); /* or surface to user */ } Prevention
- Only write DECIMAL, DECIMAL(p), DECIMAL(p,s) in DDL
- Validate generated type strings in connectors before registration
- Lint migration scripts for extra type parameters
- Add tests for type-signature parsing
When it happens
Trigger: DDL/statements like `CREATE TABLE t (x DECIMAL(10,2,3))`, `CAST(v AS DECIMAL(1,2,3))`, or a connector supplying more than two type parameters to DECIMAL.
Common situations: Hand-written DDL typos; programmatically built type signatures passing extra args; connectors/templates that concatenate parameter lists incorrectly.
Related errors
- DECIMAL precision must be in range [1, 38]
- DECIMAL scale must be in range [0, precision]
- Invalid decimal value '{stringValue}'
- decimal precision larger than column precision
- MISSING_COLUMN
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/eeae54dfb3b0b0b4.
Report an issue: GitHub.