MyCATApache/Mycat-Server · error · RuntimeException
file name is null !
Error message
file name is null !
What it means
HintDataNodeHandler.parseLoadDataPram() parses a LOAD DATA INFILE statement routed via the datanode hint and extracts the file name from the SQL text. If the parsed file name is null or blank, it throws this RuntimeException because LOAD DATA without a file name cannot be forwarded to the backend.
Solutions
- Check the LOAD DATA statement syntax and ensure a literal file path is present: LOAD DATA INFILE '/path/file.csv' INTO TABLE t.
- Unquote or normalize the file path so the parser's parseFileName() can extract it, matching the format Mycat expects.
- Verify the Mycat version handles the LOAD DATA variant you use (LOCAL INFILE vs INFILE) and upgrade or adjust the statement accordingly.
- Catch the RuntimeException at the client/session level and report the malformed statement instead of retrying.
Example fix
// before "LOAD DATA INFILE INTO TABLE t"; // file name is null ! // after "LOAD DATA INFILE '/data/import/t.csv' INTO TABLE t";
Defensive patterns
Strategy: validation
Validate before calling
Matcher m = Pattern.compile("LOAD\\s+DATA\\s+(?:LOW_PRIORITY\\s+|CONCURRENT\\s+)?(?:LOCAL\\s+)?INFILE\\s+'?([^'\\s]+)'?", Pattern.CASE_INSENSITIVE).matcher(sql);
if (!m.find() || m.group(1).trim().isEmpty()) throw new IllegalArgumentException("LOAD DATA missing file name"); Type guard
String extractLoadDataFile(String sql) {
Matcher m = Pattern.compile("INFILE\\s+'?([^'\\s]+)'?", Pattern.CASE_INSENSITIVE).matcher(sql);
return (m.find() && m.group(1) != null && !m.group(1).trim().isEmpty()) ? m.group(1) : null;
} Try / catch
try { routeWithHint(sql); } catch (RuntimeException e) { if (e.getMessage().contains("file name is null")) { /* fix LOAD DATA syntax: include a literal file path */ } throw e; } Prevention
- Always include a literal, unquoted-or-simply-quoted file path in LOAD DATA statements sent through hints.
- Avoid dynamic/templated file names that the simple SQL text parser cannot see.
- Validate LOAD DATA syntax client-side before routing through a datanode hint.
When it happens
Trigger: Routing a LOAD DATA INFILE statement through a /*+ datanode=... */ hint where parseFileName(sql) cannot extract a file name, e.g. "LOAD DATA INFILE INTO TABLE t" (missing the file token), malformed syntax, or a statement whose file path is quoted/positioned in a way the simple parser does not recognize.
Common situations: Client-generated LOAD DATA statements with non-standard syntax; file path wrapped in quotes or variables so the string parser misses it; truncated SQL from a custom driver; users running LOAD DATA LOCAL INFILE variants the parser does not handle.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- can't find hint datanode
- can't find hint schema
- sql 注释 语法错误
- not a query sql statement
- number of columns error
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/365bf8107913f021.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/route/handler/HintDataNodeHandler.java:90
loadData.setLineTerminatedBy(lineTerminatedBy);
SQLTextLiteralExpr rawFieldEnd = (SQLTextLiteralExpr) statement.getColumnsTerminatedBy();
String fieldTerminatedBy = rawFieldEnd == null ? "\t" : rawFieldEnd.getText();
loadData.setFieldTerminatedBy(fieldTerminatedBy);
SQLTextLiteralExpr rawEnclosed = (SQLTextLiteralExpr) statement.getColumnsEnclosedBy();
String enclose = rawEnclosed == null ? null : rawEnclosed.getText();
loadData.setEnclose(enclose);
SQLTextLiteralExpr escapseExpr = (SQLTextLiteralExpr)statement.getColumnsEscaped() ;
String escapse=escapseExpr==null?"\\":escapseExpr.getText();
loadData.setEscape(escapse);
String charset = statement.getCharset() != null ? statement.getCharset() : connectionCharset;
loadData.setCharset(charset);
String fileName = parseFileName(sql);
if(StringUtils.isBlank(fileName)){
throw new RuntimeException(" file name is null !");
}
loadData.setFileName(fileName);
return loadData ;
}
// 处理文件名
private String parseFileName(String sql)
{
if (sql.contains("'"))
{
int beginIndex = sql.indexOf("'");
return sql.substring(beginIndex + 1, sql.indexOf("'", beginIndex + 1));
} else if (sql.contains("\""))
{
int beginIndex = sql.indexOf("\"");
return sql.substring(beginIndex + 1, sql.indexOf("\"", beginIndex + 1));View on GitHub (pinned to 65f8d8beb7)