MyCATApache/Mycat-Server · error · IllegalArgumentException

columnValue: Please check if the format satisfied.

Error message

columnValue:{columnValue} Please check if the format satisfied.

What it means

PartitionByRangeDateHash.calculate() parses the column value as a date using an internal SimpleDateFormat with the configured dateFormat. Any ParseException (unparseable or wrong-format date string) is rethrown as this IllegalArgumentException. The value must match the rule's dateFormat exactly to be routed.

Solutions

  1. Align the rule's dateFormat property with the actual stored date format, or normalize the column values.
  2. Normalize/parse the date in the application before routing so it matches the expected pattern exactly (including zero-padding).
  3. Pre-validate the sharding column with a SimpleDateFormat of the configured pattern and reject bad rows before reaching the router.
  4. If multiple formats must be supported, wrap calculate() with a fallback parser that converts to the canonical format.

Example fix

// before (dateFormat=yyyy-MM-dd)
calculate("2023/01/15"); // IllegalArgumentException
// after
String v = "2023/01/15";
Date d = new SimpleDateFormat("yyyy/MM/dd").parse(v);
String v2 = new SimpleDateFormat("yyyy-MM-dd").format(d);
calculate(v2); // routes normally
Defensive patterns

Strategy: validation

Validate before calling

SimpleDateFormat check = new SimpleDateFormat("yyyy-MM-dd"); // same as rule dateFormat
check.setLenient(false);
try { check.parse(columnValue); } catch (ParseException e) { throw new IllegalArgumentException("bad date for sharding: " + columnValue); }

Type guard

boolean matchesDateFormat(String v, String pattern) {
  SimpleDateFormat sdf = new SimpleDateFormat(pattern);
  sdf.setLenient(false);
  try { sdf.parse(v); return true; } catch (ParseException e) { return false; }
}

Try / catch

try { idx = rule.calculate(value); } catch (IllegalArgumentException e) { /* normalize the date to the rule's dateFormat and retry, else reject */ }

Prevention

When it happens

Trigger: Calling calculate(columnValue) with a date string not matching the configured dateFormat, e.g. passing "2023/01/15" when dateFormat=yyyy-MM-dd, passing "2023-1-5" (non-padded), or passing a datetime string when only a date format is configured.

Common situations: Column stores dates in a different format than the rule's <property name="dateFormat">; applications write ISO-8601 with time and timezone but the rule expects plain dates; data migrated from another system with a legacy format; null or empty values submitted for the sharding column.

Related errors


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

Appendix: source

Thrown at src/main/java/io/mycat/route/function/PartitionByRangeDateHash.java:81

        {
            throw new IllegalArgumentException(e);
        }
        partionTime = Integer.parseInt(sPartionDay) * oneDay;
    }

    @Override
    public Integer calculate(String columnValue)  {
        try
        {
            long targetTime = formatter.get().parse(
                    columnValue).getTime();
            int targetPartition = (int) ((targetTime - beginDate) / partionTime);
            int innerIndex =  Hashing.consistentHash(targetTime,intGroupPartionSize);
            return targetPartition * intGroupPartionSize + innerIndex;

        } catch (ParseException e)
        {
            throw new IllegalArgumentException(new StringBuilder().append("columnValue:").append(columnValue).append(" Please check if the format satisfied.").toString(),e);
        }
    }

    public Integer calculateStart(String columnValue)
    {
        try
        {
            long targetTime = formatter.get().parse(columnValue).getTime();
            int targetPartition = (int) ((targetTime - beginDate) / partionTime);
            return targetPartition * intGroupPartionSize;

        } catch (ParseException e)
        {
            throw new IllegalArgumentException(e);

        }
    }

View on GitHub (pinned to 65f8d8beb7)