Support TsFile properties and optional table point counting - #882
Support TsFile properties and optional table point counting#882jt2594838 wants to merge 10 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #882 +/- ##
===========================================
+ Coverage 60.47% 60.57% +0.10%
===========================================
Files 744 745 +1
Lines 49021 49267 +246
Branches 7787 7830 +43
===========================================
+ Hits 29644 29844 +200
- Misses 17972 18021 +49
+ Partials 1405 1402 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| /** Get the properties stored in the TsFile metadata. */ | ||
| public Map<String, String> getTsFileProperties() throws IOException { |
There was a problem hiding this comment.
This exposes TsFile properties through the low-level reader API so callers can retrieve file-level metadata without depending on internal metadata objects. The corresponding V4 reader/writer interfaces expose the same capability across implementations while preserving existing behavior for callers that do not use properties.
| public void endCurrentChunk() { | ||
| this.currentChunkMetadataSize += currentChunkMetadata.getRetainedSizeInBytes(); | ||
| chunkMetadataCount++; | ||
| if (recordTablePointCount |
There was a problem hiding this comment.
Point counting is opt-in to avoid changing existing write-path cost or file output by default. It aggregates only non-null FIELD values into tablePointCount.<tableName> properties; the mask check excludes timestamp chunks, while table-model device detection excludes tree-model data.
| * untouched. The source file is replaced only after a complete rewritten copy has been forced to | ||
| * disk. | ||
| */ | ||
| public static UpdateStatus updateTablePointCountIfMissing(File file) throws IOException { |
There was a problem hiding this comment.
This entry point backfills missing counts for complete table-model TsFiles by scanning timeseries metadata instead of enumerating every device. It preserves unrelated properties, skips files that already have valid counts, and replaces the source only after a temporary rewrite has been flushed; reflink cloning is used where available with a prefix-copy fallback.
| <destName>tools/arrow2tsfile.bat</destName> | ||
| </file> | ||
| <file> | ||
| <source>${maven.multiModuleProjectDirectory}/java/tools/src/assembly/resources/tools/tsfile-table-point-count.sh</source> |
There was a problem hiding this comment.
Packaging both launchers makes the repair utility directly available from the assembled tools distribution. The shell entry is explicitly marked executable, and the Windows launcher is placed beside it using the same tool name.
| - Multiple batches: `{source_basename}_1.tsfile`, `{source_basename}_2.tsfile`, ... | ||
| - Table name and output filename are independent — table name comes from schema or `--table_name`, filename comes from source file. | ||
|
|
||
| ## Table Point Count Tool |
There was a problem hiding this comment.
This section documents the tool point-count semantics, invocation, result statuses, in-place replacement behavior, and disk-space and backup considerations. The matching Chinese README and message bundles keep the user experience consistent with the project localization convention.
| * file data, and leave the file byte-for-byte unchanged when run again. | ||
| */ | ||
| @Test | ||
| public void backfillMissingTablePointCountProperties() throws Exception { |
There was a problem hiding this comment.
This test covers multi-table counting, null FIELD exclusion, preservation of unrelated properties and file data, and idempotent re-execution. The related API and writer tests cover property round trips and opt-in collection, while the performance test isolates enabled and disabled modes in separate JVMs to avoid warm-up bias.
There was a problem hiding this comment.
Pull request overview
Adds TsFile metadata property read/write support across writer/reader APIs, introduces optional table-level non-null FIELD point-count recording, and provides a repair tool to backfill missing table point-count properties in existing complete TsFiles.
Changes:
- Add
TsFilePropertiesAPIs to V4 writer/reader interfaces and toTsFileSequenceReader/TsFileIOWriter. - Add optional
TsFileIOWritermode to record per-table non-null FIELD point counts into TsFile properties. - Add
TsFileTablePointCountTool(plus scripts, i18n messages, and tests) to detect/backfill missing table point-count properties.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| java/tsfile/src/test/java/org/apache/tsfile/write/TsFileWriteApiTest.java | Adds a correctness test for table point-count property semantics (non-null FIELD only). |
| java/tsfile/src/test/java/org/apache/tsfile/write/TablePointCountPerformanceTest.java | Adds an opt-in (property-gated) performance comparison test for point counting. |
| java/tsfile/src/test/java/org/apache/tsfile/utils/TsFileTablePointCountToolTest.java | Adds repair-tool coverage: scanning, update behavior, property preservation, idempotency. |
| java/tsfile/src/test/java/org/apache/tsfile/read/TsFileV4ReadWriteInterfacesTest.java | Verifies properties are visible via both TsFileSequenceReader and V4 ITsFileReader. |
| java/tsfile/src/main/java/org/apache/tsfile/write/writer/TsFileIOWriter.java | Adds property collection and optional table point-count recording at write time. |
| java/tsfile/src/main/java/org/apache/tsfile/write/v4/ITsFileWriter.java | Adds addTsFileProperty to the V4 writer API. |
| java/tsfile/src/main/java/org/apache/tsfile/write/v4/AbstractTableModelTsFileWriter.java | Implements addTsFileProperty by delegating to the underlying writer. |
| java/tsfile/src/main/java/org/apache/tsfile/utils/TsFileTablePointCountTool.java | Introduces the repair tool: scan metadata and rewrite metadata tail (reflink+fallback). |
| java/tsfile/src/main/java/org/apache/tsfile/read/v4/ITsFileReader.java | Adds getTsFileProperties to the V4 reader API. |
| java/tsfile/src/main/java/org/apache/tsfile/read/v4/DeviceTableModelReader.java | Implements getTsFileProperties by delegating to the underlying reader. |
| java/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java | Adds getTsFileProperties() accessor for metadata properties. |
| java/tools/src/assembly/tools.xml | Packages the new tool launch scripts into the tools distribution. |
| java/tools/src/assembly/resources/tools/tsfile-table-point-count.sh | Adds Linux/macOS launcher for the repair tool. |
| java/tools/src/assembly/resources/tools/tsfile-table-point-count.bat | Adds Windows launcher for the repair tool. |
| java/tools/README.md | Documents the new repair tool in the tools README. |
| java/tools/README-zh.md | Adds Chinese documentation for the new repair tool. |
| java/common/src/main/resources/org/apache/tsfile/i18n/messages.properties | Adds i18n messages for tool usage/errors/output. |
| java/common/src/main/resources/org/apache/tsfile/i18n/messages_zh.properties | Adds Chinese i18n messages for tool usage/errors/output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tablePointCounts.forEach( | ||
| (tableName, pointCount) -> | ||
| metadata.addProperty( | ||
| TsFileIOWriter.TABLE_POINT_COUNT_PROPERTY_PREFIX + tableName, | ||
| Long.toString(pointCount))); |
There was a problem hiding this comment.
This is intentionally overwritten by design. The user should not specify this or use our key.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
TsFilePropertiesread/write APIs toTsFileIOWriter,TsFileSequenceReader,ITsFileWriter, andITsFileReaderTsFileIOWritermode that records non-null FIELD point counts per table in TsFile propertiesPoint-count semantics
tablePointCount.<tableName>key formatTable point-count repair tool
tsfile-table-point-count.shandtsfile-table-point-count.batVerification
mvn -P with-java -pl java/tsfile -am test-compile -DskipTestsEach performance mode performed an independent warm-up in its own Surefire JVM.