Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions docs/docs/multimodal-table/data-evolution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,106 @@ Persisted row-ID references must be coordinated with this maintenance.
See [Data Evolution Maintenance](./data-evolution-maintenance) for commands,
large-file splitting, limitations, and the row-ID lifetime table.

## Spark File Metadata Memory

Tables with many files can require substantial heap for the metadata returned
by scans and write tasks, and processed during commit. Select a metadata mode
manually for Spark Data Evolution operations:

```sql
ALTER TABLE target_table SET TBLPROPERTIES (
'data-evolution.metadata-memory-optimization.mode' = 'lightweight'
);
```

The mode defaults to `off` and takes effect only for Data Evolution tables:

| Mode | Behavior |
| --- | --- |
| `off` | Uses the ordinary metadata path. |
| `lightweight` | Reduces unnecessary metadata copies, decoded objects and their lifetime. |
| `streaming` | Also plans complete row-ID dependency groups incrementally and replays file metadata from Driver-local disk. |

For scans that request discarded statistics, `lightweight` mode releases value
statistics before collecting file metadata when no pushed data predicate needs
them. Filtered scans retain statistics until row-ID groups have been evaluated.
In `streaming` mode, statistics remain in the external sort and dependency-group
filtering input. Unneeded statistics are discarded before selected file metadata
is encoded into replay files.
Explicitly retained statistics, including supported statistics-based Top-N
planning, follow the original retention policy.
Scans also share repeated column-name strings from the current schema while
keeping each file's column list independent. Historical names absent from the
current schema retain their original representation.

For writes, it keeps commit messages encoded until needed, avoids some eager
copies of expanded file metadata, and completes MERGE preparation and requests
cache cleanup before entering commit.

In `streaming` mode, metadata is filtered in complete Data Evolution dependency
groups before splits are produced. Completed file lists are encoded into two
local replay files per store. MERGE preparation keeps numeric row-ID summaries
and re-encodes pruned lists, preserving file order and aligned deletion vectors.
Partial-write Tasks consume contiguous row-ID ranges as Spark requests results.
Each completed range produces its original commit-message payload directly,
without retaining all decoded messages or writing a Task-local message replay file.
The original Snapshot, authorization, filtering and read-protection rules still
apply. This path supports batch ALL planning with one physical snapshot reader.
Spark fallback/chain, audit-log and incremental reads, including `latest-delta`,
keep their existing planner and its metadata memory boundaries. Internal batch
scan modes also keep the existing planner.

For LIMIT reads without data predicates, RowID filters or deletion vectors,
replay keeps only the required complete dependency groups. Candidate metadata
is still scanned and externally sorted before selecting that prefix; the
largest-group and sorting memory boundaries still apply.

Streaming scan planning requires at least three sort-buffer pages. Smaller
buffers remain valid and use ordinary scan planning with its original metadata
memory boundary.

Streaming commit conflict checking requires at least six sort-buffer pages for
its two sorters. Smaller buffers remain valid and use ordinary conflict checking,
which retains its original metadata memory boundary instead of increasing the
configured buffer budget.

Tasks receive the normal serialized metadata, so Executors do not need access
to the Driver's replay-file paths. MERGE closes its preparation stores after
its internal jobs finish. Ordinary query plans keep replay files available
while their splits remain reachable; backup cleanup has no timing guarantee.
Partial-write resources are closed when their output is consumed or the Task
completes, including failed Tasks. Input processing can overlap Spark's growing
Task-result buffer; that buffer and the complete encoded results collected by
the Driver remain memory boundaries.

`data-evolution.metadata-memory-optimization.max-disk-size` limits encoded
data and offset-index bytes per replay store, defaulting to `1 gb`. It does not
include external-sort spill, filesystem allocation overhead or other stores.
Multiple planning stores can coexist. Repeated decoding, sorting and disk I/O add
work; compare complete SQL time and resource use on a representative workload.

These modes do not make the entire Spark execution constant-memory. Complete
dependency groups, final task arrays, row-ID summaries, deletion/conflict state,
all returned message bytes and the largest individual message still require
heap. Multi-partition commit grouping
may materialize file metadata. Commit extensions that need stable, mutable
messages retain the materialized compatibility path.

Streaming conflict checks retain compact row-ID summaries and use external
sorting for file identity reconciliation. These summaries still grow with the
number of files. Potential conflicts are replayed through the original checker
to preserve diagnostics, retaining its original memory limit. Compatibility
paths, including commits with deletion vectors or callbacks, also retain the
original conflict checker.

To use streaming mode, set the mode to `streaming`. To disable metadata optimization:

```sql
ALTER TABLE target_table SET TBLPROPERTIES (
'data-evolution.metadata-memory-optimization.mode' = 'off'
);
```

## File Sizing and Metadata Compatibility

<span id="compact-write-column-metadata" />
Expand Down
24 changes: 18 additions & 6 deletions docs/generated/core_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,6 @@
<td>MemorySize</td>
<td>When incremental size is bigger than this threshold, force a full compaction.</td>
</tr>
<tr>
<td><h5>continuous-compaction.initial-scan-mode</h5></td>
<td style="word-wrap: break-word;">earliest</td>
<td><p>Enum</p></td>
<td>Initial snapshot mode for dedicated streaming compaction. When set to 'earliest' (the default), compaction starts from the earliest available snapshot if no COMPACT snapshot exists; when a COMPACT snapshot exists, compaction always resumes from the snapshot after it. When set to 'latest', the latest snapshot is read in ALL mode as the initial baseline and subsequent scans start from the next snapshot. The 'latest' mode skips historical snapshot changes and should only be used when historical changelog replay is not required.<br /><br />Possible values:<ul><li>"earliest": Read snapshots from the earliest available snapshot.</li><li>"latest": Read the latest snapshot as the initial full baseline.</li></ul></td>
</tr>
<tr>
<td><h5>compaction.max-size-amplification-percent</h5></td>
<td style="word-wrap: break-word;">200</td>
Expand Down Expand Up @@ -506,6 +500,12 @@
<td><p>Enum</p></td>
<td>Specify the consumer consistency mode for table.<br /><br />Possible values:<ul><li>"exactly-once": Readers consume data at snapshot granularity, and strictly ensure that the snapshot-id recorded in the consumer is the snapshot-id + 1 that all readers have exactly consumed.</li><li>"at-least-once": Each reader consumes snapshots at a different rate, and the snapshot with the slowest consumption progress among all readers will be recorded in the consumer.</li></ul></td>
</tr>
<tr>
<td><h5>continuous-compaction.initial-scan-mode</h5></td>
<td style="word-wrap: break-word;">earliest</td>
<td><p>Enum</p></td>
<td>Initial snapshot mode for dedicated streaming compaction. When set to 'earliest' (the default), compaction starts from the earliest available snapshot if no COMPACT snapshot exists; when a COMPACT snapshot exists, compaction always resumes from the snapshot after it. When set to 'latest', the latest snapshot is read in ALL mode as the initial baseline and subsequent scans start from the next snapshot. The 'latest' mode skips historical snapshot changes and should only be used when historical changelog replay is not required.<br /><br />Possible values:<ul><li>"earliest": Read snapshots from the earliest available snapshot.</li><li>"latest": Read the latest snapshot as the initial full baseline.</li></ul></td>
</tr>
<tr>
<td><h5>continuous.discovery-interval</h5></td>
<td style="word-wrap: break-word;">10 s</td>
Expand Down Expand Up @@ -590,6 +590,18 @@
<td>Boolean</td>
<td>Whether to push filters down into a row-id range whose columns are merged from several data files. The rows which may match are computed from the file statistics and page indexes of the files holding the latest values of the filtered columns, then every file of the range reads only these rows. Only Parquet files are supported.</td>
</tr>
<tr>
<td><h5>data-evolution.metadata-memory-optimization.max-disk-size</h5></td>
<td style="word-wrap: break-word;">1 gb</td>
<td>MemorySize</td>
<td>Maximum encoded data and offset-index bytes per metadata replay store in streaming mode. Excludes external-sort spill files, filesystem allocation overhead and other concurrent plans.</td>
</tr>
<tr>
<td><h5>data-evolution.metadata-memory-optimization.mode</h5></td>
<td style="word-wrap: break-word;">off</td>
<td><p>Enum</p></td>
<td>Metadata memory mode for Spark data evolution operations: off, lightweight or streaming. Enable manually for tables with many files. Repeated decoding, sorting and disk I/O may increase execution time.<br /><br />Possible values:<ul><li>"off": Use the ordinary metadata path.</li><li>"lightweight": Reduce metadata copies and retained decoded objects.</li><li>"streaming": Incrementally produce and replay file metadata.</li></ul></td>
</tr>
<tr>
<td><h5>data-evolution.nested-field.enabled</h5></td>
<td style="word-wrap: break-word;">false</td>
Expand Down
70 changes: 70 additions & 0 deletions paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,26 @@ public String toString() {
.defaultValue(false)
.withDescription("Whether enable data evolution for row tracking table.");

public static final ConfigOption<DataEvolutionMetadataMemoryMode>
DATA_EVOLUTION_METADATA_MEMORY_OPTIMIZATION_MODE =
key("data-evolution.metadata-memory-optimization.mode")
.enumType(DataEvolutionMetadataMemoryMode.class)
.defaultValue(DataEvolutionMetadataMemoryMode.OFF)
.withDescription(
"Metadata memory mode for Spark data evolution operations: off, "
+ "lightweight or streaming. Enable manually for tables "
+ "with many files. Repeated decoding, sorting and disk I/O "
+ "may increase execution time.");

public static final ConfigOption<MemorySize> DATA_EVOLUTION_METADATA_MEMORY_MAX_DISK_SIZE =
key("data-evolution.metadata-memory-optimization.max-disk-size")
.memoryType()
.defaultValue(MemorySize.ofMebiBytes(1024))
.withDescription(
"Maximum encoded data and offset-index bytes per metadata replay store "
+ "in streaming mode. Excludes external-sort spill files, "
+ "filesystem allocation overhead and other concurrent plans.");

public static final ConfigOption<Boolean> DATA_EVOLUTION_WRITE_COLS_OPTIMIZATION_ENABLED =
key("data-evolution.write-cols-optimization.enabled")
.booleanType()
Expand Down Expand Up @@ -4800,6 +4820,31 @@ public boolean dataEvolutionEnabled() {
return options.get(DATA_EVOLUTION_ENABLED);
}

public boolean dataEvolutionMetadataMemoryOptimizationEnabled() {
return dataEvolutionMetadataMemoryMode() != DataEvolutionMetadataMemoryMode.OFF;
}

public DataEvolutionMetadataMemoryMode dataEvolutionMetadataMemoryMode() {
if (!dataEvolutionEnabled()) {
return DataEvolutionMetadataMemoryMode.OFF;
}
return options.get(DATA_EVOLUTION_METADATA_MEMORY_OPTIMIZATION_MODE);
}

public boolean dataEvolutionMetadataStreamingEnabled() {
return dataEvolutionMetadataMemoryMode() == DataEvolutionMetadataMemoryMode.STREAMING;
}

public long dataEvolutionMetadataMaxDiskSize() {
long bytes = options.get(DATA_EVOLUTION_METADATA_MEMORY_MAX_DISK_SIZE).getBytes();
checkArgument(
bytes >= Long.BYTES,
"%s must be at least %s bytes.",
DATA_EVOLUTION_METADATA_MEMORY_MAX_DISK_SIZE.key(),
Long.BYTES);
return bytes;
}

public boolean dataEvolutionWriteColsOptimizationEnabled() {
return options.get(DATA_EVOLUTION_WRITE_COLS_OPTIMIZATION_ENABLED);
}
Expand Down Expand Up @@ -5631,6 +5676,31 @@ public InlineElement getDescription() {
}
}

/** Manually selected metadata retention strategy for Spark data evolution operations. */
public enum DataEvolutionMetadataMemoryMode implements DescribedEnum {
OFF("off", "Use the ordinary metadata path."),
LIGHTWEIGHT("lightweight", "Reduce metadata copies and retained decoded objects."),
STREAMING("streaming", "Incrementally produce and replay file metadata.");

private final String value;
private final String description;

DataEvolutionMetadataMemoryMode(String value, String description) {
this.value = value;
this.description = description;
}

@Override
public String toString() {
return value;
}

@Override
public InlineElement getDescription() {
return text(description);
}
}

/** Inner stream scan mode for some internal requirements. */
public enum StreamScanMode implements DescribedEnum {
NONE("none", "No requirement."),
Expand Down
26 changes: 26 additions & 0 deletions paimon-core/src/main/java/org/apache/paimon/io/DataFileMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,32 @@ default Range nonNullRowIdRange() {

DataFileMeta assignFileSource(FileSource fileSource);

/** Returns a standard metadata value copy with only the physical column names replaced. */
default DataFileMeta withWriteCols(@Nullable List<String> writeCols) {
return create(
fileName(),
fileSize(),
rowCount(),
minKey(),
maxKey(),
keyStats(),
valueStats(),
minSequenceNumber(),
maxSequenceNumber(),
schemaId(),
level(),
extraFiles(),
creationTime(),
deleteRowCount().orElse(null),
embeddedIndex(),
fileSource().orElse(null),
valueStatsCols(),
externalPath().orElse(null),
firstRowId(),
writeCols,
writeColsSequences());
}

DataFileMeta withWriteColsSequences(long[] writeColsSequences);

DataFileMeta assignFirstRowId(long firstRowId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,32 @@ public PojoDataFileMeta assignSequenceNumber(long minSequenceNumber, long maxSeq
writeColsSequences);
}

@Override
public PojoDataFileMeta withWriteCols(@Nullable List<String> writeCols) {
return new PojoDataFileMeta(
fileName,
fileSize,
rowCount,
minKey,
maxKey,
keyStats,
valueStats,
minSequenceNumber,
maxSequenceNumber,
schemaId,
level,
extraFiles,
creationTime,
deleteRowCount,
embeddedIndex,
fileSource,
valueStatsCols,
externalPath,
firstRowId,
writeCols,
writeColsSequences);
}

@Override
public PojoDataFileMeta withWriteColsSequences(long[] writeColsSequences) {
return new PojoDataFileMeta(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ public DataFileMeta assignFileSource(FileSource fileSource) {
throw unsupportedOperation("assignFileSource(FileSource)");
}

@Override
public DataFileMeta withWriteCols(@Nullable List<String> writeCols) {
throw unsupportedOperation("withWriteCols(List)");
}

@Override
public DataFileMeta withWriteColsSequences(long[] writeColsSequences) {
throw unsupportedOperation("withWriteColsSequences(long[])");
Expand Down
Loading
Loading