Tencent/APIJSON · error · IllegalArgumentException
预编译模式下 @sample:value 中 ${item} 不合法! value 里面用 , 分割的每一项必须是 co
Error message
预编译模式下 @sample:value 中 ${item} 不合法! value 里面用 , 分割的每一项必须是 column 且其中 column 必须是 数字或英语字母组合!并且不要有多余的空格! What it means
In prepared mode every comma-separated item of @sample:value must pass StringUtil.isName or StringUtil.isCombineOfNumOrAlpha — a column name or a digits+letters combination, with no spaces or symbols. Like other identifier-list clauses it cannot be parameter-bound, so malformed items are rejected outright.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java:1860
String[] keys = StringUtil.split(sample);
if (keys == null || keys.length <= 0) {
return StringUtil.isEmpty(joinSample, true) ? "" : (hasPrefix ? " SAMPLE BY " : "") + joinSample;
}
for (int i = 0; i < keys.length; i++) {
String item = keys[i];
String origin = item;
if (isPrepared()) { //不能通过 ? 来代替,SELECT 'id','name' 返回的就是 id:"id", name:"name",而不是数据库里的值!
//这里既不对origin trim,也不对 ASC/DESC ignoreCase,希望前端严格传没有任何空格的字符串过来,减少传输数据量,节约服务器性能
if (StringUtil.isName(origin)) {}
else if (StringUtil.isCombineOfNumOrAlpha(origin)) {
continue;
}
else {
throw new IllegalArgumentException("预编译模式下 @sample:value 中 " + item + " 不合法! value 里面用 , 分割的"
+ "每一项必须是 column 且其中 column 必须是 数字或英语字母组合!并且不要有多余的空格!");
}
}
keys[i] = gainKey(origin);
}
return (hasPrefix ? " SAMPLE BY " : "") + StringUtil.concat(StringUtil.get(keys), joinSample, ", ");
}
@Override
public String getLatest() {
return latest;
}
public AbstractSQLConfig<T, M, L> setLatest(String... conditions) {
return setLatest(StringUtil.get(conditions));
}
@OverrideView on GitHub (pinned to 5284052872)
Solutions
- Send bare identifiers: "@sample": "0.1" style numeric or plain column names only
- Remove spaces and symbols from each item
- For expressions, pre-configure in RAW_MAP and use @raw
Example fix
// before
{"@sample": "user id, 0.1"}
// after
{"@sample": "userId,0.1"} Defensive patterns
Strategy: validation
Validate before calling
const ok = s => /^[A-Za-z_][A-Za-z0-9_]*$/.test(s) || /^[A-Za-z0-9]+$/.test(s);
for (const item of String(obj['@sample'] ?? '').split(',')) {
if (item && !ok(item)) throw new Error(`@sample item '${item}' must be a name or digit/letter combo`);
} Type guard
const isSampleItemValid = s => /^[A-Za-z_][A-Za-z0-9_]*$/.test(s) || /^[A-Za-z0-9.]+$/.test(s);
Try / catch
try { await api.get(req); } catch (e) { if (e.message.includes('@sample')) sanitizeListField(req, '@sample'); else throw e; } Prevention
- Generate @sample from column pickers and numeric inputs only
- No spaces after commas in any clause list value
When it happens
Trigger: "@sample": "user id" (space), "@sample": "id,name-1" (hyphen), "@sample": "count(*)" — any SAMPLE BY item that is neither a name nor an alphanumeric combination.
Common situations: Copy-pasting SQL SAMPLE BY clauses; columns with special characters; the SAMPLE BY feature is ClickHouse-oriented so devs unfamiliar with its strict item syntax hit it first.
Related errors
- 预编译模式下 @partition:value 中 ${item} 不合法! value 里面用 , 分割的每一项必须是
- 预编译模式下 @fill:value 中 {item} 不合法! value 里面用 , 分割的每一项必须是 colum
- @group:value 中 value里面用 , 分割的每一项都必须是1个单词!并且不要有空格!
- 预编译模式下 @latest:value 中 ${item} 不合法! value 里面用 , 分割的每一项必须是 co
- 预编译模式下 @order:value 中 {item} 不合法! value 里面用 , 分割的每一项必须是 随机函数
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/78515bf7af820710.
Report an issue: GitHub.