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 &gt;;

Date:2022/3/13 21:59

To:"dev"< dev@calcite.apache.org &gt;;

Subject:Re:column data type mismatch problem &nbsp;when projecting tables








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


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

public static CursorFactory deduce(List<ColumnMetaData&gt; columns,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Class resultClazz) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (columns.size() == 1) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return OBJECT;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (resultClazz == null) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ARRAY;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (resultClazz.isArray()) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ARRAY;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (List.class.isAssignableFrom(resultClazz)) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return LIST;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return record(resultClazz, null,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; columns.stream().map(c 
-&gt; c.columnName).collect(Collectors.toList()));
&nbsp;&nbsp;&nbsp; }




we think this is bug, &nbsp;we think method deduce should always determin the 
CursorFactory type based on class of resultClazz, because our adapters always 
return a Object[] object even there is only one column.









Original


From:"xiaobo "< guxiaobo1...@qq.com &gt;;

Date:2022/3/13 20:21

To:"dev"< dev@calcite.apache.org &gt;;

Subject:column data type mismatch problem &nbsp;when projecting tables





Hi,

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

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

but the simple test2 method &nbsp;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)&nbsp; Time elapsed: 
2.222 sec&nbsp; <<< 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')
&nbsp;&nbsp; &nbsp;at 
org.apache.calcite.avatica.util.AbstractCursor$LongAccessor.getLong(AbstractCursor.java:562)
&nbsp;&nbsp; &nbsp;at 
org.apache.calcite.avatica.AvaticaResultSet.getLong(AvaticaResultSet.java:261)
&nbsp;&nbsp; &nbsp;at 
org.apache.calcite.adapter.json.test.BaseTest.exeGetLong(BaseTest.java:40)
&nbsp;&nbsp; &nbsp;at 
org.apache.calcite.adapter.json.test.DynamicDataTest.test2(DynamicDataTest.java:107)
&nbsp;&nbsp; &nbsp;at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
&nbsp;&nbsp; &nbsp;at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
&nbsp;&nbsp; &nbsp;at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
&nbsp;&nbsp; &nbsp;at java.base/java.lang.reflect.Method.invoke(Method.java:566)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
&nbsp;&nbsp; &nbsp;at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
&nbsp;&nbsp; &nbsp;at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
&nbsp;&nbsp; &nbsp;at 
org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
&nbsp;&nbsp; &nbsp;at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
&nbsp;&nbsp; &nbsp;at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
&nbsp;&nbsp; &nbsp;at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
&nbsp;&nbsp; &nbsp;at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
&nbsp;&nbsp; &nbsp;at java.base/java.lang.reflect.Method.invoke(Method.java:566)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
&nbsp;&nbsp; &nbsp;at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Tests in error: 
&nbsp; 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 
&nbsp;ScannableTable , and all the testes can run successfully.

Reply via email to