MyCATApache/Mycat-Server · error · IllegalArgumentException

columnValue: Please eliminate any quote and non number…

Error message

columnValue:{columnValue} Please eliminate any quote and non number within it.

What it means

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.

Solutions

  1. Sanitize the column value before routing: strip surrounding quotes, whitespace, and any non-digit characters.
  2. Verify the sharding column actually contains numeric data; if IDs are alphanumeric, switch to a partition function that hashes strings.
  3. Ensure the value passed to calculate() is the raw column value, not a SQL fragment like 'value' with quotes included.
  4. Catch IllegalArgumentException at the call site and return a clear SQL error to the client about the offending value.

Example fix

// before
calculate("'1001'"); // IllegalArgumentException
// after
String raw = "'1001'";
String cleaned = raw.trim().replace("'", "");
calculate(cleaned); // routes normally
Defensive patterns

Strategy: validation

Validate before calling

boolean isNumeric(String v) { return v != null && v.trim().matches("-?\\d+"); }
if (!isNumeric(columnValue)) throw new IllegalArgumentException("sharding value must be numeric: " + columnValue);

Type guard

Long parseNumericOrNull(Object v) {
  if (v == null) return null;
  try { return Long.parseLong(v.toString().trim().replace("'", "")); }
  catch (NumberFormatException e) { return null; }
}

Try / catch

try { nodeIdx = rule.calculate(value); } catch (IllegalArgumentException e) { /* strip quotes/non-numerics and retry once, else reject row */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/bcdf8ed8f51f3bb8. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/route/function/PartitionByPrefixPattern.java:85

	public Integer calculate(String columnValue)  {
		try {
			int Length = Integer.valueOf(prefixLength);

			Length = columnValue.length() < Length ? columnValue.length() : Length;
			int sum = 0;
			for (int i = 0; i < Length; i++) {
				sum = sum + columnValue.charAt(i);
			}
			Integer rst = null;
			for (LongRange longRang : this.longRongs) {
				long hash = sum % patternValue;
				if (hash <= longRang.valueEnd && hash >= longRang.valueStart) {
					return longRang.nodeIndx;
				}
			}
			return rst;
		} catch (NumberFormatException e){
			throw new IllegalArgumentException(new StringBuilder().append("columnValue:").append(columnValue).append(" Please eliminate any quote and non number within it.").toString(),e);
		}
	}
	
	@Override
	public int getPartitionNum() {
//		int nPartition = this.longRongs.length;
		/*
		 * fix #1284 这里的统计应该统计Range的nodeIndex的distinct总数
		 */
		Set<Integer> distNodeIdxSet = new HashSet<Integer>();
		for(LongRange range : longRongs) {
			distNodeIdxSet.add(range.nodeIndx);
		}
		int nPartition = distNodeIdxSet.size();
		return nPartition;
	}

	private void initialize() {

View on GitHub (pinned to 65f8d8beb7)