Skip to content

Commit 193db4f

Browse files
authored
Add measurement files, time ranges, progress and logs to export-data (#18987)
* Add measurement files, time ranges, progress and logs to export-data - -mf/--measurement_file exports the measurements matched by the IoTDB path patterns in a file, one output per measurement named by its full path. The whole file is validated before any query, and each unmatched pattern is reported with its line. - -start_time/-end_time form an inclusive interval for measurement-file and automatic Table exports. Queries run as written and report the ignored bounds as a WARNING. - Progress is reported every two seconds: one redrawn line in a terminal, one line per update otherwise, with an ETA in measurement-file mode. - Every run appends a JSON Lines log, <target>/log_export_data_<time>.log by default or the path given with -l/--export_data_log, ending with one FINISH event. The console ends with the summary, after the log path. - CSV and SQL files are split by data rows; the INSERT statements of one row stay in one file. - Ctrl+C and SIGTERM stop at the next row, close the query and the session and exit with 130 or 143; failures exit with 1. - A Table query exported as SQL or TsFile still writes to the table it reads, as in #18828; -table is ignored with a WARNING, and every query is checked before the first one runs. * Check the columns of Table SQL/TsFile export queries - A Table query exported as SQL or TsFile must select * or column names from one table of -db. Aliases, expressions and FILL would write values the table does not hold under its column names, so they are rejected, as are EXPLAIN, set operations, column aliases and subqueries without a table. - The query must return the time column and at least one FIELD column, each column once; TsFile queries also need every TAG column. The columns are checked against the table before the first query runs and again against the columns the query returns. - Export option descriptions move to Constants, keeping their lines within 100 characters, and the -q and -db help text is shortened. * Read Table TsFile export values through a TypeService The repository architecture test allows switches on TSDataType only inside a TypeService, and ExportDataTable.exportTsFile switched on the column type for every value. It now resolves one reader per column from a TypeService, keeping the same getters: getLong for TIMESTAMP, getDate for DATE, getBlob for BLOB and getObject for the other types.
1 parent e3ad535 commit 193db4f

23 files changed

Lines changed: 5235 additions & 1173 deletions

File tree

‎integration-test/src/test/java/org/apache/iotdb/tools/it/ExportDataMeasurementIT.java‎

Lines changed: 520 additions & 0 deletions
Large diffs are not rendered by default.

‎iotdb-client/cli/src/main/i18n/en/org/apache/iotdb/cli/i18n/CliMessages.java‎

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public final class CliMessages {
8585
EXCEPTION_SQL_TSFILE_EXPORT_REQUIRES_A_QUERY_FROM_A_SINGLE_TABLE_IN_DATABASE_ARG_C9EB3768 =
8686
"SQL/TsFile export requires a query from a single table in database %s.";
8787
public static final String
88-
MESSAGE_QUERY_TO_EXPORT_TABLE_SQL_TSFILE_QUERIES_REQUIRE_A_SINGLE_TABLE_WITHOUT_JOINS_SUBQUERIES_OR_CTES_OVERRIDES_TABLE_START_TIME_AND_END_TIME_OPTIONAL_CC12D400 =
89-
"Query to export. Table SQL/TsFile queries require a single table without joins, subqueries or CTEs. Overrides -table, -start_time and -end_time. (optional)";
88+
MESSAGE_QUERY_TO_EXPORT_OPTIONAL_TABLE_SQL_TSFILE_STORED_COLUMNS_OF_ONE_TABLE_6D79406B =
89+
"Query to export (optional). Table SQL/TsFile: stored columns of one table.";
9090
public static final String
9191
MESSAGE_MULTIPLE_CSV_HEADERS_RESOLVE_TO_THE_SAME_TARGET_COLUMN_99189563 =
9292
"Multiple CSV headers resolve to the same target column.";
@@ -116,4 +116,155 @@ private CliMessages() {}
116116
public static final String LOG_INPUT_TIME_FORMAT_ARG_NOT_SUPPORTED_00172A7B = "Input time format {} is not supported, ";
117117
public static final String LOG_PLEASE_INPUT_LIKE_YYYY_MM_DD_HH_MM_SS_SSS_9318BFC7 = "please input like yyyy-MM-dd\\ HH:mm:ss.SSS or yyyy-MM-dd'T'HH:mm:ss.SSS%n";
118118

119+
// Export data
120+
public static final String MESSAGE_EXPORT_LOG_FILE_DEFAULT_TARGET_LOG_EXPORT_DATA_YYYYMMDDHHMMSS_LOG_B29FC35F =
121+
"Export log file (default: <target>/log_export_data_yyyyMMddHHmmss.log).";
122+
public static final String MESSAGE_INCLUSIVE_START_TIME_FOR_MEASUREMENT_FILE_OR_AUTOMATIC_TABLE_EXPORT_69FE75CF =
123+
"Inclusive start time for measurement-file or automatic Table export.";
124+
public static final String MESSAGE_INCLUSIVE_END_TIME_FOR_MEASUREMENT_FILE_OR_AUTOMATIC_TABLE_EXPORT_D9C24D95 =
125+
"Inclusive end time for measurement-file or automatic Table export.";
126+
public static final String MESSAGE_UTF_8_IOTDB_PATH_PATTERN_FILE_FOR_TREE_EXPORT_MUTUALLY_EXCLUSIVE_WITH_Q_DD1F2CDA =
127+
"UTF-8 IoTDB path-pattern file for Tree export; mutually exclusive with -q.";
128+
public static final String MESSAGE_TABLE_TO_EXPORT_OPTIONAL_IGNORED_WHEN_Q_IS_GIVEN_4F37C0B5 =
129+
"Table to export (optional). Ignored when -q is given.";
130+
public static final String
131+
MESSAGE_DATABASE_TO_EXPORT_REQUIRED_WITHOUT_TABLE_OR_Q_EXPORTS_ALL_ITS_TABLES_704F6B55 =
132+
"Database to export (required). Without -table or -q, exports all its tables.";
133+
public static final String MESSAGE_MAXIMUM_DATA_ROWS_PER_CSV_OR_SQL_FILE_DEFAULT_10000_000CEFB9 =
134+
"Maximum data rows per CSV or SQL file (default 10000).";
135+
public static final String EXCEPTION_FILE_PREFIX_MUST_NOT_CONTAIN_PATH_SEPARATORS_ARG_C89823EE =
136+
"File prefix must not contain path separators: %s";
137+
public static final String EXCEPTION_INVALID_OUTPUT_TIME_FORMAT_ARG_9C690675 =
138+
"Invalid output time format: %s";
139+
public static final String EXCEPTION_EXPORTING_INFORMATION_SCHEMA_IS_NOT_SUPPORTED_6FD0FB85 =
140+
"Exporting information_schema is not supported.";
141+
public static final String EXCEPTION_THE_EXPORT_LOG_MUST_DIFFER_FROM_THE_MEASUREMENT_INPUT_FILE_088A542C =
142+
"The export log must differ from the measurement input file.";
143+
public static final String LOG_PLEASE_INPUT_YOUR_PASSWORD_AEE49DC5 =
144+
"Please input your password:";
145+
public static final String LOG_PLEASE_INPUT_YOUR_TRUST_STORE_4C50D824 =
146+
"Please input your trust_store:";
147+
public static final String LOG_PLEASE_INPUT_YOUR_TRUST_STORE_PASSWORD_86ED5CB6 =
148+
"Please input your trust_store_password:";
149+
public static final String LOG_PLEASE_INPUT_YOUR_KEY_STORE_AC5DB91F =
150+
"Please input your key_store:";
151+
public static final String LOG_PLEASE_INPUT_YOUR_KEY_STORE_PASSWORD_19ED16D4 =
152+
"Please input your key_store_password:";
153+
public static final String EXCEPTION_UNSUPPORTED_SQL_DIALECT_ARG_C4D0D97C =
154+
"Unsupported sql_dialect: %s";
155+
public static final String EXCEPTION_SPECIFY_AN_EXPORT_FORMAT_CSV_SQL_OR_TSFILE_RECEIVED_ARG_5B5211B5 =
156+
"Specify an export format: csv, sql or tsfile (received: %s).";
157+
public static final String EXCEPTION_MEASUREMENT_FILE_IS_SUPPORTED_ONLY_IN_THE_TREE_MODEL_1ED604B5 =
158+
"-measurement_file is supported only in the Tree model.";
159+
public static final String EXCEPTION_MEASUREMENT_FILE_AND_Q_ARE_MUTUALLY_EXCLUSIVE_7A7457D6 =
160+
"-measurement_file and -q are mutually exclusive.";
161+
public static final String EXCEPTION_UNEXPECTED_POSITIONAL_ARGUMENTS_ARG_027F44CB =
162+
"Unexpected positional arguments: %s";
163+
public static final String EXCEPTION_INVALID_POSITIVE_INTEGER_FOR_OPTION_ARG_ARG_30FB488D =
164+
"Invalid positive integer for option %s: %s";
165+
public static final String EXCEPTION_OPTION_ARG_REQUIRES_TRUE_OR_FALSE_ARG_0DC9BE3D =
166+
"Option %s requires true or false: %s";
167+
public static final String EXCEPTION_START_TIME_MUST_BE_LESS_THAN_OR_EQUAL_TO_END_TIME_3551199C =
168+
"start_time must be less than or equal to end_time.";
169+
public static final String EXCEPTION_CANNOT_PARSE_TIME_ARG_ARG_40257DF7 =
170+
"Cannot parse time %s: %s";
171+
public static final String EXCEPTION_MEASUREMENT_INPUT_MUST_BE_A_READABLE_REGULAR_FILE_ARG_43D4A272 =
172+
"Measurement input must be a readable regular file: %s";
173+
public static final String EXCEPTION_A_COMPLETE_IOTDB_PATH_PATTERN_STARTING_WITH_ROOT_IS_REQUIRED_7D000A79 =
174+
"A complete IoTDB path pattern starting with root is required.";
175+
public static final String EXCEPTION_INVALID_MEASUREMENT_INPUT_ARG_AT_LINE_ARG_CONTENT_ARG_ARG_27A0F948 =
176+
"Invalid measurement input %s at line %d, content=%s: %s";
177+
public static final String EXCEPTION_CANNOT_READ_UTF_8_MEASUREMENT_FILE_ARG_AT_LINE_ARG_ARG_A5739D3F =
178+
"Cannot read UTF-8 measurement file %s at line %d: %s";
179+
public static final String EXCEPTION_MEASUREMENT_INPUT_CONTAINS_NO_PATH_PATTERNS_ARG_96760070 =
180+
"Measurement input contains no path patterns: %s";
181+
public static final String EXCEPTION_MEASUREMENT_OUTPUT_FILENAME_EXCEEDS_THE_SUPPORTED_LENGTH_ARG_FF01275D =
182+
"Measurement output filename exceeds the supported length: %s";
183+
public static final String EXCEPTION_MEASUREMENTS_ARG_AND_ARG_MAP_TO_THE_SAME_OUTPUT_FILENAME_ARG_58E1FD4D =
184+
"Measurements %s and %s map to the same output filename: %s";
185+
public static final String EXCEPTION_EXPORT_OUTPUT_CONFLICTS_WITH_THE_LOG_FILE_ARG_F01BE79D =
186+
"Export output conflicts with the log file: %s";
187+
public static final String LOG_EXPORT_STARTED_45465087 =
188+
"Export started.";
189+
public static final String LOG_EXPORT_COMPLETELY_34200D19 =
190+
"Export completely!";
191+
public static final String EXCEPTION_EXPORT_CANCELLED_85D44F54 =
192+
"Export cancelled.";
193+
public static final String LOG_EXPORT_FAILED_77EE72CD =
194+
"Export failed.";
195+
public static final String LOG_CANNOT_WRITE_OR_CLOSE_THE_EXPORT_LOG_32579AC6 =
196+
"Cannot write or close the export log.";
197+
public static final String LOG_EXPORT_STARTED_ARG_ARG_TARGET_ARG_LOG_ARG_BD58AECB =
198+
"Export started (%s, %s): target %s, log %s";
199+
public static final String LOG_MEASUREMENTS_TO_EXPORT_ARG_PATH_PATTERNS_ARG_A0AC5F31 =
200+
"Measurements to export: %d (path patterns: %d).";
201+
public static final String LOG_EXPORTING_ARG_ARG_ARG_ARG_ROWS_ARG_ETA_ARG_C41CA790 =
202+
"Exporting %s %d/%d %s rows %s ETA %s";
203+
public static final String LOG_ARG_ARG_ARG_MEASUREMENTS_ARG_ROWS_ELAPSED_ARG_ETA_ARG_CURRENT_ARG_B6DEA0BD =
204+
"[%s] %d/%d measurements, %s rows, elapsed %s, ETA %s, current %s";
205+
public static final String LOG_EXPORTING_ARG_ROWS_ARG_ARG_ROWS_S_56BD441C =
206+
"Exporting %s rows %s %s rows/s";
207+
public static final String LOG_ARG_ROWS_ELAPSED_ARG_ARG_ROWS_S_AE3CF660 =
208+
"%s rows, elapsed %s, %s rows/s";
209+
public static final String LOG_WARNING_ARG_05BE32E9 =
210+
"WARNING: %s";
211+
public static final String LOG_EXPORT_COMPLETELY_MEASUREMENTS_ARG_ARG_ROWS_ARG_FILES_ARG_ELAPSED_ARG_36D9F8E5 =
212+
"Export completely! Measurements: %d/%d, rows: %s, files: %s, elapsed: %s.";
213+
public static final String LOG_EXPORT_COMPLETELY_ROWS_ARG_FILES_ARG_ELAPSED_ARG_A94BBB8B =
214+
"Export completely! Rows: %s, files: %s, elapsed: %s.";
215+
public static final String LOG_EXPORT_FAILED_AFTER_ARG_ARG_C123F0EF =
216+
"Export failed after %s: %s";
217+
public static final String LOG_EXPORT_FAILED_AFTER_ARG_DA6D56F9 =
218+
"Export failed after %s.";
219+
public static final String LOG_EXPORT_CANCELLED_AFTER_ARG_ROWS_EXPORTED_ARG_0999F99F =
220+
"Export cancelled after %s. Rows exported: %s.";
221+
public static final String LOG_LOG_ARG_FBF61F63 =
222+
"Log: %s";
223+
public static final String LOG_ARG_82AC62F7 =
224+
"%.2f%%";
225+
public static final String EXCEPTION_AGGREGATE_QUERIES_CANNOT_BE_EXPORTED_AS_SQL_OR_TSFILE_48BC1932 =
226+
"Aggregate queries cannot be exported as SQL or TsFile.";
227+
public static final String LOG_NO_MEASUREMENTS_MATCHED_ARG_MEASUREMENT_FILE_LINE_ARG_94C4EF10 =
228+
"No measurements matched %s (measurement file line %d).";
229+
public static final String LOG_START_TIME_AND_END_TIME_DO_NOT_APPLY_TO_QUERIES_AND_ARE_IGNORED_02DC37CC =
230+
"-start_time and -end_time do not apply to queries and are ignored.";
231+
public static final String LOG_TABLE_DOES_NOT_APPLY_TO_QUERIES_AND_IS_IGNORED_DBA31209 =
232+
"-table does not apply to queries and is ignored.";
233+
public static final String EXCEPTION_NO_MEASUREMENTS_REMAIN_AFTER_PATTERN_EXPANSION_AND_DEDUPLICATION_40D930B7 =
234+
"No measurements remain after pattern expansion and deduplication.";
235+
public static final String EXCEPTION_THE_TARGET_DATABASE_ARG_DOES_NOT_EXIST_80E096EB =
236+
"The target database %s does not exist.";
237+
public static final String EXCEPTION_THERE_ARE_NO_TABLES_OR_THE_TARGET_TABLE_ARG_DOES_NOT_EXIST_E5F88A98 =
238+
"There are no tables or the target table %s does not exist.";
239+
public static final String LOG_PLEASE_INPUT_QUERY_EEAD5433 =
240+
"Please input query: ";
241+
public static final String EXCEPTION_NO_EXPORT_QUERY_WAS_PROVIDED_09E24A92 =
242+
"No export query was provided.";
243+
public static final String LOG_EXPORT_FAILED_ARG_57F9420F =
244+
"Export failed: %s";
245+
public static final String EXCEPTION_CANNOT_OBTAIN_SCHEMA_FOR_MEASUREMENT_ARG_D3F1DAF3 =
246+
"Cannot obtain schema for measurement %s.";
247+
public static final String
248+
EXCEPTION_SQL_TSFILE_OUTPUT_REQUIRES_THE_TIME_COLUMN_AND_COLUMNS_OF_TABLE_ARG_14B7FB67 =
249+
"SQL/TsFile output requires the time column and columns of table %s.";
250+
public static final String
251+
EXCEPTION_SQL_TSFILE_EXPORT_CAN_ONLY_SELECT_OR_COLUMN_NAMES_WITHOUT_FILL_EC83126D =
252+
"SQL/TsFile export can only select * or column names, without FILL.";
253+
public static final String
254+
EXCEPTION_SQL_TSFILE_OUTPUT_REQUIRES_A_FIELD_COLUMN_FROM_TABLE_ARG_1C08B044 =
255+
"SQL/TsFile output requires a FIELD column from table %s.";
256+
public static final String
257+
EXCEPTION_TSFILE_OUTPUT_REQUIRES_EVERY_TAG_COLUMN_FROM_TABLE_ARG_901F420F =
258+
"TsFile output requires every TAG column from table %s.";
259+
public static final String EXCEPTION_SQL_OUTPUT_REQUIRES_ORIGINAL_MEASUREMENT_PATHS_OR_AN_ALIGN_BY_DEVICE_QUERY_ADA72EA8 =
260+
"SQL output requires original measurement paths or an ALIGN BY DEVICE query.";
261+
262+
263+
264+
265+
public static final String EXCEPTION_EXPORT_OUTPUT_CONFLICTS_WITH_THE_MEASUREMENT_INPUT_FILE_ARG_1CBEBB6C =
266+
"Export output conflicts with the measurement input file: %s";
267+
public static final String EXCEPTION_TREE_TSFILE_OUTPUT_REQUIRES_A_TIME_COLUMN_AND_ORIGINAL_MEASUREMENT_PATHS_1DCEE8EA =
268+
"Tree TsFile output requires a time column and original measurement paths.";
269+
119270
}

0 commit comments

Comments
 (0)