rodmeneses commented on code in PR #12071:
URL: https://github.com/apache/iceberg/pull/12071#discussion_r2098984273


##########
flink/v1.20/flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergSink.java:
##########
@@ -140,6 +140,13 @@ void testWriteRowWithTableSchema() throws Exception {
     testWriteRow(SimpleDataUtil.FLINK_SCHEMA, DistributionMode.NONE);
   }
 
+  @TestTemplate
+  void testWriteRowWithTableSchemaRANGE() throws Exception {
+    if (partitioned) {
+      testWriteRow(SimpleDataUtil.FLINK_SCHEMA, DistributionMode.RANGE);

Review Comment:
   not in this same unit test, as `env.execute` traverse the graph.
   I did implement it in another unit test. But it is hacky as there's no type 
safe way to get an instance of the underlying `Partitioner` that is wrapped 
around a `CustomPartitionerWrapper`. However, with reflection magic, it is 
possible.  I did see precedent of other unit tests leveraging Java Reflection. 
So, I think this is helpful, but please let me know your thoughts @pvary 
   ```java
     @TestTemplate
     void testRangePartitionedIsSet() throws Exception {
       if (partitioned) {
         List<Row> rows = createRows("");
         DataStream<Row> dataStream =
                 env.addSource(createBoundedSource(rows), 
ROW_TYPE_INFO).uid("mySourceId");
   
         IcebergSink.forRow(dataStream, SimpleDataUtil.FLINK_SCHEMA)
                 .table(table)
                 .tableLoader(tableLoader)
                 .tableSchema(SimpleDataUtil.FLINK_SCHEMA)
                 .writeParallelism(parallelism)
                 .distributionMode(DistributionMode.RANGE)
                 .append();
   
         boolean found = false;
         for (StreamNode node :  env.getStreamGraph().getStreamNodes()) {
           for (StreamEdge edge : node.getOutEdges()) {
             if (edge.getPartitioner() instanceof CustomPartitionerWrapper) {
               CustomPartitionerWrapper wrapper = (CustomPartitionerWrapper) 
edge.getPartitioner();
               try {
                 Field privatePartitionerField = 
CustomPartitionerWrapper.class.getDeclaredField("partitioner");
                 privatePartitionerField.setAccessible(true);
                 Object wrappedPartitionerObject = 
privatePartitionerField.get(wrapper);
                 if (wrappedPartitionerObject instanceof RangePartitioner) {
                   found = true;
                 }
               } catch (Exception e) {
                 throw new RuntimeException(e);
               }
             }
           }
         }
         assertThat(found)
                 .as("RangePartitioner was found")
                 .isTrue();
       }
     }
   ```
   
   
   



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