prestodb/presto · error · PrestoException
ELASTICSEARCH_TYPE_MISMATCH
ELASTICSEARCH_TYPE_MISMATCH
Error message
Value out of range for field '%s' of type SMALLINT: %s
What it means
SmallintDecoder reads the number's long value and rejects it when it does not fit in Presto SMALLINT's 16-bit range (Short.MIN_VALUE..Short.MAX_VALUE), throwing ELASTICSEARCH_TYPE_MISMATCH. The stored JSON type is correct (numeric); only the magnitude is out of range.
Source
Thrown at presto-elasticsearch/src/main/java/com/facebook/presto/elasticsearch/decoders/SmallintDecoder.java:48
private final String path;
public SmallintDecoder(String path)
{
this.path = requireNonNull(path, "path is null");
}
@Override
public void decode(Hit hit, Supplier<Object> getter, BlockBuilder output)
{
Object value = getter.get();
if (value == null) {
output.appendNull();
}
else if (value instanceof Number) {
long decoded = ((Number) value).longValue();
if (decoded < Short.MIN_VALUE || decoded > Short.MAX_VALUE) {
throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format("Value out of range for field '%s' of type SMALLINT: %s", path, decoded));
}
SMALLINT.writeLong(output, decoded);
}
else {
throw new PrestoException(ELASTICSEARCH_TYPE_MISMATCH, format("Expected a numeric value for field '%s' of type SMALLINT: %s [%s]", path, value, value.getClass().getSimpleName()));
}
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Re-map the Presto column to INTEGER or BIGINT so the range accommodates the data.
- Clamp or cap the values at ingest time, or reindex with values converted to fit SMALLINT.
- If the oversized values are data errors, clean them (e.g. set null) in the source index.
Example fix
// table definition before count SMALLINT // after count INTEGER
Defensive patterns
Strategy: validation
Validate before calling
SELECT MAX(t.count), MIN(t.count) FROM idx t; -- verify fits in [-32768, 32767] before declaring SMALLINT
Type guard
function fitsSmallint(n) { return typeof n === 'number' && Number.isInteger(n) && n >= -32768 && n <= 32767; } Try / catch
try { SELECT count FROM "idx" } catch (PrestoException e) { if (e.getErrorCode().getName().equals("ELASTICSEARCH_TYPE_MISMATCH")) { /* re-map to INTEGER */ } throw e; } Prevention
- Profile min/max of the field before choosing SMALLINT.
- Prefer INTEGER/BIGINT unless the range is guaranteed.
- Clamp or validate values at ingest time.
When it happens
Trigger: decode() finds a numeric value like 40000 or -40000 for a field the Presto table maps to SMALLINT, e.g. {"count": 100000}.
Common situations: Column declared SMALLINT but documents exceed 32767 (counters, IDs, timestamps in ms); documents grew over time beyond the original value range assumption.
Related errors
- ELASTICSEARCH_TYPE_MISMATCH
- ELASTICSEARCH_TYPE_MISMATCH
- INVALID_CAST_ARGUMENT
- GENERIC_INTERNAL_ERROR
- ELASTICSEARCH_TYPE_MISMATCH
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/f796c881d45dbb8b.
Report an issue: GitHub.