prestodb/presto · error · SemanticException

TYPE_MISMATCH

TYPE_MISMATCH

Error message

Unknown type: 

What it means

visitGenericLiteral throws a SemanticException TYPE_MISMATCH when a generic literal like X'...' or MyType 'value' names a type unknown to the metadata registry. The type name must resolve before the literal can be cast.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LiteralInterpreter.java:256

        @Override
        protected Slice visitBinaryLiteral(BinaryLiteral node, ConnectorSession session)
        {
            return node.getValue();
        }

        @Override
        protected Object visitEnumLiteral(EnumLiteral node, ConnectorSession context)
        {
            return node.getValue();
        }

        @Override
        protected Object visitGenericLiteral(GenericLiteral node, ConnectorSession session)
        {
            Type type = metadata.getType(parseTypeSignature(node.getType()));
            if (type == null) {
                throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType());
            }

            if (JSON.equals(type)) {
                FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("json_parse", fromTypes(VARCHAR));
                return functionInvoker.invoke(functionHandle, session.getSqlFunctionProperties(), ImmutableList.of(utf8Slice(node.getValue())));
            }

            try {
                FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupCast(CAST, VARCHAR, type);
                return functionInvoker.invoke(functionHandle, session.getSqlFunctionProperties(), ImmutableList.of(utf8Slice(node.getValue())));
            }
            catch (IllegalArgumentException e) {
                throw new SemanticException(TYPE_MISMATCH, node, "No literal form for type %s", type);
            }
        }

        @Override
        protected Long visitTimeLiteral(TimeLiteral node, ConnectorSession session)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the type name in the literal.
  2. Use a supported type or explicit CAST instead of a generic literal.
  3. Install the plugin providing the custom type.

Example fix

// before
SELECT MYTYPE 'abc';
// after
SELECT CAST('abc' AS VARCHAR);
Defensive patterns

Strategy: validation

Validate before calling

if (metadata.getType(parseTypeSignature(literalType)) == null) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + literalType); }

Type guard

boolean typeExists(Metadata metadata, String typeName) { return metadata.getType(parseTypeSignature(typeName)) != null; }

Try / catch

try { return LiteralInterpreter.evaluateGenericLiteral(node, session); } catch (SemanticException e) { if (e.getCode() == TYPE_MISMATCH) { /* fall back to CAST(string AS knownType) */ } else { throw e; } }

Prevention

When it happens

Trigger: Evaluating GenericLiteral whose node.getType() (e.g. `FOO 'bar'`) is not a registered type.

Common situations: Typos in type names, using custom/connector types not installed, or dialect-specific syntax that Presto doesn't recognize.

Related errors


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