rdblue commented on code in PR #16100:
URL: https://github.com/apache/iceberg/pull/16100#discussion_r3244557708


##########
core/src/test/java/org/apache/iceberg/TestTrackedFileAdapters.java:
##########
@@ -0,0 +1,424 @@
+/*
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.types.Conversions;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+class TestTrackedFileAdapters {
+
+  private static final String MANIFEST_LOCATION = 
"s3://bucket/table/manifest.parquet";
+
+  private static final Map<Integer, PartitionSpec> UNPARTITIONED =
+      ImmutableMap.of(0, PartitionSpec.unpartitioned());
+
+  private static Map<Integer, PartitionSpec> specsById(PartitionSpec spec) {
+    return ImmutableMap.of(spec.specId(), spec);
+  }
+
+  @Test
+  void testDataFileAdapterDelegatesAllFields() {
+    TrackingStruct tracking = createTracking(3L);
+    ContentStats stats = createContentStats();
+
+    TrackedFileStruct file =
+        new TrackedFileStruct(
+            tracking,
+            FileContent.DATA,
+            "s3://bucket/data/file.parquet",
+            FileFormat.PARQUET,
+            null,
+            100L,
+            1024L);
+    file.set(6, 0);
+    file.set(8, stats);
+    file.set(9, 3);
+    file.set(12, ByteBuffer.wrap(new byte[] {1, 2, 3}));
+    file.set(13, ImmutableList.of(50L, 100L));
+
+    DataFile dataFile = TrackedFileAdapters.asDataFile(file, UNPARTITIONED);
+
+    assertThat(dataFile.pos()).isEqualTo(3L);
+    assertThat(dataFile.specId()).isEqualTo(0);
+    assertThat(dataFile.content()).isEqualTo(FileContent.DATA);
+    assertThat(dataFile.location()).isEqualTo("s3://bucket/data/file.parquet");
+    assertThat(dataFile.format()).isEqualTo(FileFormat.PARQUET);
+    assertThat(dataFile.recordCount()).isEqualTo(100L);
+    assertThat(dataFile.fileSizeInBytes()).isEqualTo(1024L);
+    assertThat(dataFile.sortOrderId()).isEqualTo(3);
+    assertThat(dataFile.dataSequenceNumber()).isEqualTo(10L);
+    assertThat(dataFile.fileSequenceNumber()).isEqualTo(11L);
+    assertThat(dataFile.firstRowId()).isEqualTo(1000L);
+    assertThat(dataFile.keyMetadata()).isEqualTo(ByteBuffer.wrap(new byte[] 
{1, 2, 3}));
+    assertThat(dataFile.splitOffsets()).containsExactly(50L, 100L);
+    assertThat(dataFile.manifestLocation()).isEqualTo(MANIFEST_LOCATION);
+    assertThat(dataFile.equalityFieldIds()).isNull();
+    assertThat(dataFile.columnSizes()).isNull();
+    assertThat(dataFile.valueCounts()).containsOnly(entry(1, 100L), entry(2, 
200L));
+    assertThat(dataFile.nullValueCounts()).containsOnly(entry(1, 5L), entry(2, 
10L));
+    assertThat(dataFile.nanValueCounts()).containsOnly(entry(2, 3L));
+    assertThat(dataFile.lowerBounds())
+        .containsEntry(1, Conversions.toByteBuffer(Types.IntegerType.get(), 1))
+        .containsEntry(2, Conversions.toByteBuffer(Types.FloatType.get(), 
1.0f));
+    assertThat(dataFile.upperBounds())
+        .containsEntry(1, Conversions.toByteBuffer(Types.IntegerType.get(), 
1000))
+        .containsEntry(2, Conversions.toByteBuffer(Types.FloatType.get(), 
100.0f));
+  }
+
+  @Test
+  void testDataFileAdapterRejectsNonData() {
+    TrackedFileStruct file =
+        new TrackedFileStruct(
+            null,
+            FileContent.EQUALITY_DELETES,
+            "s3://bucket/delete.avro",
+            FileFormat.AVRO,
+            null,
+            50L,
+            512L);
+    file.set(6, 0);
+
+    assertThatThrownBy(() -> TrackedFileAdapters.asDataFile(file, 
UNPARTITIONED))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid content type for DataFile: %s", 
FileContent.EQUALITY_DELETES);
+  }
+
+  @Test
+  void testEqualityDeleteFileAdapterDelegatesAllFields() {
+    TrackingStruct tracking = createTracking(5L);
+    PartitionSpec spec = PartitionSpec.builderFor(new 
Schema()).withSpecId(1).build();

Review Comment:
   This unpartitioned spec and its ID can be constants to help with readability.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to