{"record":{"id":"638a4104152a7c4b","repo":"prestodb/presto","slug":"invalid-cast-argument-638a41","errorCode":"INVALID_CAST_ARGUMENT","errorMessage":"No value '%s' in enum '%s'","messagePattern":"No value '(.+?)' in enum '(.+?)'","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/EnumCasts.java","lineNumber":45,"sourceCode":"import static com.facebook.presto.common.function.OperatorType.CAST;\nimport static com.facebook.presto.common.type.StandardTypes.BIGINT;\nimport static com.facebook.presto.common.type.StandardTypes.BIGINT_ENUM;\nimport static com.facebook.presto.common.type.StandardTypes.VARCHAR_ENUM;\nimport static com.facebook.presto.spi.StandardErrorCode.INVALID_CAST_ARGUMENT;\n\npublic final class EnumCasts\n{\n    private EnumCasts()\n    {\n    }\n\n    @ScalarOperator(CAST)\n    @TypeParameter(value = \"T\", boundedBy = VARCHAR_ENUM)\n    @SqlType(\"T\")\n    public static Slice castVarcharToEnum(@TypeParameter(\"T\") Type enumType, @SqlType(StandardTypes.VARCHAR) Slice value)\n    {\n        if (!(((VarcharEnumType) enumType).getEnumMap().values().contains(value.toStringUtf8()))) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT,\n                    String.format(\n                            \"No value '%s' in enum '%s'\",\n                            value.toStringUtf8(),\n                            enumType.getTypeSignature().getBase()));\n        }\n        return value;\n    }\n\n    @ScalarOperator(CAST)\n    @TypeParameter(value = \"T\", boundedBy = VARCHAR_ENUM)\n    @SqlType(StandardTypes.VARCHAR)\n    public static Slice castEnumToVarchar(@SqlType(\"T\") Slice value)\n    {\n        return value;\n    }\n\n    @ScalarOperator(CAST)\n    @TypeParameter(value = \"T\", boundedBy = BIGINT_ENUM)","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/EnumCasts.java#L27-L63","documentation":"Cast error from varchar-to-enum casting: the string being cast is not one of the values declared for the target ENUM type. The %s pair names the offending value and the enum type; the faulty input is the string being cast.","triggerScenarios":"CAST(varchar_value AS <enum type>) where the string is not in the enum's defined value set (castVarcharToEnum in EnumCasts.java).","commonSituations":"Source data containing new/renamed labels not yet added to the enum, whitespace or case mismatches ('Active' vs 'active'), stale enum definitions after upstream schema changes.","solutions":["Add the missing value to the enum definition","Normalize the input (trim/lowercase) to match enum spelling exactly","Inspect the enum's allowed values and fix the data or the mapping"],"exampleFix":"// before (SQL)\nSELECT CAST(status AS order_status) FROM t -- status = 'cancelled '\n// after\nSELECT CAST(trim(lower(status)) AS order_status) FROM t","handlingStrategy":"validation","validationCode":"-- check values against the enum before casting\nSELECT DISTINCT status FROM t; -- compare against enum's declared values; normalize with trim/lower if needed","typeGuard":null,"tryCatchPattern":"SELECT try(CAST(status AS order_status)) FROM t -- NULL for unknown labels","preventionTips":["Keep enum definitions in sync with upstream vocabularies","Normalize case/whitespace before casting to enums","Alert on new distinct values appearing in source columns"],"tags":["cast","enum","varchar","presto"],"backgroundTag":"invalid-enum-value","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}