amogh-jahagirdar commented on code in PR #12736:
URL: https://github.com/apache/iceberg/pull/12736#discussion_r2059375632


##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestRowLevelOperationsWithLineage.java:
##########
@@ -0,0 +1,436 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.extensions;
+
+import static org.apache.iceberg.TableUtil.schemaWithRowLineage;
+import static org.apache.iceberg.spark.Spark3Util.loadIcebergTable;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Function;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.MetadataColumns;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotRef;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TestHelpers;
+import org.apache.iceberg.data.GenericAppenderFactory;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.encryption.EncryptionUtil;
+import org.apache.iceberg.io.DataWriter;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.spark.functions.BucketFunction;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.Pair;
+import org.apache.iceberg.util.PartitionMap;
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
+import org.apache.spark.sql.catalyst.parser.ParseException;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+
+public abstract class TestRowLevelOperationsWithLineage extends 
SparkRowLevelOperationsTestBase {
+  static final Function<StructLike, StructLike> UNPARTITIONED_GENERATOR = 
record -> null;
+  static final Function<StructLike, StructLike> BUCKET_PARTITION_GENERATOR =
+      record ->
+          TestHelpers.Row.of(BucketFunction.BucketInt.invoke(2, record.get(0, 
Integer.class)));
+  static final Schema SCHEMA =
+      new Schema(
+          ImmutableList.of(
+              Types.NestedField.required(1, "data", Types.IntegerType.get()),
+              MetadataColumns.ROW_ID,
+              MetadataColumns.LAST_UPDATED_SEQUENCE_NUMBER));
+
+  static final List<Record> INITIAL_RECORDS =
+      ImmutableList.of(
+          createRecord(0, 0L, 1L),
+          createRecord(1, 1L, 1L),
+          createRecord(2, 2L, 1L),
+          createRecord(3, 3L, 1L),
+          createRecord(4, 4L, 1L));
+
+  @BeforeAll
+  public static void setupSparkConf() {
+    spark.conf().set("spark.sql.shuffle.partitions", "4");
+  }
+
+  @BeforeEach
+  public void beforeEach() {
+    assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+    // ToDo: Remove these as row lineage inheritance gets implemented in the 
other readers
+    assumeThat(fileFormat).isEqualTo(FileFormat.PARQUET);
+    assumeThat(vectorized).isFalse();

Review Comment:
   I've changed this test class to assert against the row IDs/last udpated 
sequence via SQL, which will go through inheritance (as opposed to reading from 
files). I went back and forth on this, and concluded that testing with 
inheritance ends up actually being simpler.
   
   The original goal of testing without inheritance was to have independent 
tests that just verify our Spark changes are preserving or nulling out when 
appropriate, but building and reading via the low level reader has its own 
complications imo for someone wanting to verify this test does what it should.
   
   For example, with reading the files directly, we have to specify the 
idToConstant mapping to have the baseRowId/seq number otherwise the reader will 
return nulls for those. After specifying the mapping, the seq number passed in 
will override instead of returning nulls. We could work around this when 
building our list of expected rows for specific records, but then someone 
reading the test has to gauge that and additionally verify that logic is 
correct, and that we're not getting lucky somehow.
   
   Reading the raw data file records is made more complicated by the fact that 
expectations need to filter out deleted or updated rows and treat those 
separately.
   
    So with all that said, it ended up being simpler to just assert the row 
ID/seq number including inheritance. Since it's no guarantee what row Ids new 
rows would be assigned we just need to assert that the new row has a higher row 
ID than the prev max. I think that's OK because at this abstraction the actual 
row ID assigned for new rows is inconsequential so long as we're not somehow 
writing a duplicate (which the assertion mentioned before would catch).
   
   The implication of this is this test class cannot run for Spark readers 
where inheritance is not implemented. I also think that's OK because as we add 
the implementations we'd tighten up these assumptions.
   
   cc @rdblue 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to