Skip to content

Commit d245edc

Browse files
authored
Fix NPE in table model export when -q is not specified (#17462)
When using export-data with table model (sql_dialect=table) and only specifying -db without -q, queryCommand is null. The original condition `sqlDialectTree && queryCommand == null` only handled the tree model case, causing the else branch to call `queryCommand.trim().split(";")` which throws NullPointerException. Restructure the branch logic to check `queryCommand == null` first: - Tree model + no query: interactive SQL input (unchanged) - Table model + no query: call exportBySql(null, 0) to auto-generate "select * from <table>" for all tables, which also correctly applies start_time/end_time filters - Query provided: split by semicolon for multi-statement support (unchanged)
1 parent 1c1cbca commit d245edc

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ExportData.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,22 @@ public static void main(String[] args) {
224224
exportData = new ExportDataTable();
225225
exportData.init();
226226
}
227-
if (sqlDialectTree && queryCommand == null) {
228-
LineReader lineReader =
229-
JlineUtils.getLineReader(
230-
new CliContext(System.in, System.out, System.err, ExitType.EXCEPTION),
231-
username,
232-
host,
233-
port);
234-
String sql = lineReader.readLine(Constants.EXPORT_CLI_PREFIX + "> please input query: ");
235-
ioTPrinter.println(sql);
236-
String[] values = sql.trim().split(";");
237-
for (int i = 0; i < values.length; i++) {
238-
exportData.exportBySql(values[i], i);
227+
if (queryCommand == null) {
228+
if (sqlDialectTree) {
229+
LineReader lineReader =
230+
JlineUtils.getLineReader(
231+
new CliContext(System.in, System.out, System.err, ExitType.EXCEPTION),
232+
username,
233+
host,
234+
port);
235+
String sql = lineReader.readLine(Constants.EXPORT_CLI_PREFIX + "> please input query: ");
236+
ioTPrinter.println(sql);
237+
String[] values = sql.trim().split(";");
238+
for (int i = 0; i < values.length; i++) {
239+
exportData.exportBySql(values[i], i);
240+
}
241+
} else {
242+
exportData.exportBySql(null, 0);
239243
}
240244
} else {
241245
String[] values = queryCommand.trim().split(";");

0 commit comments

Comments
 (0)