{"record":{"id":"365bf8107913f021","repo":"MyCATApache/Mycat-Server","slug":"file-name-is-null","errorCode":null,"errorMessage":" file name is null !","messagePattern":" file name is null !","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/handler/HintDataNodeHandler.java","lineNumber":90,"sourceCode":"\t\tloadData.setLineTerminatedBy(lineTerminatedBy);\n\n\t\tSQLTextLiteralExpr rawFieldEnd = (SQLTextLiteralExpr) statement.getColumnsTerminatedBy();\n\t\tString fieldTerminatedBy = rawFieldEnd == null ? \"\\t\" : rawFieldEnd.getText();\n\t\tloadData.setFieldTerminatedBy(fieldTerminatedBy);\n\n\t\tSQLTextLiteralExpr rawEnclosed = (SQLTextLiteralExpr) statement.getColumnsEnclosedBy();\n\t\tString enclose = rawEnclosed == null ? null : rawEnclosed.getText();\n\t\tloadData.setEnclose(enclose);\n\n\t\tSQLTextLiteralExpr escapseExpr =  (SQLTextLiteralExpr)statement.getColumnsEscaped() ;\n\t\tString escapse=escapseExpr==null?\"\\\\\":escapseExpr.getText();\n\t\tloadData.setEscape(escapse);\n\t\tString charset = statement.getCharset() != null ? statement.getCharset() : connectionCharset;\n\t\tloadData.setCharset(charset);\n\n\t\tString fileName = parseFileName(sql);\n\t\tif(StringUtils.isBlank(fileName)){\n\t\t\tthrow new RuntimeException(\" file name is null !\");\n\t\t}\n\n\t\tloadData.setFileName(fileName);\n\n\t\treturn loadData ;\n\t}\n\n\t// 处理文件名\n\tprivate String parseFileName(String sql)\n\t{\n\t\tif (sql.contains(\"'\"))\n\t\t{\n\t\t\tint beginIndex = sql.indexOf(\"'\");\n\t\t\treturn sql.substring(beginIndex + 1, sql.indexOf(\"'\", beginIndex + 1));\n\t\t} else if (sql.contains(\"\\\"\"))\n\t\t{\n\t\t\tint beginIndex = sql.indexOf(\"\\\"\");\n\t\t\treturn sql.substring(beginIndex + 1, sql.indexOf(\"\\\"\", beginIndex + 1));","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/handler/HintDataNodeHandler.java#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n\"LOAD DATA INFILE INTO TABLE t\"; // file name is null !\n// after\n\"LOAD DATA INFILE '/data/import/t.csv' INTO TABLE t\";","handlingStrategy":"validation","validationCode":"Matcher m = Pattern.compile(\"LOAD\\\\s+DATA\\\\s+(?:LOW_PRIORITY\\\\s+|CONCURRENT\\\\s+)?(?:LOCAL\\\\s+)?INFILE\\\\s+'?([^'\\\\s]+)'?\", Pattern.CASE_INSENSITIVE).matcher(sql);\nif (!m.find() || m.group(1).trim().isEmpty()) throw new IllegalArgumentException(\"LOAD DATA missing file name\");","typeGuard":"String extractLoadDataFile(String sql) {\n  Matcher m = Pattern.compile(\"INFILE\\\\s+'?([^'\\\\s]+)'?\", Pattern.CASE_INSENSITIVE).matcher(sql);\n  return (m.find() && m.group(1) != null && !m.group(1).trim().isEmpty()) ? m.group(1) : null;\n}","tryCatchPattern":"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; }","preventionTips":["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."],"tags":["sql","load-data","parsing","hint"],"backgroundTag":"empty-required-field","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"}