This is an automated email from the ASF dual-hosted git repository.

boroknagyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 6b4c895f9aa1d3989c343f05270bc6a60815bc45
Author: Steve Carlin <[email protected]>
AuthorDate: Tue Feb 3 09:55:11 2026 -0800

    IMPALA-14719: Fixed race condition for Calcite property
    
    IMPALA-14710 was filed for a flaky test involving the
    calcite.default.charset property. Setting this property
    before the jar file is loaded fixes this issue.
    
    This commit also fixes two other issues:
    
    - IMPALA-14384: Class.forName() is only called once now. The compiler
      factory is stored in a singleton.
    
    - The Calcite planner is now part of the build and should be in the
      target directory. If the user explicitly sets the calcite planner
      option and the calcite jar file not found, an error is thrown rather
      than falling back.
    
    Change-Id: I80a0207150cf521c297b12a24075ae5f29c5c5ff
    Reviewed-on: http://gerrit.cloudera.org:8080/23935
    Reviewed-by: Impala Public Jenkins <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 .../java/org/apache/impala/service/Frontend.java   | 36 +++++++++++++---------
 .../calcite/service/CalciteCompilerFactory.java    |  4 ---
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/fe/src/main/java/org/apache/impala/service/Frontend.java 
b/fe/src/main/java/org/apache/impala/service/Frontend.java
index f9f8184f4..35ddee177 100644
--- a/fe/src/main/java/org/apache/impala/service/Frontend.java
+++ b/fe/src/main/java/org/apache/impala/service/Frontend.java
@@ -308,6 +308,10 @@ public class Frontend {
   public static final String PLANNER_PROFILE = "PlannerInfo";
   public static final String PLANNER_TYPE = "PlannerType";
 
+  // The Calcite compiler is loaded on demand, not linked in. The factory is a
+  // singleton.
+  private static CompilerFactory calciteCompilerFactory = 
loadCalciteCompilerFactory();
+
   /**
    * Plan-time context that allows capturing various artifacts created
    * during the process.
@@ -3777,27 +3781,31 @@ public class Frontend {
   }
 
   @Nullable
-  private CompilerFactory getCalciteCompilerFactory(PlanCtx ctx) {
+  private CompilerFactory getCalciteCompilerFactory(PlanCtx ctx)
+      throws ImpalaException {
     TQueryOptions queryOptions = 
ctx.getQueryContext().client_request.getQuery_options();
-    LOG.info("Searching for planner to use...");
     if (queryOptions.isUse_calcite_planner()) {
-      try {
-        CompilerFactory calciteFactory = (CompilerFactory) Class.forName(
-            "org.apache.impala.calcite.service." +
-            "CalciteCompilerFactory").newInstance();
-        if (calciteFactory != null) {
-          LOG.info("Found Calcite Planner, using it.");
-          return calciteFactory;
-        } else {
-          LOG.info("Could not find Calcite planner, using original planner.");
-        }
-      } catch (Exception e) {
-        LOG.info("Could not find Calcite planner, using original planner: " + 
e);
+      if (calciteCompilerFactory == null) {
+        throw new InternalException("Could not find Calcite planner");
       }
+      return calciteCompilerFactory;
     }
     return null;
   }
 
+  private static CompilerFactory loadCalciteCompilerFactory() {
+    LOG.info("Loading Calcite Planner jar file");
+    try {
+      System.setProperty("calcite.default.charset", "UTF8");
+      return (CompilerFactory) Class.forName(
+          "org.apache.impala.calcite.service." +
+          "CalciteCompilerFactory").newInstance();
+    } catch (Exception e) {
+      LOG.info("Could not find Calcite planner: " + e);
+      return null;
+    }
+  }
+
   public String getShowCreateTable(
       TTableName tname, boolean withStats, int partitionLimit) throws 
ImpalaException {
     Frontend.RetryTracker retries = new Frontend.RetryTracker(
diff --git 
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteCompilerFactory.java
 
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteCompilerFactory.java
index 98e518d9a..e2eb59319 100644
--- 
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteCompilerFactory.java
+++ 
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteCompilerFactory.java
@@ -45,10 +45,6 @@ public class CalciteCompilerFactory implements 
CompilerFactory {
   protected static final Logger LOG =
       LoggerFactory.getLogger(CalciteCompilerFactory.class.getName());
 
-  static {
-    System.setProperty("calcite.default.charset", "UTF8");
-  }
-
   private static final String PLANNER = "CalcitePlanner";
 
   static {

Reply via email to