{"record":{"id":"bcdf8ed8f51f3bb8","repo":"MyCATApache/Mycat-Server","slug":"columnvalue-columnvalue-please-eliminate-any-quo-bcdf8e","errorCode":null,"errorMessage":"columnValue:{columnValue} Please eliminate any quote and non number within it.","messagePattern":"columnValue:(.+?) Please eliminate any quote and non number within it\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/function/PartitionByPrefixPattern.java","lineNumber":85,"sourceCode":"\tpublic Integer calculate(String columnValue)  {\r\n\t\ttry {\r\n\t\t\tint Length = Integer.valueOf(prefixLength);\r\n\r\n\t\t\tLength = columnValue.length() < Length ? columnValue.length() : Length;\r\n\t\t\tint sum = 0;\r\n\t\t\tfor (int i = 0; i < Length; i++) {\r\n\t\t\t\tsum = sum + columnValue.charAt(i);\r\n\t\t\t}\r\n\t\t\tInteger rst = null;\r\n\t\t\tfor (LongRange longRang : this.longRongs) {\r\n\t\t\t\tlong hash = sum % patternValue;\r\n\t\t\t\tif (hash <= longRang.valueEnd && hash >= longRang.valueStart) {\r\n\t\t\t\t\treturn longRang.nodeIndx;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn rst;\r\n\t\t} catch (NumberFormatException e){\r\n\t\t\tthrow new IllegalArgumentException(new StringBuilder().append(\"columnValue:\").append(columnValue).append(\" Please eliminate any quote and non number within it.\").toString(),e);\r\n\t\t}\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic int getPartitionNum() {\r\n//\t\tint nPartition = this.longRongs.length;\r\n\t\t/*\r\n\t\t * fix #1284 这里的统计应该统计Range的nodeIndex的distinct总数\r\n\t\t */\r\n\t\tSet<Integer> distNodeIdxSet = new HashSet<Integer>();\r\n\t\tfor(LongRange range : longRongs) {\r\n\t\t\tdistNodeIdxSet.add(range.nodeIndx);\r\n\t\t}\r\n\t\tint nPartition = distNodeIdxSet.size();\r\n\t\treturn nPartition;\r\n\t}\r\n\r\n\tprivate void initialize() {\r","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/function/PartitionByPrefixPattern.java#L67-L103","documentation":"PartitionByPrefixPattern.calculate() parses the sharding column value as a long to compute a hash against configured ranges. If Long.parseLong fails with NumberFormatException, it rethrows it as an IllegalArgumentException telling the user to strip quotes and non-numeric characters. This means the input value is not a bare number.","triggerScenarios":"Calling calculate(Object columnValue) with a value that cannot be parsed as a long, e.g. \"'12345'\" (value wrapped in SQL single quotes), \"12345abc\", \"12 345\", an empty string, or a String carrying currency symbols or whitespace.","commonSituations":"The application passes a quoted string literal into the rule; the column stores alphanumeric order IDs but the rule expects numeric prefixes; CSV/JSON ingestion delivers values with surrounding quotes or spaces; locale-formatted numbers with thousands separators.","solutions":["Sanitize the column value before routing: strip surrounding quotes, whitespace, and any non-digit characters.","Verify the sharding column actually contains numeric data; if IDs are alphanumeric, switch to a partition function that hashes strings.","Ensure the value passed to calculate() is the raw column value, not a SQL fragment like 'value' with quotes included.","Catch IllegalArgumentException at the call site and return a clear SQL error to the client about the offending value."],"exampleFix":"// before\ncalculate(\"'1001'\"); // IllegalArgumentException\n// after\nString raw = \"'1001'\";\nString cleaned = raw.trim().replace(\"'\", \"\");\ncalculate(cleaned); // routes normally","handlingStrategy":"validation","validationCode":"boolean isNumeric(String v) { return v != null && v.trim().matches(\"-?\\\\d+\"); }\nif (!isNumeric(columnValue)) throw new IllegalArgumentException(\"sharding value must be numeric: \" + columnValue);","typeGuard":"Long parseNumericOrNull(Object v) {\n  if (v == null) return null;\n  try { return Long.parseLong(v.toString().trim().replace(\"'\", \"\")); }\n  catch (NumberFormatException e) { return null; }\n}","tryCatchPattern":"try { nodeIdx = rule.calculate(value); } catch (IllegalArgumentException e) { /* strip quotes/non-numerics and retry once, else reject row */ }","preventionTips":["Keep sharding columns numeric in the schema so values arrive unquoted.","Sanitize values (trim, strip quotes/separators) before routing.","Log the offending columnValue in a pre-routing validator for quick triage."],"tags":["number-format","sharding","input-validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}