pvary commented on code in PR #15843:
URL: https://github.com/apache/iceberg/pull/15843#discussion_r3129978833


##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -700,4 +1041,165 @@ private static String splitSizeProperty(FileFormat 
fileFormat) {
               "No split size property defined for format: " + fileFormat);
     };
   }
+
+  private void writeRecordsWithoutFieldIds(
+      FileFormat fileFormat, Schema schema, List<Record> records) throws 
IOException {
+    switch (fileFormat) {
+      case PARQUET -> writeParquetWithoutFieldIds(schema, records);
+      case AVRO -> writeAvroWithoutFieldIds(schema, records);
+      case ORC -> writeOrcWithoutFieldIds(schema, records);
+      default -> throw new UnsupportedOperationException("Unsupported file 
format: " + fileFormat);
+    }
+  }
+
+  private void writeAvroWithoutFieldIds(Schema schema, List<Record> records) 
throws IOException {
+    org.apache.avro.Schema avroSchemaWithoutIds = 
AvroTestHelpers.removeIds(schema);
+
+    OutputFile outputFile = encryptedFile.encryptingOutputFile();
+    DatumWriter<GenericData.Record> datumWriter = new 
GenericDatumWriter<>(avroSchemaWithoutIds);
+    try (OutputStream out = outputFile.create();
+        DataFileWriter<GenericData.Record> writer = new 
DataFileWriter<>(datumWriter)) {
+      writer.create(avroSchemaWithoutIds, out);
+      for (Record record : records) {
+        GenericData.Record avroRecord = new 
GenericData.Record(avroSchemaWithoutIds);
+        for (Types.NestedField field : schema.columns()) {
+          avroRecord.put(field.name(), record.getField(field.name()));
+        }
+
+        writer.append(avroRecord);
+      }
+    }
+
+    try (DataFileStream<GenericData.Record> reader =
+        new DataFileStream<>(outputFile.toInputFile().newStream(), new 
GenericDatumReader<>())) {
+      assertThat(AvroTestHelpers.hasIds(reader.getSchema())).isFalse();
+    }
+  }
+
+  private void writeParquetWithoutFieldIds(Schema schema, List<Record> 
records) throws IOException {
+    org.apache.avro.Schema avroSchemaWithoutIds = 
AvroTestHelpers.removeIds(schema);
+
+    Path tempFile = Files.createTempFile("iceberg-test-no-ids-", ".parquet");
+    Files.deleteIfExists(tempFile);
+
+    try {
+      try (ParquetWriter<GenericData.Record> writer =
+          AvroParquetWriter.<GenericData.Record>builder(
+                  new org.apache.hadoop.fs.Path(tempFile.toUri()))
+              .withDataModel(GenericData.get())
+              .withSchema(avroSchemaWithoutIds)
+              .withConf(new Configuration())
+              .build()) {
+        for (Record record : records) {
+          GenericData.Record avroRecord = new 
GenericData.Record(avroSchemaWithoutIds);
+          for (Types.NestedField field : schema.columns()) {
+            avroRecord.put(field.name(), record.getField(field.name()));
+          }
+
+          writer.write(avroRecord);
+        }
+      }
+
+      try (ParquetFileReader reader =
+          ParquetFileReader.open(
+              HadoopInputFile.fromPath(
+                  new org.apache.hadoop.fs.Path(tempFile.toUri()), new 
Configuration()))) {
+        
assertThat(ParquetSchemaUtil.hasIds(reader.getFooter().getFileMetaData().getSchema()))
+            .isFalse();
+      }
+
+      byte[] bytes = Files.readAllBytes(tempFile);
+      try (OutputStream out = encryptedFile.encryptingOutputFile().create()) {
+        out.write(bytes);
+      }
+    } finally {
+      Files.deleteIfExists(tempFile);
+    }
+  }
+
+  private void writeOrcWithoutFieldIds(Schema schema, List<Record> records) 
throws IOException {
+    TypeDescription typeWithIds = ORCSchemaUtil.convert(schema);
+    TypeDescription typeWithoutIds = TestORCSchemaUtil.removeIds(typeWithIds);
+
+    Configuration conf = new Configuration();
+    OrcFile.WriterOptions options =
+        
OrcFile.writerOptions(conf).useUTCTimestamp(true).setSchema(typeWithoutIds);
+
+    OrcRowWriter<Record> rowWriter = GenericOrcWriter.buildWriter(schema, 
typeWithIds);
+
+    Path tempFile = Files.createTempFile("iceberg-test-no-ids-", ".orc");
+    Files.deleteIfExists(tempFile);

Review Comment:
   Same question as above



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