Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spark-3.5: make where sql case sensitive setting alterable in rewrite data files procedure #11439

Merged
merged 22 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ public void removeTable() {
sql("DROP TABLE IF EXISTS %s", tableName(QUOTED_SPECIAL_CHARS_TABLE_NAME));
}

@TestTemplate
public void testFilterCaseSensitivity() {
createTable();
insertData(10);
sql("set %s = false", SQLConf.CASE_SENSITIVE().key());
List<Object[]> expectedRecords = currentData();
List<Object[]> output =
sql(
"CALL %s.system.rewrite_data_files(table=>'%s', where=>'C1 > 0')",
ludlows marked this conversation as resolved.
Show resolved Hide resolved
catalogName, tableIdent);
assertEquals(
"Action should rewrite 10 data files and add 1 data files",
row(10, 1),
Arrays.copyOf(output.get(0), 2));
// verify rewritten bytes separately
assertThat(output.get(0)).hasSize(4);
assertThat(output.get(0)[2])
.isInstanceOf(Long.class)
.isEqualTo(Long.valueOf(snapshotSummary().get(SnapshotSummary.REMOVED_FILE_SIZE_PROP)));
List<Object[]> actualRecords = currentData();
assertEquals("Data after compaction should not change", expectedRecords, actualRecords);
}

@TestTemplate
public void testZOrderSortExpression() {
List<ExtendedParser.RawOrderField> order =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.iceberg.relocated.com.google.common.math.IntMath;
import org.apache.iceberg.relocated.com.google.common.util.concurrent.MoreExecutors;
import org.apache.iceberg.relocated.com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.iceberg.spark.SparkUtil;
import org.apache.iceberg.types.Types.StructType;
import org.apache.iceberg.util.PropertyUtil;
import org.apache.iceberg.util.StructLikeMap;
Expand Down Expand Up @@ -102,11 +103,13 @@ public class RewriteDataFilesSparkAction
private boolean useStartingSequenceNumber;
private RewriteJobOrder rewriteJobOrder;
private FileRewriter<FileScanTask, DataFile> rewriter = null;
private boolean caseSensitive;

RewriteDataFilesSparkAction(SparkSession spark, Table table) {
super(spark.cloneSession());
// Disable Adaptive Query Execution as this may change the output partitioning of our write
spark().conf().set(SQLConf.ADAPTIVE_EXECUTION_ENABLED().key(), false);
this.caseSensitive = SparkUtil.caseSensitive(spark);
this.table = table;
}

Expand Down Expand Up @@ -153,6 +156,11 @@ public RewriteDataFilesSparkAction filter(Expression expression) {
return this;
}

public RewriteDataFilesSparkAction setCaseSensitive(boolean caseSensitiveReset) {
ludlows marked this conversation as resolved.
Show resolved Hide resolved
this.caseSensitive = caseSensitiveReset;
return this;
}

@Override
public RewriteDataFiles.Result execute() {
if (table.currentSnapshot() == null) {
Expand Down Expand Up @@ -198,6 +206,7 @@ StructLikeMap<List<List<FileScanTask>>> planFileGroups(long startingSnapshotId)
table
.newScan()
.useSnapshot(startingSnapshotId)
.caseSensitive(caseSensitive)
.filter(filter)
.ignoreResiduals()
.planFiles();
Expand Down