Can't find java file for ImmutableCsvProjectTableScanRule

2022-03-13 Thread xiaobo
Hi,

we are trying to make our adapter projectable now,  but we can't find the Java 
file for the ImmutableCsvProjectTableScanRule class in the CSV example, can you 
help with this.


/** Rule configuration. */
  @Value.Immutable(singleton = false)
  public interface Config extends RelRule.Config {
    Config DEFAULT = 
ImmutableCsvProjectTableScanRule.Config.builder()
    .withOperandSupplier(b0 ->
    
b0.operand(LogicalProject.class).oneInput(b1 ->
   
 b1.operand(CsvTableScan.class).noInputs()))
    .build();

    @Override default CsvProjectTableScanRule toRule() {
  return new CsvProjectTableScanRule(this);
    }
  }

Re: Can't find java file for ImmutableCsvProjectTableScanRule

2022-03-13 Thread Fan Liya
Hi xiaobo,

It seems 'ImmutableCsvProjectTableScanRule' is a generated class.
You have to build the project first?

Best,
Liya Fan


xiaobo  于2022年3月13日周日 18:47写道:

> Hi,
>
> we are trying to make our adapter projectable now,  but we can't find the
> Java file for the ImmutableCsvProjectTableScanRule class in the CSV
> example, can you help with this.
>
>
> /** Rule configuration. */
>   @Value.Immutable(singleton = false)
>   public interface Config extends RelRule.Config {
>     Config DEFAULT =
> ImmutableCsvProjectTableScanRule.Config.builder()
>     .withOperandSupplier(b0 ->
>    
> b0.operand(LogicalProject.class).oneInput(b1 ->
>    
> b1.operand(CsvTableScan.class).noInputs()))
>     .build();
>
>     @Override default CsvProjectTableScanRule toRule() {
>   return new CsvProjectTableScanRule(this);
>     }
>   }


column data type mismatch problem when projecting tables

2022-03-13 Thread xiaobo
Hi,

Followed the avro example at 
https://github.com/masayuki038/calcite-avro-sample, 

we make a projectable version of our JsonAdapter  at 
https://github.com/guxiaobo/calcite-json-adapter, 

but the simple test2 method  at 
https://github.com/guxiaobo/calcite-json-adapter/blob/main/src/test/java/org/apache/calcite/adapter/json/test/DynamicDataTest.java




 failed with data type mismatch problem with message :




Running org.apache.calcite.adapter.json.test.DynamicDataTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
details.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.286 sec <<< 
FAILURE!
test2(org.apache.calcite.adapter.json.test.DynamicDataTest)  Time elapsed: 
2.222 sec  <<< ERROR!
java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class 
java.lang.Long ([Ljava.lang.Object; and java.lang.Long are in module java.base 
of loader 'bootstrap')
    at 
org.apache.calcite.avatica.util.AbstractCursor$LongAccessor.getLong(AbstractCursor.java:562)
    at 
org.apache.calcite.avatica.AvaticaResultSet.getLong(AvaticaResultSet.java:261)
    at 
org.apache.calcite.adapter.json.test.BaseTest.exeGetLong(BaseTest.java:40)
    at 
org.apache.calcite.adapter.json.test.DynamicDataTest.test2(DynamicDataTest.java:107)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at 
org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at 
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at 
org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at 
org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at 
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at 
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at 
org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Tests in error: 
  test2(org.apache.calcite.adapter.json.test.DynamicDataTest): class 
[Ljava.lang.Object; cannot be cast to class java.lang.Long ([Ljava.lang.Object; 
and java.lang.Long are in module java.base of loader 'bootstrap')

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0







By the way, the v0.0.1 version of our adapter only implements a  ScannableTable 
, and all the testes can run successfully.

Re:column data type mismatch problem when projecting tables

2022-03-13 Thread xiaobo
if we change the sql to  "select c1, c2 from js.t1", then test2 passes, 
 and we found that


the deduce method CursorFactory returns OBJECT when the resultset has only one 
column,

public static CursorFactory deduce(Listhttps://github.com/masayuki038/calcite-avro-sample,

we make a projectable version of our JsonAdapter  at 
https://github.com/guxiaobo/calcite-json-adapter,

but the simple test2 method  at 
https://github.com/guxiaobo/calcite-json-adapter/blob/main/src/test/java/org/apache/calcite/adapter/json/test/DynamicDataTest.java




failed with data type mismatch problem with message :




Running org.apache.calcite.adapter.json.test.DynamicDataTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
details.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.286 sec <<< 
FAILURE!
test2(org.apache.calcite.adapter.json.test.DynamicDataTest)  Time elapsed: 
2.222 sec  <<< ERROR!
java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class 
java.lang.Long ([Ljava.lang.Object; and java.lang.Long are in module java.base 
of loader 'bootstrap')
    at 
org.apache.calcite.avatica.util.AbstractCursor$LongAccessor.getLong(AbstractCursor.java:562)
    at 
org.apache.calcite.avatica.AvaticaResultSet.getLong(AvaticaResultSet.java:261)
    at 
org.apache.calcite.adapter.json.test.BaseTest.exeGetLong(BaseTest.java:40)
    at 
org.apache.calcite.adapter.json.test.DynamicDataTest.test2(DynamicDataTest.java:107)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at 
org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at 
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at 
org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at 
org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at 
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at 
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at 
org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Tests in error: 
  test2(org.apache.calcite.adapter.json.test.DynamicDataTest): class 
[Ljava.lang.Object; cannot be cast to class java.lang.Long ([Ljava.lang.Object; 
and java.lang.Long are in module java.base of loader 'bootstrap')

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0







By the way, the v0.0.1 version of our adapter only implements a 
 ScannableTable , and all the testes can run successfully.

Re: Can't find java file for ImmutableCsvProjectTableScanRule

2022-03-13 Thread Gavin Ray
I believe you need to make sure that the "Immutables" annotations processor
is set up correctly
Like Fan Liya mentioned, that class is generated by the annotations, so you
need to configure Gradle/Maven to process them:

If you haven't already, make sure to enable Annotation Processors in your
IDE settings (I assume IntelliJ?)
https://immutables.github.io/apt.html#intellij-idea

Hope this helps

On Sun, Mar 13, 2022 at 6:24 AM Fan Liya  wrote:

> Hi xiaobo,
>
> It seems 'ImmutableCsvProjectTableScanRule' is a generated class.
> You have to build the project first?
>
> Best,
> Liya Fan
>
>
> xiaobo  于2022年3月13日周日 18:47写道:
>
> > Hi,
> >
> > we are trying to make our adapter projectable now,  but we can't find the
> > Java file for the ImmutableCsvProjectTableScanRule class in the CSV
> > example, can you help with this.
> >
> >
> > /** Rule configuration. */
> >   @Value.Immutable(singleton = false)
> >   public interface Config extends RelRule.Config {
> >     Config DEFAULT =
> > ImmutableCsvProjectTableScanRule.Config.builder()
> >     .withOperandSupplier(b0 ->
> >    
> > b0.operand(LogicalProject.class).oneInput(b1 ->
> >
>    
> > b1.operand(CsvTableScan.class).noInputs()))
> >     .build();
> >
> >     @Override default CsvProjectTableScanRule toRule() {
> >   return new CsvProjectTableScanRule(this);
> >     }
> >   }
>


Re:Re:column data type mismatch problem when projecting tables

2022-03-13 Thread xiaobo
we updated our  enumerator to return only the column data object for single 
column projects,  our projectable adapter works for basic queries now, but 
faced with new problems which I'll send another mail.












Original


From:"xiaobo "< guxiaobo1...@qq.com >;

Date:2022/3/13 21:59

To:"dev"< dev@calcite.apache.org >;

Subject:Re:column data type mismatch problem  when projecting tables








if we change the sql to  "select c1, c2 from js.t1", then test2 passes, 
 and we found that


the deduce method CursorFactory returns OBJECT when the resultset has only one 
column,

public static CursorFactory deduce(Listhttps://github.com/masayuki038/calcite-avro-sample,

we make a projectable version of our JsonAdapter  at 
https://github.com/guxiaobo/calcite-json-adapter,

but the simple test2 method  at 
https://github.com/guxiaobo/calcite-json-adapter/blob/main/src/test/java/org/apache/calcite/adapter/json/test/DynamicDataTest.java




failed with data type mismatch problem with message :




Running org.apache.calcite.adapter.json.test.DynamicDataTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
details.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.286 sec <<< 
FAILURE!
test2(org.apache.calcite.adapter.json.test.DynamicDataTest)  Time elapsed: 
2.222 sec  <<< ERROR!
java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class 
java.lang.Long ([Ljava.lang.Object; and java.lang.Long are in module java.base 
of loader 'bootstrap')
    at 
org.apache.calcite.avatica.util.AbstractCursor$LongAccessor.getLong(AbstractCursor.java:562)
    at 
org.apache.calcite.avatica.AvaticaResultSet.getLong(AvaticaResultSet.java:261)
    at 
org.apache.calcite.adapter.json.test.BaseTest.exeGetLong(BaseTest.java:40)
    at 
org.apache.calcite.adapter.json.test.DynamicDataTest.test2(DynamicDataTest.java:107)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at 
org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at 
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at 
org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at 
org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at 
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at 
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at 
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at 
org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Tests in error: 
  test2(org.apache.calcite.adapter.json.test.DynamicDataTest): class 
[Ljava.lang.Object; cannot be cast to class java.lang.Long ([Ljava.lang.Object; 
and java.lang.Long are i

applying the wrong rule for calculated columns

2022-03-13 Thread xiaobo
@Test

public void test1_2()throws SQLException{

Map

re:applying the wrong rule for calculated columns

2022-03-13 Thread xiaobo
our runnable test is at 
https://github.com/guxiaobo/calcite-json-adapter/blob/main/src/test/java/org/apache/calcite/adapter/json/test/JsonSchemaTest.java



-- original mail --



@Test
public void test1_2()throws SQLException{
Map> map = makeJsonMap();
Schema schema = new JsonSchema<>("js", map);
CalciteConnection conn = this.openConn1(schema, "js");  
System.out.println("c1 + c11 = " + exeGetLong(conn, "select c1 
+ c11 from js.t1"));

conn.close();

}

For the above simple calculated sql, calcite throws the following error, it 
seems calcite refers to our Table class to return data type information for c1 
+ c11, which we think calcite should infer itself. calcite calls 
deriveRowType() of our JsonTableScan class with field [EXPR$0] which is not a 
field of ourtable.test1_2(org.apache.calcite.adapter.json.test.JsonSchemaTest) 


Error while preparing plan [LogicalProject(EXPR$0=[+($1, $0)])
  JsonTableScan(table=[[vars, vars]])
]
at 
com.xsmartware.pbcm.policy.CalciteBasedVarGenerator.generateVariable(CalciteBasedVarGenerator.java:65)
 ~[classes/:?]
at 
com.xsmartware.pbcm.thread.VarGenThread.doCompute(VarGenThread.java:24) 
~[classes/:?]
at 
com.xsmartware.pbcm.thread.VarGenThread.doCompute(VarGenThread.java:10) 
~[classes/:?]
at 
com.xsmartware.pbcm.thread.PBCMBaseThread.run(PBCMBaseThread.java:38) 
[classes/:?]
at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 
[?:?]
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 
[?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.sql.SQLException: Error while preparing plan 
[LogicalProject(EXPR$0=[+($1, $0)])
  JsonTableScan(table=[[vars, vars]])
]
at org.apache.calcite.avatica.Helper.createException(Helper.java:56) 
~[avatica-core-1.20.0.jar:1.20.0]
at org.apache.calcite.avatica.Helper.createException(Helper.java:41) 
~[avatica-core-1.20.0.jar:1.20.0]
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:239)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.access$100(CalciteConnectionImpl.java:101)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.jdbc.CalciteConnectionImpl$2.prepareStatement(CalciteConnectionImpl.java:188)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
com.xsmartware.common.calcite.CalciteDatabase.executeQuery(CalciteDatabase.java:109)
 ~[classes/:?]
at 
com.xsmartware.common.calcite.CalciteDatabase.executeQuery(CalciteDatabase.java:103)
 ~[classes/:?]
at 
com.xsmartware.common.calcite.CalciteDatabase.exeGetLong(CalciteDatabase.java:138)
 ~[classes/:?]
at 
com.xsmartware.pbcm.policy.CalciteBasedVarGenerator.generateVariable(CalciteBasedVarGenerator.java:43)
 ~[classes/:?]
... 8 more
Caused by: java.lang.RuntimeException: Error while applying rule 
JsonProjectTableScanRule, args 
[rel#500:LogicalProject.NONE.[](input=RelSubset#499,exprs=[+($1, $0)]), 
rel#494:JsonTableScan.ENUMERABLE.[](table=[vars, vars])]
at 
org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:250)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.plan.volcano.IterativeRuleDriver.drive(IterativeRuleDriver.java:59)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:523)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:276) 
~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:336) 
~[calcite-core-1.29.0.jar:1.29.0]
at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:177) 
~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.prepare_(CalcitePrepareImpl.java:1026)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.prepareRel(CalcitePrepareImpl.java:988)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:668)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:513)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:483)
 ~[calcite-core-1.29.0.jar:1.29.0]
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java

re:applying the wrong rule for calculated columns

2022-03-13 Thread xiaobo
after we change the String[] fields to Integer[] fields , the problem still 
occurs.



our runnable test is at 
https://github.com/guxiaobo/calcite-json-adapter/blob/main/src/test/java/org/apache/calcite/adapter/json/test/JsonSchemaTest.java

---
@Test
public void test1_2()throws SQLException{
Map> map = makeJsonMap();
Schema schema = new JsonSchema<>("js", map);
CalciteConnection conn = this.openConn1(schema, "js");  
System.out.println("c1 + c11 = " + exeGetLong(conn, "select c1 
+ c11 from js.t1"));

conn.close();

}
---

java.sql.SQLException: Error while executing SQL "select c1 + c11 from js.t1": 
Error while applying rule JsonProjectTableScanRule, args 
[rel#11:LogicalProject.NONE.[](input=RelSubset#10,exprs=[+($9, $3)]), 
rel#1:JsonTableScan.ENUMERABLE.[](table=[js, t1])]
at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
at 
org.apache.calcite.adapter.json.test.BaseTest.exeGetLong(BaseTest.java:37)
at 
org.apache.calcite.adapter.json.test.JsonSchemaTest.test1_2(JsonSchemaTest.java:76)
at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at 
org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.RuntimeException: Error while applying rule 
JsonProjectTableScanRule, args 
[rel#11:LogicalProject.NONE.[](input=RelSubset#10,exprs=[+($9, $3)]), 
rel#1:JsonTableScan.ENUMERABLE.[](table=[js, t1])]
at 
org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:250)
at 
org.apache.calcite.plan.volcano.IterativeRuleDriver.drive(IterativeRuleDriver.java:59)
at 
org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:523)
at 
org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:276)
at 
org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:336)
at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:177)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:312)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:220)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:647)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:513)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:483)

Re:re:applying the wrong rule for calculated columns

2022-03-13 Thread xiaobo
@Override

  public void onMatch(RelOptRuleCall call) {

    LogicalProject project = call.rel(0);

    JsonTableScan scan = call.rel(1);

    Integer[] fields = 
getProjectFields(project.getProjects());

    if(fields == null || fields.length == 0)

      return ;

    for(int i = 0; i < fields.length; i++) {

      if(fields[i] == null)

      return;

    }




    call.transformTo(

      new JsonTableScan(scan.getCluster(), 
scan.getTable(), fields)

    );

  }




the onMatch method should check fields data, if they are not  correct, 
then should not call  call.transformTo.




test1_2 now passes.





-- Original --
From:   
 "xiaobo "  
  
https://github.com/guxiaobo/calcite-json-adapter/blob/main/src/test/java/org/apache/calcite/adapter/json/test/JsonSchemaTest.java

---
 @Test
 public void test1_2()throws SQLException{
Map

[jira] [Created] (CALCITE-5039) View:Timestamp cannot query Data:Long in GMT+8 TimeZone Env

2022-03-13 Thread itxiangkui (Jira)
itxiangkui created CALCITE-5039:
---

 Summary: View:Timestamp cannot query Data:Long in GMT+8 TimeZone 
Env
 Key: CALCITE-5039
 URL: https://issues.apache.org/jira/browse/CALCITE-5039
 Project: Calcite
  Issue Type: Bug
  Components: jdbc-driver
Affects Versions: 1.29.0
Reporter: itxiangkui


When I have a row like :
|ts:TimeStamp|channel:String|pv:Long|
|164718720|ios|10|

 

while 164718720 is a timestamp in TimeZone of "GMT+8",the datetime is 
"2022-03-14 00:00:00"

but you can not query the data using a sql like :

```sql

select * from table where ts='2022-03-14 00:00:00';

select * from table where ts<'2022-03-14 00:00:01' and  ts>'2022-03-13 
23:59:59' ;

```

it is like the jdbc-fether will filter the data when match the 
timestampString,while the timestamp String looks like '2022-03-13 16:00:00' or 
'2022-03-14 08:00:00'

 

 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)