[ 
https://issues.apache.org/jira/browse/DRILL-7272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16887321#comment-16887321
 ] 

ASF GitHub Bot commented on DRILL-7272:
---------------------------------------

vvysotskyi commented on pull request #1826: DRILL-7272: Drill Metastore Read / 
Write API and Drill Iceberg Metastore implementation
URL: https://github.com/apache/drill/pull/1826#discussion_r304528967
 
 

 ##########
 File path: common/src/main/java/org/apache/drill/common/util/GuavaPatcher.java
 ##########
 @@ -88,4 +96,82 @@ private static void patchCloseables() throws Exception {
     logger.info("Google's Closeables patched for old HBase Guava version.");
   }
 
-}
+  /**
+   * Patches Guava Preconditions with missing methods, added for the Apache 
Iceberg.
+   */
+  private static void patchPreconditions() throws NotFoundException, 
CannotCompileException {
+    ClassPool cp = ClassPool.getDefault();
+    CtClass cc = cp.get("com.google.common.base.Preconditions");
+
+    // Javassist does not support varargs, generate methods with varying 
number of arguments
+    int startIndex = 1;
+    int endIndex = 5;
+
+    List<String> methodsWithVarargsTemplates = Arrays.asList(
+      "public static void checkArgument(boolean expression, String 
errorMessageTemplate, %s) {\n"
+        + "    if (!expression) {\n"
+        + "      throw new 
IllegalArgumentException(format(errorMessageTemplate, new Object[] { %s }));\n"
+        + "    }\n"
+        + "  }",
+
+      "public static Object checkNotNull(Object reference, String 
errorMessageTemplate, %s) {\n"
+        + "    if (reference == null) {\n"
+        + "      throw new NullPointerException(format(errorMessageTemplate, 
new Object[] { %s }));\n"
+        + "    } else {\n"
+        + "      return reference;\n"
+        + "    }\n"
+        + "  }",
+
+      "public static void checkState(boolean expression, String 
errorMessageTemplate, %s) {\n"
+        + "    if (!expression) {\n"
+        + "      throw new IllegalStateException(format(errorMessageTemplate, 
new Object[] { %s }));\n"
+        + "    }\n"
+        + "  }"
+    );
+
+    List<String> methodsWithPrimitives = Arrays.asList(
+      "public static void checkArgument(boolean expression, String 
errorMessageTemplate, int arg1) {\n"
+        + "    if (!expression) {\n"
+        + "      throw new 
IllegalArgumentException(format(errorMessageTemplate, new Object[] { new 
Integer(arg1) }));\n"
+        + "    }\n"
+        + "  }",
+      "public static Object checkNotNull(Object reference, String 
errorMessageTemplate, int arg1) {\n"
+        + "    if (reference == null) {\n"
+        + "      throw new NullPointerException(format(errorMessageTemplate, 
new Object[] { new Integer(arg1) }));\n"
+        + "    } else {\n"
+        + "      return reference;\n"
+        + "    }\n"
+        + "  }"
+    );
+
+    List<String> newMethods = IntStream.rangeClosed(startIndex, endIndex)
+      .mapToObj(
+        i -> {
+          List<String> args = IntStream.rangeClosed(startIndex, i)
+            .mapToObj(j -> "arg" + j)
+            .collect(Collectors.toList());
+
+          String methodInput = args.stream()
+            .map(arg -> "Object " + arg)
+            .collect(Collectors.joining(", "));
+
+          String arrayInput = String.join(", ", args);
+
+          return methodsWithVarargsTemplates.stream()
+            .map(method -> String.format(method, methodInput, arrayInput))
+            .collect(Collectors.toList());
+        })
+      .flatMap(Collection::stream)
+      .collect(Collectors.toList());
+
+    newMethods.addAll(methodsWithPrimitives);
+
+    for (String method : newMethods) {
+      CtMethod newMethod = CtNewMethod.make(method, cc);
+      cc.addMethod(newMethod);
+    }
+
+    cc.toClass();
+    logger.info("Google's Preconditions were patched to hold new methods.");
+  }
+}
 
 Review comment:
   ```suggestion
   }
   
   ```
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Implement Drill Iceberg Metastore plugin
> ----------------------------------------
>
>                 Key: DRILL-7272
>                 URL: https://issues.apache.org/jira/browse/DRILL-7272
>             Project: Apache Drill
>          Issue Type: Sub-task
>            Reporter: Arina Ielchiieva
>            Assignee: Arina Ielchiieva
>            Priority: Major
>              Labels: doc-impacting
>             Fix For: 1.17.0
>
>
> PR contains two README.md files which describe the changes.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to