Files
greptimedb/docs/parquet-tools.md
T
AumandClaude Opus 5.5 6ffb0ec793 feat: answer scalar COUNT on Mito from SST metadata (#9891)
* feat: answer scalar COUNT on Mito from SST metadata

Behind `experimental_metadata_aggr` (off by default), ScanHintRule marks
an ungrouped scalar COUNT directly over a Mito scan. Mito then proves the
scan's row count without reading SST data. Every file intersecting the
query time range must be covered by the static predicates and have a
known manifest row count. In deduplicating regions it must also share no
(time, primary key) point with another file or a memtable, and its
`__op_type` Parquet statistics must show no deletions. The statistics are
read through the SST metadata caches, only for files that pass the
manifest checks. RegionScanExec publishes the proven count as exact
statistics, which lets DataFusion replace the scan with a literal. Other
scans are unchanged.

Overlaps are found with one time sweep over a segment tree of compressed
primary key bounds, in O(N log N). The pairwise check remains as the
test oracle and benchmark baseline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito): cover metadata COUNT and address core review

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito): match metadata aggregate fixture region IDs

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): prove SST row counts before publishing exact statistics

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): add SQLness coverage for the SST footer marker

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): verify tightened partition bounds and source estimates

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): keep lazy footer reads sendable

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): use valid sequence fences and SST owners

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): validate SST key bounds before metadata count

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): verify SST time bounds before metadata count

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): own SST inputs to asynchronous bound checks

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): match displayed scan names in COUNT fallback

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): keep SST replacements coherent with metadata counts

Signed-off-by: aumnertic <aumnertic@gmail.com>

* refactor(cmd): reuse the replacement SST reader during validation

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): verify listed SST sizes against object storage

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): keep metadata count proofs within the SST read set

Signed-off-by: aumnertic <aumnertic@gmail.com>

* docs(mito2): use the actual scan memory limit key

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): gate metadata counts on trusted SST dedup markers

Record the provenance of engine-written dedup markers in the manifest.
Clear it for external imports and preserve it during internal transfers.
Require this proof for metadata counts over non-append multi-row SSTs.

Keep the live file metadata consistent when an import supersedes a
background publication, and cover checkpoint downgrade and reopen.

Signed-off-by: aumnertic <aumnertic@gmail.com>

---------

Signed-off-by: aumnertic <aumnertic@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 11:43:27 +00:00

8.8 KiB

Parquet Development Tools

GreptimeDB provides the following datanode CLI commands for inspecting, rewriting, benchmarking, and replacing Parquet SST files:

  • parquet-meta: inspect a local Parquet file.
  • parquet-rewrite: rewrite a local Parquet file with different writer properties.
  • parquetbench: benchmark reads from a local GreptimeDB SST or an SST in a configured object store.
  • sst-replace: install a replacement Mito SST and update its manifest metadata.

These are development and recovery tools, not stable user-facing interfaces. Always test a workflow on disposable data before using it on an important region.

Build

parquet-meta, parquet-rewrite, and sst-replace require the dev-tools feature. The same build also includes parquetbench:

cargo build -p cmd --bin greptime --features dev-tools

The examples below use:

GREPTIME=./target/debug/greptime

Run $GREPTIME datanode <COMMAND> --help for the authoritative argument list.

Inspect a Parquet file

parquet-meta reads a local Parquet footer and optional page indexes. It reports file, row-group, and column metadata, including compression, encodings, sizes, page offsets, statistics presence, and bloom-filter/index offsets.

Text output:

$GREPTIME datanode parquet-meta \
  --input /tmp/source.parquet

Machine-readable JSON output:

$GREPTIME datanode parquet-meta \
  --input /tmp/source.parquet \
  --format json > /tmp/source-meta.json

--format accepts text (the default) or json. This command can inspect a general Parquet file; it does not require GreptimeDB SST key-value metadata.

Rewrite a Parquet file

parquet-rewrite has two modes. First, dump a TOML properties file inferred from an existing file:

$GREPTIME datanode parquet-rewrite \
  --input /tmp/source.parquet \
  --dump-properties /tmp/writer-properties.toml

Review and edit the generated file. Its shape is:

[writer]
dictionary_enabled = true
compression = "zstd"
max_row_group_row_count = 8192

[[columns]]
path = ["host"]
dictionary_enabled = true
compression = "zstd"
encoding = "plain"

Supported compression names are uncompressed, snappy, gzip, lzo, brotli, lz4, zstd, and lz4-raw. Supported encodings are plain, delta-binary-packed, delta-length-byte-array, delta-byte-array, and byte-stream-split.

The [writer] table also accepts compression_level, data_page_size_limit, data_page_row_count_limit, and dictionary_page_size_limit. It also accepts column_index_truncate_length and statistics_truncate_length; set either to zero to disable that truncation. A [[columns]] entry overrides dictionary, compression, compression level, or encoding for its column path. Unknown TOML fields are rejected. Compression levels are supported for gzip, brotli, and zstd. A column-level compression_level without compression inherits the writer compression codec; it is rejected when there is no writer codec to inherit.

Rewrite the data using the edited properties:

$GREPTIME datanode parquet-rewrite \
  --input /tmp/source.parquet \
  --properties /tmp/writer-properties.toml \
  --output /tmp/rewritten.parquet

Use --batch-size <ROWS> to control reader batch size. Output and dumped properties files are not replaced unless --overwrite is passed. The output or dump path must not be exactly the same path as the input, even with --overwrite. This check does not resolve symbolic links, hard links, or other spellings of the same path.

The rewrite decodes and writes the Arrow record batches into a new physical layout. It copies region metadata, recomputes decoded value sizes when present, and drops the greptimedb.deduped marker. Inspect the result before using it as an SST:

$GREPTIME datanode parquet-meta \
  --input /tmp/rewritten.parquet

The dumped properties are inferred primarily from the first row group. Review them when the source uses different properties across row groups.

Benchmark an SST

parquetbench expects GreptimeDB region metadata embedded in the SST. It can read a local file with the direct reader:

$GREPTIME datanode parquetbench \
  --file-path /tmp/rewritten.parquet \
  --reader direct \
  --iterations 5 \
  --batch-size 8192

Local-file mode cannot be combined with --config, --region-id, --table-dir, or --file-id, and it does not support the flat-prune reader.

To benchmark an SST in the object store configured for a datanode or standalone deployment:

$GREPTIME datanode parquetbench \
  --config /path/to/datanode.toml \
  --region-id 1024:0 \
  --table-dir data/greptime/public/1024 \
  --file-id 00020380-009c-426d-953e-b4e34c15af34 \
  --path-type bare \
  --reader flat-prune \
  --iterations 5

Region mode requires all four of --config, --region-id, --table-dir, and --file-id. --region-id accepts either the packed unsigned integer or <table-id>:<region-number>. --path-type accepts bare, data, or metadata and defaults to bare.

An optional scan configuration selects columns and row groups:

{
  "projection_names": ["host", "value", "ts"],
  "row_groups": [0, 2]
}
$GREPTIME datanode parquetbench \
  --file-path /tmp/rewritten.parquet \
  --scan-config /tmp/parquet-scan.json \
  --iterations 5

Use --pk-as-binary to expose __primary_key as binary with the direct reader. On Unix, --pprof-file <SVG> writes a flamegraph. Add --pprof-after-warmup and use at least two iterations to exclude the first iteration from profiling.

Replace an existing region SST

Stop the datanode that owns the region and back up its manifest before using --confirm. The command writes the replacement under a fresh file ID, then publishes one manifest edit that swaps the old ID for the new one. Readers of the previous manifest can still use the original object. If publication fails after the upload, check the active manifest before cleaning up the reported replacement path.

The target must be a locally owned, unshared Parquet SST. The replacement must belong to the same source region and time index and match the manifest row and row-group counts when those counts are known. Its footer must provide exact time bounds. Missing primary-key bounds remain unknown. Use parquet-rewrite first if the replacement carries greptimedb.deduped. Index sidecars belong to the original file ID. When the manifest has a sequence fence or preserves per-row sequences, the command compares the sequence column of both files before retaining those guarantees. Allow memory for both SSTs during validation.

Start with the default dry run using a local replacement file:

$GREPTIME datanode sst-replace \
  --config /path/to/datanode.toml \
  --region-id 1024:0 \
  --table-dir data/greptime/public/1024 \
  --file-id 00020380-009c-426d-953e-b4e34c15af34 \
  --replacement-file /tmp/rewritten.parquet

The dry run locates the manifest and target SST, reads and validates the replacement footer, and prints the old and new sizes without writing anything. --path-type defaults to auto, which probes bare, data, and metadata. Specify the path type if the file ID is visible in more than one manifest.

The replacement can instead be read from the configured object store:

$GREPTIME datanode sst-replace \
  --config /path/to/datanode.toml \
  --region-id 1024:0 \
  --table-dir data/greptime/public/1024 \
  --file-id 00020380-009c-426d-953e-b4e34c15af34 \
  --replacement-object staging/rewritten.parquet \
  --path-type bare

After reviewing the dry-run output and confirming that the datanode is stopped, repeat the exact command with --confirm:

$GREPTIME datanode sst-replace \
  --config /path/to/datanode.toml \
  --region-id 1024:0 \
  --table-dir data/greptime/public/1024 \
  --file-id 00020380-009c-426d-953e-b4e34c15af34 \
  --replacement-file /tmp/rewritten.parquet \
  --path-type bare \
  --confirm

The confirmed operation prints the new SST path and manifest version. Restart the datanode and validate queries against the region before removing the backup. To repair bounds or stale cache entries left by an older in-place replacement, use its current manifest ID as --file-id. If the current object has no deduplication marker, it can be passed directly as --replacement-object.

  1. Back up the source SST and its region manifest.
  2. Inspect the source with parquet-meta.
  3. Dump and edit writer properties with parquet-rewrite.
  4. Rewrite to a new local file; never rewrite directly over the source SST.
  5. Inspect the output and benchmark it with parquetbench.
  6. Stop the owning datanode.
  7. Run sst-replace without --confirm and review its resolved target and statistics.
  8. Repeat with --confirm, restart the datanode, and validate the region.