{"record":{"id":"57d2a1135de0ce49","repo":"prestodb/presto","slug":"char-length-scale-must-be-in-range-0-s","errorCode":null,"errorMessage":"CHAR length scale must be in range [0, %s]","messagePattern":"CHAR length scale must be in range \\[0, (.+?)\\]","errorType":"validation","errorClass":"InvalidFunctionArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/CharType.java","lineNumber":50,"sourceCode":"    public static final int MAX_LENGTH = 65_536;\n\n    private final int length;\n\n    public static CharType createCharType(long length)\n    {\n        return new CharType(length);\n    }\n\n    private CharType(long length)\n    {\n        super(\n                new TypeSignature(\n                        StandardTypes.CHAR,\n                        singletonList(TypeSignatureParameter.of(length))),\n                Slice.class);\n\n        if (length < 0 || length > MAX_LENGTH) {\n            throw new InvalidFunctionArgumentException(format(\"CHAR length scale must be in range [0, %s]\", MAX_LENGTH));\n        }\n        this.length = (int) length;\n    }\n\n    public int getLength()\n    {\n        return length;\n    }\n\n    @Override\n    public boolean isComparable()\n    {\n        return true;\n    }\n\n    @Override\n    public boolean isOrderable()\n    {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/CharType.java#L32-L68","documentation":"CharType's constructor validates the CHAR(n) length parameter when building the type from a TypeSignature. If the length is negative or exceeds MAX_LENGTH, the type cannot be represented, so it throws InvalidFunctionArgumentException immediately rather than constructing an invalid type. This guards the type registry against malformed CHAR definitions from catalogs, connectors, or SQL like CHAR(-1) or CHAR(99999999).","triggerScenarios":"Calling CharType.createType(length) or constructing CharType via TypeRegistry with length < 0 or length > MAX_LENGTH (typically 65536); a connector/catalog metadata declares a CHAR column with an out-of-range length.","commonSituations":"Metadata drift between a connector's declared column types and Presto's CHAR limits; user SQL with an extreme CHAR(n); auto-generated schemas computing length as -1 when a column length is unknown.","solutions":["Clamp or reject CHAR lengths at the connector/catalog level so only 0..MAX_LENGTH reach type creation","Fix the column metadata source (e.g. unknown length mapped to -1) to emit a valid length or fall back to VARCHAR","Validate user SQL CHAR(n) lengths before type resolution","If MAX_LENGTH is genuinely too small for your data, use VARCHAR instead of CHAR"],"exampleFix":"// before\nType charType = typeManager.getParameterizedType(StandardTypes.CHAR, ImmutableList.of(TypeSignatureParameter.of(columnLength)));\n// after\nint safeLength = (columnLength < 0 || columnLength > CharType.MAX_LENGTH) ? CharType.MAX_LENGTH : (int) columnLength;\nType charType = typeManager.getParameterizedType(StandardTypes.CHAR, ImmutableList.of(TypeSignatureParameter.of(safeLength)));","handlingStrategy":"validation","validationCode":"public static boolean isValidCharLength(long length) {\n    return length >= 0 && length <= CharType.MAX_LENGTH;\n}\n// call: if (!isValidCharLength(len)) coerce or reject before createType\n","typeGuard":"public static boolean isUsableCharLength(Long length) {\n    return length != null && length >= 0 && length <= CharType.MAX_LENGTH;\n}","tryCatchPattern":"try {\n    Type t = typeManager.getParameterizedType(StandardTypes.CHAR, ImmutableList.of(TypeSignatureParameter.of(length)));\n} catch (InvalidFunctionArgumentException e) {\n    // fall back to VARCHAR or clamp length and retry\n}","preventionTips":["Clamp CHAR lengths to [0, MAX_LENGTH] in connector metadata mapping","Map unknown column lengths to VARCHAR instead of CHAR(-1)","Validate DDL lengths before registering types"],"tags":["presto","type-system","char","argument-validation"],"backgroundTag":"char-length-out-of-range","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"}