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


##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -700,4 +1089,164 @@ 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 = RemoveIds.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(AvroSchemaUtil.hasIds(reader.getSchema())).isFalse();
+    }
+  }
+
+  private void writeParquetWithoutFieldIds(Schema schema, List<Record> 
records) throws IOException {
+    org.apache.avro.Schema avroSchemaWithoutIds = RemoveIds.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 org.apache.hadoop.conf.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 org.apache.hadoop.conf.Configuration()))) {

Review Comment:
   Path need, but Configuration don't, remove it. 



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