I had found the empty result was happened at select validate,it could
not get column datatype from jdbc connection metadata .
I changed the query,it throw exception about "Column 'TS' not found in
any table":
String url="jdbc:TAOS://127.0.0.1:6030/hdb";
DriverManager.registerDriver(DriverManager.getDriver(url));
Class.forName("org.postgresql.Driver");
BasicDataSource dataSource = new BasicDataSource();
...
Schema schema = JdbcSchema.create(rootSchema, "test", dataSource,
"hdb", null);
rootSchema.add("test", schema);
Statement stat = calciteConnection.createStatement();
ResultSet rs = stat.executeQuery("select ts,speed from test.t");
while(rs.next()) {
System.out.println(rs.getObject(2));
}
I debug this code step by step,found this happened at JdbcSchema.java
line 368,which function is :getRelDataType(DatabaseMetaData metaData,
String catalogName,
String schemaName, String tableName)
the catalogName and schemaName are both null,tableName is "t".
and it execute
final ResultSet resultSet =
metaData.getColumns(catalogName, schemaName, tableName, null);
to get the columns.
*But I don't know why **catalogName is null,I think it should be "hdb"*
I checked the object JdbcTable,its property jdbcCatalogName was also
null,while jdbcSchema.catalog was "hdb".
Is this a bug? The catalog assigned when JdbcSchema created was not
assigned to the JdbcTable.
this is the stack trace:
Thread [main] (Suspended)
owns: CalciteJdbc41Factory$CalciteJdbc41Statement (id=40)
JdbcSchema.getRelDataType(DatabaseMetaData, String, String, String)
line: 370
JdbcSchema.getRelDataType(String, String, String) line: 362
JdbcTable.getRowType(RelDataTypeFactory) line: 117
EmptyScope.resolve_(CalciteSchema, List<String>, List<String>,
SqlNameMatcher, Path, Resolved) line: 159
EmptyScope.resolveTable(List<String>, SqlNameMatcher, Path,
Resolved) line: 99
CatalogScope(DelegatingScope).resolveTable(List<String>,
SqlNameMatcher, Path, Resolved) line: 203
IdentifierNamespace.resolveImpl(SqlIdentifier) line: 112
IdentifierNamespace.validateImpl(RelDataType) line: 184
IdentifierNamespace(AbstractNamespace).validate(RelDataType) line: 84
CalciteSqlValidator(SqlValidatorImpl).validateNamespace(SqlValidatorNamespace,
RelDataType) line: 1110
CalciteSqlValidator(SqlValidatorImpl).validateQuery(SqlNode,
SqlValidatorScope, RelDataType) line: 1084
CalciteSqlValidator(SqlValidatorImpl).validateFrom(SqlNode,
RelDataType, SqlValidatorScope) line: 3256
CalciteSqlValidator(SqlValidatorImpl).validateFrom(SqlNode,
RelDataType, SqlValidatorScope) line: 3238
CalciteSqlValidator(SqlValidatorImpl).validateSelect(SqlSelect,
RelDataType) line: 3510
SelectNamespace.validateImpl(RelDataType) line: 60
SelectNamespace(AbstractNamespace).validate(RelDataType) line: 84
CalciteSqlValidator(SqlValidatorImpl).validateNamespace(SqlValidatorNamespace,
RelDataType) line: 1110
CalciteSqlValidator(SqlValidatorImpl).validateQuery(SqlNode,
SqlValidatorScope, RelDataType) line: 1084
SqlSelect.validate(SqlValidator, SqlValidatorScope) line: 232
CalciteSqlValidator(SqlValidatorImpl).validateScopedExpression(SqlNode,
SqlValidatorScope) line: 1059
CalciteSqlValidator(SqlValidatorImpl).validate(SqlNode) line: 766
SqlToRelConverter.convertQuery(SqlNode, boolean, boolean) line: 563
CalcitePrepareImpl$CalcitePreparingStmt(Prepare).prepareSql(SqlNode,
SqlNode, Class, SqlValidator, boolean) line: 242
CalcitePrepareImpl$CalcitePreparingStmt(Prepare).prepareSql(SqlNode,
Class, SqlValidator, boolean) line: 208
CalcitePrepareImpl.prepare2_(Context, Query<T>, Type, long,
CalciteCatalogReader, RelOptPlanner) line: 632
CalcitePrepareImpl.prepare_(Context, Query<T>, Type, long) line: 498
CalcitePrepareImpl.prepareSql(Context, Query<T>, Type, long) line: 468
CalciteJdbc41Factory$CalciteJdbc41Connection(CalciteConnectionImpl).parseQuery(Query<T>,
Context, long) line: 231
CalciteMetaImpl.prepareAndExecute(Meta$StatementHandle, String,
long, int, Meta$PrepareCallback) line: 552
CalciteJdbc41Factory$CalciteJdbc41Connection(AvaticaConnection).prepareAndExecuteInternal(AvaticaStatement,
String, long) line: 675
CalciteJdbc41Factory$CalciteJdbc41Statement(AvaticaStatement).executeInternal(String)
line: 156
CalciteJdbc41Factory$CalciteJdbc41Statement(AvaticaStatement).executeQuery(String)
line: 227
App5.main(String[]) line: 45
On 7/24/20 9:20 AM, tonytao wrote:
Thanks Julian!
I had queried on result metadata,it has 2 columns.
code:
ResultSet rs = stmt.executeQuery("select * from hdb.t");
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
System.out.println(rs.getMetaData().getColumnName(i));
}
while (rs.next()) {
System.out.println(rs.getObject(2));
}
output:
ts
speed
10
20
I'll dig in this jdbc driver today to find where the this empty
resultset returned.
Thanks again for your help.
Best regards!
On 7/24/20 1:18 AM, Julian Hyde wrote:
I don’t think you need to debug the code, Tony. It’s not your fault,
it is a bug in the code generation. So, two actions:
1. Please log a bug with a repro case. (It sounds as if the key
factor is a table with zero columns.)
2. There is a workaround. Add at least one column to your table.
Julian
On Jul 23, 2020, at 2:18 AM, tonytao <[email protected]> wrote:
Thanks again,danny!
It's hard to set the appropriate breakpoint position.:-). I'll check
the jdbc api whether it returned correct results.
Best regards!
On 7/23/20 4:44 PM, Danny Chan wrote:
In general, Calcite use janino to compile the generated Java string
codes into real instances during the query execution, you error
throws because the code generation generates java file with invalid
syntax.
Things are not bad now, you can set up a break point in the
debugger, and all the generated code would be in the directory you
have configured, here, you can see the error file path is:
File '/home/tony/workspace/tmp/janino7222401528383593043.java',
Line 8, Column 20:
The generated files names may change each time you debug it, and
disappear when you stop debugging, so you need to copy the files
out and past it into the IDEA again to see which file has the Java
syntax error.
Best,
Danny Chan
在 2020年7月23日 +0800 PM4:05,tonytao
<[email protected]>,写道:
hi Danny,
Thank you for your kindly help.
Attach is the generated code.but I had no idea how this file
generated or fix the bug.
I'm sorry that I could not receive your reply with my work email
account,so I replied with my personal account.
errlog:
at org.apache.calcite.avatica.Helper.wrap(Helper.java:37)
at
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:128)
at
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1111)
at
org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:309)
at
org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:208)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:632)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:498)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:468)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231)
at
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:552)
at
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: File
'/home/tony/workspace/tmp/janino7222401528383593043.java', Line 8,
Column 20: Catch clause is unreachable
at
org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:12211)
at
org.codehaus.janino.UnitCompiler.compileTryCatch(UnitCompiler.java:3110)
at
org.codehaus.janino.UnitCompiler.compileTryCatchFinally(UnitCompiler.java:2966)
at
org.codehaus.janino.UnitCompiler.compileTryCatchFinallyWithResources(UnitCompiler.java:2770)
Thanks!
It seems that you got some problem with the generated code, take
this [1] to debug the code
and to see which line caused the compilation error.
[1]
https://calcite.apache.org/docs/howto.html#debugging-generated-classes-in-intellij
Best,
Danny Chan
在 2020年7月22日 +0800 AM12:17,taojin <[email protected]>,写道:
hi folks,
I has met a compiler error on calcite-core:1.23.0,jdk version is
:openjdk version "11.0.7" 2020-04-14.
Here is the error log,is this a bug?
Exception in thread "main" java.sql.SQLException: Error while
executing
SQL "select * from test.t": Error while compiling generated Java
code:
public org.apache.calcite.linq4j.Enumerable bind(final
org.apache.calcite.DataContext root) {
final org.apache.calcite.linq4j.function.Function1
rowBuilderFactory
= new org.apache.calcite.linq4j.function.Function1() {
public org.apache.calcite.linq4j.function.Function0 apply(final
java.sql.ResultSet resultSet) {
return new org.apache.calcite.linq4j.function.Function0() {
public Object apply() {
try {
return new Object[0];
} catch (java.sql.SQLException e) {
throw new RuntimeException(
e);
}
}
}
;
}
public Object apply(final Object resultSet) {
return apply(
(java.sql.ResultSet) resultSet);
}
}
;
final org.apache.calcite.runtime.ResultSetEnumerable enumerable =
org.apache.calcite.runtime.ResultSetEnumerable.of((javax.sql.DataSource)
root.getRootSchema().getSubSchema("test").unwrap(javax.sql.DataSource.class),
"SELECT *\nFROM hdb.t", rowBuilderFactory);
enumerable.setTimeout(root);
return enumerable;
}
public Class getElementType() {
return org.apache.calcite.runtime.FlatLists.ComparableList.class;
}
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 mtest.App5.main(App5.java:45)
Caused by: java.lang.RuntimeException: Error while compiling
generated
Java code:
public org.apache.calcite.linq4j.Enumerable bind(final
org.apache.calcite.DataContext root) {
final org.apache.calcite.linq4j.function.Function1
rowBuilderFactory
= new org.apache.calcite.linq4j.function.Function1() {
public org.apache.calcite.linq4j.function.Function0 apply(final
java.sql.ResultSet resultSet) {
return new org.apache.calcite.linq4j.function.Function0() {
public Object apply() {
try {
return new Object[0];
} catch (java.sql.SQLException e) {
throw new RuntimeException(
e);
}
}
}
;
}
public Object apply(final Object resultSet) {
return apply(
(java.sql.ResultSet) resultSet);
}
}
;
final org.apache.calcite.runtime.ResultSetEnumerable enumerable =
org.apache.calcite.runtime.ResultSetEnumerable.of((javax.sql.DataSource)
root.getRootSchema().getSubSchema("test").unwrap(javax.sql.DataSource.class),
"SELECT *\nFROM hdb.t", rowBuilderFactory);
enumerable.setTimeout(root);
return enumerable;
}
public Class getElementType() {
return org.apache.calcite.runtime.FlatLists.ComparableList.class;
}
at org.apache.calcite.avatica.Helper.wrap(Helper.java:37)
at
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:128)
at
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1111)
at
org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:309)
at
org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:208)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:632)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:498)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:468)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231)
at
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:552)
at
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: Line 8,
Column 20: Catch clause is unreachable
at
org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:12211)
at
org.codehaus.janino.UnitCompiler.compileTryCatch(UnitCompiler.java:3110)
at
org.codehaus.janino.UnitCompiler.compileTryCatchFinally(UnitCompiler.java:2966)
at
org.codehaus.janino.UnitCompiler.compileTryCatchFinallyWithResources(UnitCompiler.java:2770)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2742)
at
org.codehaus.janino.UnitCompiler.access$2300(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$6.visitTryStatement(UnitCompiler.java:1499)
at
org.codehaus.janino.UnitCompiler$6.visitTryStatement(UnitCompiler.java:1487)
at org.codehaus.janino.Java$TryStatement.accept(Java.java:3241)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
at
org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
at
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
at
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:981)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:951)
at
org.codehaus.janino.UnitCompiler.access$200(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:409)
at
org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:406)
at
org.codehaus.janino.Java$AnonymousClassDeclaration.accept(Java.java:1149)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
at
org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5509)
at
org.codehaus.janino.UnitCompiler.access$9500(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4432)
at
org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4396)
at
org.codehaus.janino.Java$NewAnonymousClassInstance.accept(Java.java:5238)
at
org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
at
org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2649)
at
org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1504)
at
org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1487)
at
org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3563)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
at
org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
at
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
at
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:981)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:951)
at
org.codehaus.janino.UnitCompiler.access$200(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:409)
at
org.codehaus.janino.UnitCompiler$2.visitAnonymousClassDeclaration(UnitCompiler.java:406)
at
org.codehaus.janino.Java$AnonymousClassDeclaration.accept(Java.java:1149)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
at
org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5509)
at
org.codehaus.janino.UnitCompiler.access$9500(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4432)
at
org.codehaus.janino.UnitCompiler$16.visitNewAnonymousClassInstance(UnitCompiler.java:4396)
at
org.codehaus.janino.Java$NewAnonymousClassInstance.accept(Java.java:5238)
at
org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4396)
at
org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5662)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2580)
at
org.codehaus.janino.UnitCompiler.access$2700(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$6.visitLocalVariableDeclarationStatement(UnitCompiler.java:1503)
at
org.codehaus.janino.UnitCompiler$6.visitLocalVariableDeclarationStatement(UnitCompiler.java:1487)
at
org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.java:3522)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
at
org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
at
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
at
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:432)
at
org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:215)
at
org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:411)
at
org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:406)
at
org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1414)
at
org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
at
org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:378)
at
org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237)
at
org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465)
at
org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:313)
at
org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:235)
at
org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:207)
at
org.codehaus.commons.compiler.Cookable.cook(Cookable.java:50)
at
org.codehaus.janino.ClassBodyEvaluator.createInstance(ClassBodyEvaluator.java:347)
at
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.getBindable(EnumerableInterpretable.java:162)
at
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:125)
... 12 more