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

Julian Hyde commented on CALCITE-821:
-------------------------------------

I changed the apply method because we were wanted to use the schema from 
Frameworks.PrepareAction.getConfig().getDefaultSchema() in preference to 
CalcitePrepare.Context.getRootSchema(). If you back out the change, 
RelBuilderTest fails to find any tables.

But I didn't think of the case where FrameworkConfig.getDefaultSchema() returns 
null. The method javadoc says it is allowed to, and it seems that Hive is doing 
that.

Can you try the following patch and see if it improves things:

{noformat}
diff --git a/core/src/main/java/org/apache/calcite/tools/Frameworks.java 
b/core/src/main/java/org/apache/calcite/tools/Frameworks.java
index c73a1e2..db3f3f0 100644
--- a/core/src/main/java/org/apache/calcite/tools/Frameworks.java
+++ b/core/src/main/java/org/apache/calcite/tools/Frameworks.java
@@ -36,6 +36,7 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import org.apache.calcite.util.Util;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -106,8 +107,11 @@ public abstract R apply(RelOptCluster cluster, 
RelOptSchema relOptSchema,
         new Frameworks.PrepareAction<R>(config) {
           public R apply(RelOptCluster cluster, RelOptSchema relOptSchema,
               SchemaPlus rootSchema, CalciteServerStatement statement) {
+            if (false)
+              return action.apply(cluster, relOptSchema, rootSchema);
             final CalciteSchema schema =
-                CalciteSchema.from(config.getDefaultSchema());
+                CalciteSchema.from(
+                    Util.first(config.getDefaultSchema(), rootSchema));
             return action.apply(cluster, relOptSchema, schema.root().plus());
           }
         });
{noformat}

> NPE in CalciteSchema during preparation of planning phase
> ---------------------------------------------------------
>
>                 Key: CALCITE-821
>                 URL: https://issues.apache.org/jira/browse/CALCITE-821
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Jesus Camacho Rodriguez
>
> During testing of 1.4-SNAPSHOT on Hive, we hit the Exception with the 
> following stacktrace in all our tests:
> {noformat}
> java.lang.NullPointerException
>         at org.apache.calcite.jdbc.CalciteSchema.from(CalciteSchema.java:316)
>         at org.apache.calcite.tools.Frameworks$1.apply(Frameworks.java:109)
>         at 
> org.apache.calcite.prepare.CalcitePrepareImpl.perform(CalcitePrepareImpl.java:880)
>         at 
> org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:147)
>         at 
> org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:105)
>         at 
> org.apache.hadoop.hive.ql.parse.CalcitePlanner.getOptimizedAST(CalcitePlanner.java:614)
>         at 
> org.apache.hadoop.hive.ql.parse.CalcitePlanner.genOPTree(CalcitePlanner.java:249)
>         at 
> org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:10130)
>         at 
> org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:209)
>         at 
> org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:240)
> ...
> {noformat}
> The problem is that the FrameworkConfig defaultSchema is null. Thus, a NPE is 
> thrown after hitting this piece of code in Frameworks:
> {code}
> final CalciteSchema schema =
>   CalciteSchema.from(config.getDefaultSchema());
> {code}
> The apply method was changed in CALCITE-748.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to