Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about spark/v4.0 and spark/v3.5? Shall we fix there too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,13 @@ private Column sortColumn() {
partitionFieldClustering);

// Map the top level partition column names to the column name referenced within the manifest
// entry dataframe
// entry dataframe. Backtick-quote the partition field name because it may itself contain a
// literal '.' (e.g. when partitioning on a nested source column) - the partition struct is
// always flat, so unquoted, col() would misparse that dot as a further level of nesting
// instead of treating the whole name as one field.
Column[] partitionColumns =
partitionFieldClustering.stream()
.map(p -> col(DATA_FILE_PARTITION_COLUMN_NAME + "." + p))
.map(p -> col(DATA_FILE_PARTITION_COLUMN_NAME + ".`" + p + "`"))

@uros-b uros-b Jul 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backtick quoting is written as

". + p + ""

without escaping an embedded backtick in p.

A partition field name containing a backtick, e.g.

"a`b"

produces a malformed col() expression and an AnalysisException at runtime.

The correct idiom would be

p.replace("", "``")

e.g. used by SparkSchemaUtil.indexQuotedNameById.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, PTAL @uros-b thanks!

.toArray(Column[]::new);

// Form a new temporary column to cluster manifests on, based on the custom clustering columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,45 @@ public void testRewriteManifestsPartitionedTableWithCustomSorting() throws IOExc
assertThat(manifestsDf.count()).as("There should be at least 2 manifests").isGreaterThan(1L);
}

@TestTemplate
public void testRewriteManifestsPartitionedTableWithCustomSortingOnFieldNameContainingDot()
throws IOException {
// Regression test: partitioning on a nested source column (struct "a" with child field "b")
// used to make sortBy() fail at execution time, since the resulting partition field is named
// "a.b" but the partition struct is flat - col() misparsed the dot as a further nesting level
// instead of treating "a.b" as a single field name.
Schema schema =
new Schema(
optional(1, "a", Types.StructType.of(optional(2, "b", Types.StringType.get()))),
optional(3, "ds", Types.StringType.get()));
PartitionSpec spec = PartitionSpec.builderFor(schema).identity("a.b").build();
Map<String, String> options = Maps.newHashMap();
options.put(TableProperties.FORMAT_VERSION, String.valueOf(formatVersion));
options.put(TableProperties.SNAPSHOT_ID_INHERITANCE_ENABLED, snapshotIdInheritanceEnabled);
Table table = TABLES.create(schema, spec, options, tableLocation);

// write two manifests so the rewrite doesn't short-circuit via the "already optimal" early
// return, and sortColumn() actually gets exercised
ManifestFile manifest1 =
writeManifest(table, ImmutableList.of(newDataFile(table, TestHelpers.Row.of("val1"))));
table.newFastAppend().appendManifest(manifest1).commit();

ManifestFile manifest2 =
writeManifest(table, ImmutableList.of(newDataFile(table, TestHelpers.Row.of("val2"))));
table.newFastAppend().appendManifest(manifest2).commit();

RewriteManifests.Result result =
SparkActions.get()
.rewriteManifests(table)
.rewriteIf(manifest -> true)
.sortBy(ImmutableList.of("a.b"))
.option(RewriteManifestsSparkAction.USE_CACHING, useCaching)
.execute();

assertThat(result.rewrittenManifests()).hasSize(2);
assertThat(result.addedManifests()).hasSizeGreaterThanOrEqualTo(1);
}

@TestTemplate
public void testRewriteManifestsWithPredicate() throws IOException {
PartitionSpec spec = PartitionSpec.builderFor(SCHEMA).identity("c1").truncate("c2", 2).build();
Expand Down
Loading