fqaiser94 commented on code in PR #9641:
URL: https://github.com/apache/iceberg/pull/9641#discussion_r1503273341


##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordProjection.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.connect.data;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.types.Types.ListType;
+import org.apache.iceberg.types.Types.MapType;
+import org.apache.iceberg.types.Types.NestedField;
+import org.apache.iceberg.types.Types.StructType;
+
+/**
+ * This is modified from {@link org.apache.iceberg.util.StructProjection} to 
support record types.
+ */
+public class RecordProjection implements Record {

Review Comment:
   nit: would it be worth it to write some unit tests for this class?
   
   If so, feel free to use the following as a starting point (wrote a couple 
quickly while I was trying to understand things). 
   
   ```java
   package org.apache.iceberg.connect.data;
   
   import org.apache.iceberg.data.GenericRecord;
   import org.apache.iceberg.types.Types;
   import org.junit.jupiter.api.Test;
   
   import static org.assertj.core.api.Assertions.assertThat;
   import static org.assertj.core.api.Assertions.assertThatThrownBy;
   
   import org.apache.iceberg.data.Record;
   
   class RecordProjectionTest {
   
       @Test
       void testShouldReturnOnlyValuesInProjectionSchema() {
           final org.apache.iceberg.Schema SIMPLE_SCHEMA =
                   new org.apache.iceberg.Schema(
                           Types.NestedField.required(1, "a", 
Types.IntegerType.get()),
                           Types.NestedField.required(2, "b", 
Types.StringType.get()));
   
           final org.apache.iceberg.Schema PROJECTION_SCHEMA =
                   new org.apache.iceberg.Schema(
                           Types.NestedField.required(1, "a", 
Types.IntegerType.get()));
   
           final RecordProjection projection = 
RecordProjection.create(SIMPLE_SCHEMA, PROJECTION_SCHEMA);
           final Record record = GenericRecord.create(SIMPLE_SCHEMA);
           record.setField("a", 234L);
           record.setField("b", "foobar");
           final Record projectedRecord = projection.wrap(record);
   
           assertThat(projectedRecord.get(0)).isEqualTo(234L);
           assertThatThrownBy(() -> projectedRecord.get(1))
                   .isInstanceOf(ArrayIndexOutOfBoundsException.class)
                   .hasMessageContaining("Index 1 out of bounds for length 1");
       }
   
       @Test
       void testShouldReturnOnlyValuesInNestedProjectionSchema() {
           final Types.StructType A_STRUCT = Types.StructType.of(
                   Types.NestedField.required(2, "b", Types.IntegerType.get()),
                   Types.NestedField.required(3, "c", Types.StringType.get())
           );
   
           final org.apache.iceberg.Schema NESTED_SCHEMA =
                   new org.apache.iceberg.Schema(
                           Types.NestedField.required(1, "a", A_STRUCT)
                   );
   
           final org.apache.iceberg.Schema NESTED_PROJECTION_SCHEMA =
                   new org.apache.iceberg.Schema(
                           Types.NestedField.required(1, "a", 
Types.StructType.of(
                                   Types.NestedField.required(2, "b", 
Types.IntegerType.get())
                           ))
                   );
   
           final RecordProjection projection = 
RecordProjection.create(NESTED_SCHEMA, NESTED_PROJECTION_SCHEMA);
   
           final Record aRecord = GenericRecord.create(A_STRUCT);
           aRecord.setField("b", 234L);
           aRecord.setField("c", "foobar");
   
           final Record record = GenericRecord.create(NESTED_SCHEMA);
           record.setField("a", aRecord);
   
           final Record projectedRecord = projection.wrap(record);
           final Record aProjectedRecord = (Record) projectedRecord.get(0);
   
           assertThat(aProjectedRecord.get(0)).isEqualTo(234L);
           assertThatThrownBy(() -> aProjectedRecord.get(1))
                   .isInstanceOf(ArrayIndexOutOfBoundsException.class)
                   .hasMessageContaining("Index 1 out of bounds for length 1");
       }
   }
   ```



-- 
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