Repository navigation
Support tags and attributes in tree-model schema export/import - #19150
CritasWang wants to merge 8 commits into
Conversation
3ffe671 to
087ed76
Compare
| } else { | ||
| builder.setQuote('`').setEscape('\\'); | ||
| } | ||
| return builder.build().parse(new InputStreamReader(new FileInputStream(path))); |
There was a problem hiding this comment.
[P1] Use an explicit UTF-8 charset for schema CSV I/O. The V2 format carries arbitrary tag and attribute text, but this reader uses the platform default charset. The exporter also opens new PrintWriter(filePath) with the platform default. On supported JDK 17 Windows, values such as 中文😀 may be replaced during export; files exchanged across platforms can also be decoded incorrectly on import. The new round-trip test reads the file as UTF-8, so this can fail there too. Please use UTF-8 consistently for writing, parsing, and header detection.
There was a problem hiding this comment.
Fixed in 610e1a2 — thanks, and you were right on all three points.\n\nAll schema I/O is now pinned to (11 call sites):\n\n| File | Site |\n| --- | --- |\n| | 3 × in (export, and the failed-records files) |\n| | parse stream, and (header detection) |\n| | 3 × (table-model SQL output) |\n| | and the failed-file |\n\nI also fixed the table-model sites in the same package: same defect, and leaving them would have produced the same review comment on the next PR.\n\nTwo regression tests in :\n- — writes through the real writer and compares the bytes on disk against the expected UTF-8 encoding.\n- — writes the file as UTF-8 bytes directly (so only the reader's charset can change the outcome) and reads it back through and .\n\nBoth are charset-sensitive rather than merely passing on a UTF-8 default: with the writer test fails before the fix ( — the character is replaced) and passes after it. Full suite: 102 tests, 0 failures; test-compile green; clean.
HTHou
left a comment
There was a problem hiding this comment.
Comments on the tree-model schema import path.
| paths.add(0, path.substring(deviceId.length() + 1)); | ||
| if (v2) { | ||
| // keep the maps aligned with the measurements list, whose head now holds this one | ||
| tags.add(0, recordTags); |
There was a problem hiding this comment.
[P2] Exercise aligned import through the CLI and server
The CLI rejects -aligned true with Unrecognized option. The new test sets aligned directly and expects the request to contain both s1 and root.sg.d.s1 alongside one data type. The server rejects the full path because each measurement must be a single node name.
Please register the CLI option and send one measurement with matching type, encoding, compression, alias, tags, and attributes per row. An end-to-end test would catch both failures.
There was a problem hiding this comment.
Fixed in 49d8409.
import-schema now registers -aligned / --use_aligned. Each valid aligned row sends exactly one measurement and one corresponding entry for type, encoding, compression, alias, tags, and attributes. MeasurementPath preserves quoted measurement names containing dots. The existing incorrect mock expectation has been corrected.
Added alignedImportThroughCliPreservesEveryRow, which runs the actual import script against the server for both v2 and legacy CSV files. It covers aliases, missing metadata, multiple measurements/devices, and a quoted measurement name, compares every schema field read back from the server, and checks that the devices are aligned.
Passed with both SimpleIT (1C1D) and ClusterIT (1C3D).
| if (trimmed.isEmpty() || "null".equals(trimmed)) { | ||
| return null; | ||
| } | ||
| Map<String, String> parsed = JSON_GSON.fromJson(trimmed, JSON_CELL_TYPE); |
There was a problem hiding this comment.
[P2] Reject null metadata values before batching
Gson accepts a cell such as {"room":null} as a map containing a null value. Thrift then throws NullPointerException in writeString while serializing the map, so the entire createMultiTimeseries batch fails, including valid rows.
Please validate that each value in Tags and Attributes is a JSON string before adding the row to the batch. The existing failed-records path can then capture the invalid row.
There was a problem hiding this comment.
Fixed in 49d8409.
Metadata values are now decoded as JsonElement and checked to be strings before a row enters either import path. JSON nulls, numbers, booleans, arrays, and objects are rejected through the existing failed-records path. Empty metadata cells/objects and string values such as "null" remain supported, and duplicate-key rejection is preserved.
Added unit coverage for batch isolation and invalidMetadataIsIsolatedFromValidRowsThroughCli for the real script/server path. The latter checks all five invalid value types in both Tags and Attributes, verifies the exact 10 rows written to the failed file, and confirms that valid rows, including an aliased row, are created correctly.
Passed with both SimpleIT (1C1D) and ClusterIT (1C3D).
| try (BufferedReader reader = | ||
| new BufferedReader( | ||
| new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8))) { | ||
| String headerLine = reader.readLine(); |
There was a problem hiding this comment.
[P3] Use consistent header handling for format detection and parsing
The probe reads the first physical line. CSVParser skips leading empty lines, so a leading blank line sends a V2 file through the legacy parser and splits quoted Tags JSON containing a comma. A UTF-8 BOM also becomes part of the Timeseries header and causes validation to reject the file.
Please apply the same rules for leading blank lines and an optional BOM during detection and parsing.
There was a problem hiding this comment.
Fixed in 49d8409.
Format detection and CSV parsing now share the same UTF-8 reader, which strips an optional BOM at the start of the file. Detection skips leading empty lines consistently with the parser's ignoreEmptyLines setting. The separate RFC4180 and legacy backtick/backslash settings are retained.
Regression coverage includes LF/CRLF prefixes, BOM with and without leading empty lines, quoted/unquoted v2 headers, Tags JSON containing a comma, and legacy escaping. The real CLI/server tests also import files with a BOM and leading empty lines; all three integration cases passed in both 1C1D and 1C3D environments.
|
Pushed 49d8409 to address the three review comments:
Local validation on macOS with Microsoft OpenJDK 21:
The integration runs used |
HTHou
left a comment
There was a problem hiding this comment.
The targeted CLI tests passed, and SchemaTagsRoundTripIT passed in both local 1C1D and 1C3D runs. The inline comments cover five additional cases reproduced with the CLI.
| tagsList, | ||
| attributesList, | ||
| --retryTime); | ||
| } |
There was a problem hiding this comment.
[P1] Report aligned import failures when connection retries are exhausted
I ran import-schema -aligned true with a valid seven-column CSV and an unused local port. After exhausting its retries, the CLI printed Import completely successful!, exited with code 0, and produced no failed-record file. The last IoTDBConnectionException falls through this branch and the row is cleared.
Please propagate the final connection error to the command exit status and preserve the failed row for retry.
There was a problem hiding this comment.
Fixed in 686cf2f. Both create paths now return the failure instead of swallowing it: when the retries are exhausted, the affected rows are written to the failed-record file and throws, so exits non-zero and prints the failure (the message names the device or first path plus the last ).\n\nReproduced your scenario in a unit test: a mocked pool that always throws now makes the run throw and leaves in the failed file — for both the batch path and the aligned path (, ).
| dataTypes.clear(); | ||
| encodings.clear(); | ||
| compressors.clear(); | ||
| pathsWithAlias.clear(); |
There was a problem hiding this comment.
[P2] Record failures from the aliased batch before clearing it
With -batch 2 and three aliased rows, an alias of bad.alias on the second row made the server reject the first two rows. The catch block reads paths, which is empty for an all-aliased batch. Only the third time series was created, but the CLI reported complete success and wrote no failed-record file.
Please capture the failed rows from the aliased batch, including their alias and metadata, before clearing its buffers.
There was a problem hiding this comment.
Fixed in 686cf2f. The aliased flush recorded from (empty for an all-aliased batch) instead of ; both the batch-boundary and the final flush now record the aliased rows, and each entry carries path, alias, type, encoding, compression, tags and attributes so the failed file is usable for a retry.\n\nCovered by : with two aliased rows and a pool that rejects the batch leaves both paths and both aliases in the failed file.
| } | ||
|
|
||
| static boolean checkHeader(List<String> headerNames) { | ||
| if (isV2Format(headerNames)) { |
There was a problem hiding this comment.
[P2] Keep format detection and header validation consistent
A seven-column CSV with headers named Tags and Attributes is detected as V2 because the probe trims the names. The parser preserves the leading spaces, so validation and writeScheme treat the same file as legacy and silently discard both metadata columns. I verified that the CLI reported success and created the time series without its metadata.
Please use the same normalized headers throughout, or explicitly reject the file when a V2 header fails validation.
There was a problem hiding this comment.
Fixed in 686cf2f. Format detection, header validation and column lookup now share one pass, so a header like / is v2 consistently and the metadata columns are no longer dropped. also reports the seven-column format for such a file if a column is missing.\n\nCovered by : the padded header imports and the tags map reaches .
| compressors.add(compressionType); | ||
| measurementAlias.add(StringUtils.isBlank(alias) ? null : alias); | ||
| if (v2) { | ||
| tags.add(recordTags); |
There was a problem hiding this comment.
[P3] Omit metadata parameters for aligned rows with empty metadata
For aligned rows with both cells empty, the lists still contain a null entry. Session converts the entries to empty maps for Thrift, so the server writes a tag log record for each row. Importing the same 12 aligned measurements left tlog.txt at 0 bytes with the five-column CSV and wrote 8,400 bytes with the seven-column CSV.
Please omit both metadata lists when the aligned row has neither tags nor attributes.
There was a problem hiding this comment.
Fixed in 686cf2f. The aligned writer now calls the shorter overload when every metadata entry of the row is null, so no tag log record is written for a row without tags and attributes.\n\nCovered by , which snapshots the invocation and asserts only six arguments were passed; was extended to capture both overloads.
| if (trimmed.isEmpty() || "null".equals(trimmed)) { | ||
| return null; | ||
| } | ||
| Map<String, JsonElement> parsed = JSON_GSON.fromJson(trimmed, JSON_CELL_TYPE); |
There was a problem hiding this comment.
[P3] Require a JSON object with strict JSON syntax
The Gson map adapter accepts [["room","101"]], and the default parser accepts {"room":yes}. I verified that both cells import successfully, even though the format specifies a JSON object with string values.
Please check the root token and use strict JSON parsing while preserving duplicate-key rejection and the supported empty-cell behavior.
There was a problem hiding this comment.
Fixed in 686cf2f. Metadata cells are parsed with a strict () driven explicitly: the document must be an object, every value must be a JSON string token, trailing content is rejected and duplicate keys are rejected. The empty-cell and literal behaviours are unchanged.\n\nCovered by — , , and trailing garbage are all rejected while , empty and still work — and by .\n\nVerification for the whole batch: 115 tests pass, test-compile green, clean.
7a21e9f to
73daa4c
Compare
The tree-model schema source joined the tags and attributes maps into a JSON object without escaping, so a value containing a quote, a backslash or a control character produced a document that no JSON reader accepts. Escape the string values the way RFC 8259 requires, leave printable non-ASCII characters raw, and share the implementation with the logical view source instead of keeping a second copy of it.
Extend the seven-column version 2 CSV with a Tags and an Attributes column so that a tree-model schema exports and imports without losing metadata. The columns hold a compact JSON object, written and read with the gson that ships inside ratis-thirdparty-misc: the reader is strict, so a JSON array of pairs, an unquoted token and a duplicate key are rejected instead of silently accepted. A five-column file is still imported as before, the header alone decides which format is in use, and every read and write pins UTF-8 so that a non-ASCII tag survives a platform with a different default charset. A rejected batch now reports its rows together with their alias and metadata instead of dropping them, an exhausted connection retry reaches the exit status instead of looking like success, and an aligned row without metadata no longer passes all-null lists that make the server write a tag log record.
Export a schema that carries awkward tag values, aliases and every data type, import it into an empty cluster and compare the result with what was exported. The cases cover the presence combinations of tags and attributes and mixed devices, and read a NULL alias back as null instead of the literal text.
73daa4c to
ead5699
Compare
|
The branch is now rebased onto the current master and the history is rewritten into three commits, so the earlier per-comment commit hashes no longer exist. The working tree is byte-identical to the previous push.\n\n\n\nAll five review points are contained in :\n\n- an exhausted connection retry is recorded, its rows go to the failed-record file and the command exits non-zero;\n- a rejected aliased batch is recorded with its alias and metadata;\n- header names are normalised once, for detection, validation and column lookup;\n- an aligned row without metadata omits the metadata parameters;\n- the metadata cells are read with a strict reader that rejects a JSON array of pairs, an unquoted token, a duplicate key and trailing content.\n\nVerification on this revision: 35 schema tests pass, is clean, and [INFO] |
…sted The connection failure was already reported to the console and the failed rows were written to the failed-record file, but writeScheme threw IllegalStateException after all of that work was done and the calling importSchemaFromCsvFile only caught IOException / IllegalPathException, so the exception was swallowed by the generic run() handler and importFromTargetPath returned CODE_OK (0). Add a connectionFailed flag in AbstractSchemaTool. The IllegalStateException that writeScheme raises on retry exhaustion is now caught separately in importSchemaFromCsvFile, which sets the flag instead of re-throwing. importFromTargetPath reads the flag after all files are processed and returns CODE_ERROR when it is set. Verified: import against an unreachable port now exits 1 for both aligned and non-aligned paths, the failed-record file is still written, and all 35 cli schema unit tests pass on both en and zh-locale compile.
09f87bc to
f6d3e51
Compare
Conflicts were limited to the table-model schema tools, where master replaced the line-based SQL splitting of import-schema with a lexer based stream: - ExportSchemaTable: keep master's Path based target directory handling and this branch's UTF-8 FileWriter. - ImportSchemaTable: adopt master's statement stream and re-apply the UTF-8 reader and failed-record writer. - ImportSchema: keep the status code returned by importFiles() and still exit non-zero when a file ran out of connection retries.
HTHou
left a comment
There was a problem hiding this comment.
I reproduced the four cases below with the CLI. I recommend fixing the three P2 issues before merging because they affect recovery from incomplete imports. The P3 JSON strictness issue can be addressed in a follow-up.
| --retryTime); | ||
| } | ||
| for (String measurement : measurements) { | ||
| failedRecords.add(Collections.singletonList(deviceId + "." + measurement)); |
There was a problem hiding this comment.
[P2] Preserve the full aligned row when connection retries fail
I confirmed that import-schema -aligned true now exits with code 1 when the server is unreachable. The .failed_0 file contains only the path. It drops the alias, data type, encoding, compression, tags, and attributes. Importing that record under the seven-column header fails with Index 1 out of bounds for length 1.
Please preserve the complete row in the failed file before clearing the aligned batch.
There was a problem hiding this comment.
Fixed in d224bad. The exhausted-retry branch of the aligned import now records the whole row of every measurement of the batch before the batch is cleared: path, alias, data type, encoding, compression, tags and attributes.
Covered by SchemaTagsImportTest#exhaustedAlignedConnectionRetriesKeepTheWholeRow, which asserts the seven cells and that the failed file is importable under the seven-column header.
| row.add(i < dataTypes.size() ? dataTypes.get(i).name() : ""); | ||
| row.add(i < encodings.size() ? encodings.get(i).name() : ""); | ||
| row.add(i < compressors.size() ? compressors.get(i).name() : ""); | ||
| row.add(tagsList != null && i < tagsList.size() ? toJsonCell(tagsList.get(i)) : ""); |
There was a problem hiding this comment.
[P2] Keep failed CSV rows in one column order
With a valid header ending in Attributes,Tags, the rows rejected by CSV validation are saved in source order, while rows rejected by the RPC are saved in Tags,Attributes order. I reproduced both in a single .failed_0 file. When I restored the source header and retried, the RPC-failed row was imported with its owner attribute in Tags and its room tag in Attributes.
Please use one column order for every row in the failed file and write the corresponding header.
There was a problem hiding this comment.
Fixed in d224bad. Every rejected row is now kept in one canonical order (Timeseries, Alias, DataType, Encoding, Compression, Tags, Attributes) and projected onto the columns of the imported file only when the failed file is written, whose first line is that header. A header ending in Attributes,Tags therefore yields an Attributes,Tags failed file, and a legacy five-column file stays five columns. Rows rejected by the CSV validation copy their cells verbatim, so a rejected JSON cell is retried exactly as it was read instead of being re-serialized.
Covered by SchemaTagsImportTest#failedFileUsesOneColumnOrderForValidationAndRpcRejections: one validation rejection plus one RPC rejection end up in a single failed file under the source header, and re-importing that file puts owner back into Attributes and room back into Tags. #legacyFileFailsIntoAFiveColumnFileWithItsOwnHeader guards the legacy layout, and the integration test invalidMetadataIsIsolatedFromValidRowsThroughCli now asserts the header line as well.
| String.valueOf(e.getMessage())); | ||
| } catch (StatementExecutionException e) { | ||
| ioTPrinter.println(Constants.INSERT_CSV_MEET_ERROR_MSG + e.getMessage()); | ||
| System.exit(1); |
There was a problem hiding this comment.
[P2] Preserve failed records and continue after an aligned create rejection
With -aligned true, I imported a file containing an invalid metadata row, a valid row, a row with the alias bad.alias, and a final valid row. The server rejected the alias. Only the first valid row was created, and there was no failed file for the earlier validation error. System.exit(1) terminates the JVM before the failed rows are written and also stops other import workers.
Please record the server-rejected row, let the workers finish, and report the failure at the entry point.
There was a problem hiding this comment.
Fixed in d224bad. System.exit(1) is gone. A rejected aligned create now prints the server message, records the rejected rows, and returns the failure without aborting the remaining records of the file; at the end of the file the existing ConnectionRetriesExhaustedException path marks the run failed and ImportSchema returns CODE_ERROR, so the workers finish and the entry point reports the failure.
SchemaTagsImportTest#serverRejectedAlignedRowIsRecordedAndTheRestIsStillImported reproduces your file (invalid metadata row, valid row, bad.alias, final valid row): no JVM exit, both valid rows created, both rejected rows in the failed file, and the run reported as failed. The same flow is exercised end to end by SchemaTagsRoundTripIT against a real import-schema process.
|
|
||
| private static Map<String, String> parseStrictJsonObject(String text) { | ||
| JsonReader reader = new JsonReader(new StringReader(text)); | ||
| reader.setLenient(false); |
There was a problem hiding this comment.
[P3] Use strict JSON parsing for metadata cells
In the bundled Gson, setLenient(false) selects LEGACY_STRICT. I verified that the CLI still imports metadata strings containing a literal tab or the invalid escape \'.
reader.setStrictness(Strictness.STRICT) enforces JSON syntax. The duplicate-key and empty-cell handling can stay as implemented. This can be addressed in a follow-up.
There was a problem hiding this comment.
Fixed in 2d3001a rather than deferred. parseStrictJsonObject now calls reader.setStrictness(Strictness.STRICT); duplicate-key rejection, trailing-token rejection and the empty-cell/null behaviour are unchanged.
Covered by SchemaTagsFidelityTest#jsonSyntaxIsStrictlyEnforced: a raw tab and the escape \' are rejected, while \t and a plain apostrophe are still accepted.
The failed-record file mixed two column orders: the rows rejected by the CSV validation kept the order of the imported file while the rows rejected by the RPC were written in Tags,Attributes order, so restoring the header of a failed file could put a tag into the attribute column. Every failed row is now kept in one canonical order and projected onto the columns of the imported file when the failed file is written, whose first line is the header its rows follow. An exhausted connection retry on an aligned import kept the path only, which is not importable, and a create the server rejected called System.exit, which lost the rejected row and stopped the other import workers. Both paths now record the whole row and let the file finish; the entry point reports the failure through the existing status code.
setLenient(false) only selects LEGACY_STRICT, which still accepts a raw control character inside a string and the invalid escape \'. The reader now uses Strictness.STRICT, so a Tags or Attributes cell that is not JSON is rejected.
|
Pushed d224bad and 2d3001a to address all four points; the three P2 issues are fixed and the P3 JSON strictness is included rather than deferred.
Local validation on macOS (Microsoft OpenJDK 17):
One intentional format change: a |
HTHou
left a comment
There was a problem hiding this comment.
I verified the four earlier fixes with the CLI. The 42 focused unit tests and all three local 1C1D integration cases passed. I recommend fixing the two remaining failed-file retry issues before merging.
| for (List<Object> failedRow : failedRecords.subList(from, from + step)) { | ||
| failureFileRecords.add(projectFailedRow(failedRow, columns)); | ||
| } | ||
| writeCsvFile(failureFileRecords, failedFilePath + "_" + fileIndex++); |
There was a problem hiding this comment.
[P2] Make the generated failed files importable through the CLI
I passed a generated schema.csv.failed_0 to import-schema -s against a running server. The CLI printed that the filename must end in csv, skipped the file, and exited with code 0. Renaming that same seven-column file to .csv restored the row and its metadata.
The current retry test calls importSchemaFromCsvFile directly, so it bypasses the filename check. Please make the generated file usable through -s and exercise the original filename in the retry test.
There was a problem hiding this comment.
Fixed in 969d6c2. The generated chunks are now named <stem>.failed_<n>.csv (schema.csv -> schema.failed_0.csv, same name under -d <failed dir>), so the dispatcher's suffix check selects them and a failed file can be passed to -s exactly as it was written; chunking by linesPerFile is unchanged and the table dialect's statements.sql.failed naming is untouched.
SchemaTagsRoundTripIT#invalidMetadataIsIsolatedFromValidRowsThroughCli now takes the generated file and feeds it back to import-schema -s <generated file>: it asserts the CLI does not print the must-end-with-csv message for it and does process its rows. The unit retry tests import the generated file itself instead of a renamed copy.
One consequence worth flagging: because the failed files are *.csv now, a directory import (-s <dir>) also re-attempts files a previous run left there. That is what makes them usable through -s, but it is a behaviour change for directory imports - tell me if you would rather keep those untouched.
| .setEscape('\\') | ||
| .setQuoteMode(QuoteMode.NONE) | ||
| .build(); | ||
| this.csvFormat = createRfc4180CsvFormat().setHeader().setSkipHeaderRecord(true).build(); |
There was a problem hiding this comment.
[P2] Preserve legacy CSV escaping in five-column failed files
A valid five-column source can contain a path whose measurement is sensor,1, with the comma escaped as \, in the source. After a connection failure, the failed file keeps the five-column header but quotes the path using RFC 4180. On retry, that header selects the legacy parser, which splits the path at the comma and shifts the remaining cells.
I verified that the original source creates the series. Renaming the generated failed file to .csv and importing it creates zero series. Please use compatible CSV rules when writing and reading five-column failed files, and include an escaped comma in the retry test.
There was a problem hiding this comment.
Fixed in 969d6c2. The failed-record writer now picks the dialect from the columns it actually writes: a five-column file is written with the legacy escaped-delimiter layout (a comma inside a cell becomes \,, no quote char, matching what readCsvFile selects for a header without Tags and Attributes), while a seven-column file keeps RFC4180.
Covered by SchemaTagsImportTest#legacyFailedFileKeepsItsEscapedCommaAndCanBeImportedAgain: a source row whose path is root.sg.d.sensor\,1 runs out of connection retries, the generated file contains exactly root.sg.d.sensor\,1,aliasA,INT64,TS_2DIFF,SNAPPY and no " at all, and importing that generated file creates the series under root.sg.d.sensor,1 with alias, datatype, encoding and compression still in their own columns. On the pre-fix code the same row is written as "root.sg.d.sensor,1",aliasA,... and re-reads as six cells, which is the shift you reported.
A five-column failed file was written with RFC4180 quoting while the reader selects the legacy dialect for a header without Tags and Attributes, so a path carrying an escaped comma was quoted and then split at that comma on retry, shifting every cell that followed it and creating no series. The failed-record writer now picks the dialect from the columns it writes: the legacy escaped delimiter for five columns, RFC4180 for seven. The generated chunks are also named <stem>.failed_<n>.csv, so import-schema selects them by suffix and a failed file can be fed back through -s exactly as it was written instead of being renamed first.
Summary
Tree-model
export-schemadropped tags and attributes entirely, andimport-schemahad no way to restore them even thoughcreateMultiTimeseries/createAlignedTimeseriesaccept both. This PR makes a full export → import cycle preserve them exactly, including every special character.It is four commits:
bcaec8a3[Server] Render tags and attributes as valid JSON in SHOW TIMESERIES01cf3c46[Tools] Export and import tags and attributes in tree-model schema filesead56995[IT] Cover the tags and attributes round tripf6d3e51f[Tools] Exit non-zero when import-schema connection retries are exhaustedExample
Create two time series whose metadata contains the characters that used to break the format:
SHOW TIMESERIES root.e2e.**now renders both metadata columns as valid JSON:{"room":"101","type":"sensor"}{"note":"a"b","owner":"team a"}{"desc":"a,b","p":"a\\b"}Export:
Drop the database, import the same file into the empty database, and
SHOW TIMESERIESgives back the values above, with the alias, data type, encoding and compression intact:Error path — when the connection cannot be re-established, the rows land in
schema0_0.csv.failedand the command no longer reports success:1. Why the server change is required
The client has no API that returns tags as a
Map—Session/SessionPoolonly accepttagsListon write. Reading them is only possible through theTags/Attributescolumns ofSHOW TIMESERIES, andTimeSeriesSchemaSource.mapToStringconcatenated keys and values without escaping, so that column was not parseable data:a"b{"k":"a"b"}a\b{"k":"a�"}a<backspace>— silent corruptiona<TAB>b{"k":"a<TAB>b"}The fix escapes per RFC 8259 and keeps non-ASCII characters readable; it also removes the duplicate implementation in
LogicalViewSchemaSource. Output is byte-identical for values that need no escaping, so ordinary schemas are unaffected.2. File format
Export now writes seven columns:
Tags/Attributesare compact JSON objects with sorted keys and HTML escaping disabled; an absent set is an empty cell.", no escape character, LF). JSON cells are therefore quoted with their inner quotes doubled, which is what makes them round-trip.3. Compatibility
quote='',escape=''`), so existing exports keep importing unchanged.TagsorAttributespresent, leading and trailing spaces ignored), and such a header is rejected unless all seven expected columns are there.",\or control characters are now rendered escaped inSHOW TIMESERIES(previously the output was not valid JSON at all). Values without such characters are unchanged.","would need adjusting.4. Testing
Unit tests (real classes, no mocks except the session pool):
TimeSeriesSchemaSourceMapToStringTest(18 tests): every escaping case, and byte-identity with the old algorithm for values that need no escaping.SchemaTagsFidelityTest(18) andSchemaTagsImportTest(19): JSON cell encoding (sorted keys, no HTML escaping, empty cell), RFC4180 bytes, CSV round-trip for"\,tab newline CJK backtick, header normalisation, legacy detection, the create-call arguments for both the normal and the aligned path, and the connection-retry failure. The batch test was validated by reverting the fix and observing it fail (expected:<4> but was:<2>).Full local runs:
mvn test -pl iotdb-client/cli→ 125/125; datanode test for the escaping change → 18/18; both locales (-P with-zh-locale) compile;dependency:analyze-only -DfailOnWarning=trueclean.End-to-end on a real standalone cluster (built from this branch): created 18 time series covering
",\, a literal\n, tab, newline, CJK+emoji, literalnull, empty string, double spaces, backtick, a key with a space, multiple tags, attributes-only, neither, and an alias; exported, dropped the database, imported, and compared the server's rendering field by field — 18/18 identical. Editing one tag in the exported file with a spreadsheet tool and re-importing also worked, leaving the other rows untouched.SchemaTagsRoundTripITcovers the same scenario in CI (three test methods: the round trip, an aligned import through the CLI, and isolation of invalid metadata rows). It could not be executed in this environment (the integration-test assembly referencesiotdb-core/ainode/dist/ainode/, absent here), but it compiles, is spotless-clean, passes the repository's IT-selection check, and theSimple (17)shard that owns its category is green on CI.5. Not addressed here
Logical views, schema templates and device alignment are still not exported (they need different creation statements or device-level information); the import batch fix above is included because misaligned tags would otherwise corrupt exactly this feature's data.