{"record":{"id":"0b64915c7300c82e","repo":"prestodb/presto","slug":"generic-internal-error-0b6491","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"RegExp type cannot be serialized","messagePattern":"RegExp type cannot be serialized","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/Re2JRegexpType.java","lineNumber":52,"sourceCode":"        super(new TypeSignature(NAME), Re2JRegexp.class);\n    }\n\n    @Override\n    public Object getObjectValue(SqlFunctionProperties properties, Block block, int position)\n    {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public void appendTo(Block block, int position, BlockBuilder blockBuilder)\n    {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries, int expectedBytesPerEntry)\n    {\n        throw new PrestoException(GENERIC_INTERNAL_ERROR, \"RegExp type cannot be serialized\");\n    }\n\n    @Override\n    public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries)\n    {\n        throw new PrestoException(GENERIC_INTERNAL_ERROR, \"RegExp type cannot be serialized\");\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":61,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/Re2JRegexpType.java#L34-L61","documentation":"Re2JRegexpType wraps compiled RE2/J Pattern objects used by regexp functions. Like LikePatternType, compiled regex objects are transient engine values that cannot be materialized into a Block, so createBlockBuilder(status, expectedEntries, expectedBytesPerEntry) unconditionally throws GENERIC_INTERNAL_ERROR 'RegExp type cannot be serialized'.","triggerScenarios":"Calling Re2JRegexpType.createBlockBuilder(BlockBuilderStatus, int, int) — any attempt to write RE2J_REGEXP values into a page for exchange, aggregation, output, or in engine/plugin code that generically serializes all column types.","commonSituations":"Custom connectors or functions that try to return/store a REGEXP-typed column; misuse of the transient REGEXP type in a table schema; engine changes that route compiled patterns through serialization points.","solutions":["Carry patterns as VARCHAR and compile them with re2jPattern(VARCHAR) at the point of use instead of serializing the compiled object.","Ensure REGEXP-typed values never reach exchange/spill/output paths; keep them as scalar function arguments only.","Add an instanceof Re2JRegexpType guard in generic block-building/serialization code to route to a non-materializing path."],"exampleFix":"// before\nBlockBuilder bb = re2jRegexpType.createBlockBuilder(new BlockBuilderStatus(), 1, 32);\n// after\nbb.writeBytes(patternSourceSlice, 0, patternSourceSlice.length()).closeEntry(); // send VARCHAR, recompile later","handlingStrategy":"type-guard","validationCode":"if (type instanceof Re2JRegexpType) {\n    throw new IllegalStateException(\"RegExp values cannot be written to blocks\");\n}","typeGuard":"boolean isSerializableType(Type t) {\n    return !(t instanceof Re2JRegexpType) && !(t instanceof LikePatternType);\n}","tryCatchPattern":"try {\n    bb = type.createBlockBuilder(status, entries, bytesPerEntry);\n} catch (PrestoException e) {\n    if (e.getMessage().contains(\"RegExp type cannot be serialized\")) {\n        throw new IllegalStateException(\"Pass the pattern as VARCHAR and recompile with re2jPattern()\", e);\n    }\n    throw e;\n}","preventionTips":["Never declare REGEXP-typed columns in tables, outputs, or aggregation inputs; it is a transient function-argument type.","In generic connectors, check for transient types before calling createBlockBuilder.","Serialize the pattern source string, not the compiled Re2J Pattern."],"tags":["presto","serialization","regex","re2j","internal-error"],"backgroundTag":"non-serializable-type","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"}