{"record":{"id":"8767d728b530dd14","repo":"prestodb/presto","slug":"invalid-function-argument-8767d7","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Not a valid base-%d number: %s","messagePattern":"Not a valid base-(.+?) number: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MathFunctions.java","lineNumber":1616,"sourceCode":"    @SqlType(\"varchar(64)\")\n    public static Slice toBase(@SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.BIGINT) long radix)\n    {\n        checkRadix(radix);\n        return utf8Slice(Long.toString(value, (int) radix));\n    }\n\n    @Description(\"convert a string in the given base to a number\")\n    @ScalarFunction\n    @LiteralParameters(\"x\")\n    @SqlType(StandardTypes.BIGINT)\n    public static long fromBase(@SqlType(\"varchar(x)\") Slice value, @SqlType(StandardTypes.BIGINT) long radix)\n    {\n        checkRadix(radix);\n        try {\n            return Long.parseLong(value.toStringUtf8(), (int) radix);\n        }\n        catch (NumberFormatException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Not a valid base-%d number: %s\", radix, value.toStringUtf8()), e);\n        }\n    }\n\n    private static void checkRadix(long radix)\n    {\n        checkCondition(radix >= MIN_RADIX && radix <= MAX_RADIX,\n                INVALID_FUNCTION_ARGUMENT, \"Radix must be between %d and %d\", MIN_RADIX, MAX_RADIX);\n    }\n\n    @Description(\"The bucket number of a value given a lower and upper bound and the number of buckets\")\n    @ScalarFunction(\"width_bucket\")\n    @SqlType(StandardTypes.BIGINT)\n    public static long widthBucket(@SqlType(StandardTypes.DOUBLE) double operand, @SqlType(StandardTypes.DOUBLE) double bound1, @SqlType(StandardTypes.DOUBLE) double bound2, @SqlType(StandardTypes.BIGINT) long bucketCount)\n    {\n        checkCondition(bucketCount > 0, INVALID_FUNCTION_ARGUMENT, \"bucketCount must be greater than 0\");\n        checkCondition(!isNaN(operand), INVALID_FUNCTION_ARGUMENT, \"operand must not be NaN\");\n        checkCondition(isFinite(bound1), INVALID_FUNCTION_ARGUMENT, \"first bound must be finite\");\n        checkCondition(isFinite(bound2), INVALID_FUNCTION_ARGUMENT, \"second bound must be finite\");","sourceCodeStart":1598,"sourceCodeEnd":1634,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/MathFunctions.java#L1598-L1634","documentation":"The from_base(varchar, radix) function parses a string as a number in the given base using Long.parseLong. If the string contains characters invalid for that radix or overflows a signed 64-bit long, it throws INVALID_FUNCTION_ARGUMENT 'Not a valid base-%d number: %s'.","triggerScenarios":"SELECT from_base('12g', 10); from_base('z', 10); from_base('9223372036854775808', 10) (BIGINT overflow); whitespace or sign-only strings; wrong radix/data pairing (binary string parsed as base 10).","commonSituations":"Parsing user-supplied encoded IDs (hex/base36) with mixed-case or stray characters; decoding columns where some rows hold decimal values while the query uses base 16; upstream systems writing unpadded/malformed numeric strings.","solutions":["Validate/clean the string before parsing: trim whitespace, ensure only digits valid for the radix (regex '^[0-9a-fA-F]+$' style for the radix).","Wrap with TRY: SELECT TRY(from_base(value, 16)) to return NULL for invalid rows instead of failing the query.","Confirm the radix matches the actual encoding of the data.","Check magnitude fits in BIGINT; use from_base on halves or handle larger values differently."],"exampleFix":"-- before\nSELECT from_base(value, 16) FROM t; -- value='1Z3' fails\n-- after\nSELECT TRY(from_base(trim(value), 16)) AS parsed FROM t WHERE regexp_like(value, '^[0-9A-Fa-f]+$');","handlingStrategy":"validation","validationCode":"-- radix 16 example: validate characters and length before from_base\nSELECT * FROM t WHERE value IS NULL OR NOT regexp_like(trim(value), '^[0-9A-Fa-f]+$')\n   OR length(trim(value)) > 15;","typeGuard":null,"tryCatchPattern":"SELECT TRY(from_base(value, 16)) AS parsed FROM t; -- NULL for invalid strings","preventionTips":["Match the radix to the actual data encoding; confirm upstream format docs.","Trim inputs and reject empty/whitespace strings at ingestion.","Validate with a regex per radix before parsing; cap length to stay within BIGINT range."],"tags":["presto","sql","from-base","parsing"],"backgroundTag":"invalid-number-format","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"}