sshkvar commented on a change in pull request #2757:
URL: https://github.com/apache/iceberg/pull/2757#discussion_r670224086



##########
File path: spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java
##########
@@ -185,4 +190,51 @@ public void testMixedTypes() throws IOException {
 
     writeAndValidate(schema);
   }
+
+  @Test
+  public void testTimestampWithoutZone() throws IOException {
+    withSQLConf(ImmutableMap.of(SparkUtil.HANDLE_TIMESTAMP_WITHOUT_TIMEZONE, 
"true"), () -> {
+      Schema schema = TypeUtil.assignIncreasingFreshIds(new Schema(
+              required(0, "id", LongType.get()),
+              optional(1, "ts_without_zone", 
Types.TimestampType.withoutZone())));
+
+      writeAndValidate(schema);
+    });
+  }
+
+  protected void withSQLConf(Map<String, String> conf, Action action) throws 
IOException {
+    SQLConf sqlConf = SQLConf.get();
+
+    Map<String, String> currentConfValues = Maps.newHashMap();
+    conf.keySet().forEach(confKey -> {
+      if (sqlConf.contains(confKey)) {
+        String currentConfValue = sqlConf.getConfString(confKey);
+        currentConfValues.put(confKey, currentConfValue);
+      }
+    });
+
+    conf.forEach((confKey, confValue) -> {
+      if (SQLConf.staticConfKeys().contains(confKey)) {
+        throw new RuntimeException("Cannot modify the value of a static 
config: " + confKey);
+      }
+      sqlConf.setConfString(confKey, confValue);
+    });
+
+    try {
+      action.invoke();
+    } finally {
+      conf.forEach((confKey, confValue) -> {
+        if (currentConfValues.containsKey(confKey)) {
+          sqlConf.setConfString(confKey, currentConfValues.get(confKey));
+        } else {
+          sqlConf.unsetConf(confKey);
+        }
+      });
+    }
+  }
+
+  @FunctionalInterface
+  protected interface Action {
+    void invoke() throws IOException;
+  }

Review comment:
       I am fully agree with you, it can be moved to separate interface with 
static method and placed in some general package  like
   
   ```java
   @FunctionalInterface
   public interface ConfigurableTestSQLConf {
   
     void invoke() throws IOException;
   
     static void withSQLConf(Map<String, String> conf, ConfigurableTestSQLConf 
action) throws IOException {
       SQLConf sqlConf = SQLConf.get();
   
       Map<String, String> currentConfValues = Maps.newHashMap();
       conf.keySet().forEach(confKey -> {
         if (sqlConf.contains(confKey)) {
           String currentConfValue = sqlConf.getConfString(confKey);
           currentConfValues.put(confKey, currentConfValue);
         }
       });
   
       conf.forEach((confKey, confValue) -> {
         if (SQLConf.staticConfKeys().contains(confKey)) {
           throw new RuntimeException("Cannot modify the value of a static 
config: " + confKey);
         }
         sqlConf.setConfString(confKey, confValue);
       });
   
       try {
         action.invoke();
       } finally {
         conf.forEach((confKey, confValue) -> {
           if (currentConfValues.containsKey(confKey)) {
             sqlConf.setConfString(confKey, currentConfValues.get(confKey));
           } else {
             sqlConf.unsetConf(confKey);
           }
         });
       }
     }
   }
   ```
   But this part better to do in separate PR, because other packages will be 
affected 




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