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


##########
flink/v1.16/flink/src/main/java/org/apache/iceberg/flink/util/FlinkPackage.java:
##########
@@ -19,15 +19,31 @@
 package org.apache.iceberg.flink.util;
 
 import org.apache.flink.streaming.api.datastream.DataStream;
+import 
org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
 
 public class FlinkPackage {
-  /** Choose {@link DataStream} class because it is one of the core Flink API. 
*/
-  private static final String VERSION = 
DataStream.class.getPackage().getImplementationVersion();
+
+  public static final String FLINK_UNKNOWN_VERSION = "Flink-UNKNOWN";
 
   private FlinkPackage() {}
 
   /** Returns Flink version string like x.y.z */
   public static String version() {
-    return VERSION;
+    try {
+      String version = getVersionFromJar();
+      /* If we can't detect the exact implementation version from the jar 
(this can happen if the DataStream class
+       appears multiple times in the same classpath such as with shading), 
then the best we can do is say it's
+       unknown
+      */
+      return version != null ? version : FLINK_UNKNOWN_VERSION;

Review Comment:
   If we do this, we might not want to create an extra method for 
`initFlinkVersion`, just something like this:
   ```
     public static String version() {
       if (null == VERSION.get()) {
         try {
           String jarVersion = versionFromJar();
           // use unknown version in case exact implementation version can't be 
found from the jar (this
           // can happen if the DataStream class appears multiple times in the 
same classpath such as
           // with shading)
           VERSION.set(jarVersion != null ? jarVersion : UNKNOWN_VERSION);
         } catch (Exception e) {
           VERSION.set(UNKNOWN_VERSION);
         }
       }
   
       return VERSION.get();
     }
   ```



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