lmhmhl commented on issue #8883:
URL: https://github.com/apache/shardingsphere/issues/8883#issuecomment-756029979


   Hi @tristaZero , when I am doing the test, some unexpected error happened as 
follows:
   ```
   java.lang.NullPointerException: at index 0
   
        at 
com.google.common.collect.ObjectArrays.checkElementNotNull(ObjectArrays.java:225)
        at 
com.google.common.collect.ObjectArrays.checkElementsNotNull(ObjectArrays.java:215)
        at 
com.google.common.collect.ObjectArrays.checkElementsNotNull(ObjectArrays.java:209)
        at 
com.google.common.collect.ImmutableList.construct(ImmutableList.java:346)
        at 
com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:258)
        at 
com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:231)
        at org.apache.calcite.util.Util.immutableCopy(Util.java:2456)
        at 
org.apache.calcite.prepare.CalciteCatalogReader.<init>(CalciteCatalogReader.java:104)
        at 
org.apache.calcite.prepare.CalciteCatalogReader.<init>(CalciteCatalogReader.java:92)
        at 
org.apache.shardingsphere.infra.optimize.context.CalciteContextFactory.createCalciteCatalogReader(CalciteContextFactory.java:118)
        at 
org.apache.shardingsphere.infra.optimize.context.CalciteContextFactory.create(CalciteContextFactory.java:109)
        at 
org.apache.shardingsphere.infra.optimize.context.CalciteContextFactory.create(CalciteContextFactory.java:104)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.createCalciteExecutor(ShardingSphereStatement.java:196)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.executeQueryByCalcite(ShardingSphereStatement.java:184)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.executeQuery(ShardingSphereStatement.java:171)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.executeQuery(ShardingSphereStatement.java:152)
        at 
org.apache.shardingsphere.driver.jdbc.core.calcite.CalciteJDBCExecutorTest.executeQuery(CalciteJDBCExecutorTest.java:72)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at 
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at 
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runners.Suite.runChild(Suite.java:128)
        at org.junit.runners.Suite.runChild(Suite.java:27)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
        at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
        at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
        at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70
   Process finished with exit code 255
   ```
   Then I debugged the code and found that the error is caused in 
CalciteContextFactory class:
   ```
   private CalciteContext create(final CalciteConnectionConfig config,
                                     final SqlParser.Config parserConfig, final 
RelDataTypeFactory typeFactory, final RelOptCluster cluster, final 
CalciteLogicSchema calciteLogicSchema) {
           CalciteCatalogReader catalogReader = 
createCalciteCatalogReader(config, typeFactory, calciteLogicSchema);
           SqlValidator validator = createSqlValidator(config, typeFactory, 
catalogReader);
           SqlToRelConverter relConverter = createSqlToRelConverter(cluster, 
validator, catalogReader);
           return new CalciteContext(properties, calciteLogicSchema, 
parserConfig, validator, relConverter);
       }
   ```
   ```
       private CalciteCatalogReader createCalciteCatalogReader(final 
CalciteConnectionConfig config, final RelDataTypeFactory typeFactory, final 
CalciteLogicSchema calciteLogicSchema) {
           CalciteSchema rootSchema = CalciteSchema.createRootSchema(true);
           rootSchema.add(calciteLogicSchema.getName(), calciteLogicSchema);
           return new CalciteCatalogReader(rootSchema, 
Collections.singletonList(config.schema()), typeFactory, config);
       }
   ```
   ```
   public CalciteCatalogReader(CalciteSchema rootSchema, List<String> 
defaultSchema, RelDataTypeFactory typeFactory, CalciteConnectionConfig config) {
           this(rootSchema, SqlNameMatchers.withCaseSensitive(config != null && 
config.caseSensitive()), 
ImmutableList.of(Objects.requireNonNull(defaultSchema), ImmutableList.of()), 
typeFactory, config);
       }
   ```
   The error is caused by `config.schema()` returns null, but in 
`CalciteCatalogReader` class, 
`ImmutableList.of(Objects.requireNonNull(defaultSchema)` are not allowed Null.  
I have been bothered by this question a few days, can u give me some advices? 
Thx.
   


----------------------------------------------------------------
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:
[email protected]


Reply via email to