Qihoo360 / Quicksql

A Flexible, Fast, Federated(3F) SQL Analysis Middleware for Multiple Data Sources
https://quicksql.readthedocs.io
MIT License
2.06k stars 583 forks source link

ES用jdbc方式怎么查询 #190

Open Jack0000007 opened 4 years ago

Jack0000007 commented 4 years ago

我采用java代码用客户端向服务端发出jdbc查询请求但是不能返回数据。同样的语句用命令行确可以实现查询es请问是我哪里配置错误了吗?(已经同步过元数据) 代码如下: `public static void main(String[] args) throws ClassNotFoundException, SQLException {

Class.forName("com.qihoo.qsql.client.Driver"); //注入Drvier

Properties properties = new Properties();
properties.setProperty("runner","jdbc");
String url = "jdbc:quicksql:url=http://10.121.8.4:5888";
Connection connection = DriverManager.getConnection(url,properties);
Statement pS = connection.createStatement();
String sql = "SELECT * FROM product";
ResultSet rs =  pS.executeQuery(sql);
int j=0;
while (rs.next()) {
    for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
        System.out.println(rs.getMetaData().getColumnName(i)
                + ":" + rs.getObject(i)+"|");
    }
    j++;
    System.out.println("行数"+j);
}
rs.close();
pS.close();

}`

错误如下: 20/04/10 18:08:14 INFO DynamicSqlRunner: The SQL that is ready to execute is: SELECT count(*) FROM product 20/04/10 18:08:14 INFO DynamicSqlRunner: Read schema from manual schema, schema or path is: inline: { "version": "1.0", "defaultSchema": "QSql", "schemas": [{ "type": "custom", "name": "ecommerce", "factory": "com.qihoo.qsql.org.apache.calcite.adapter.elasticsearch.ElasticsearchCustomSchemaFactory", "operand": { "coordinates": "{'10.121.8.5': 9200}", "userConfig": "{'bulk.flush.max.actions': 10, 'bulk.flush.max.size.mb': 1,'esUser':'','esPass':''}", "index": "ecommerce" }, "tables": [ { "name": "product", "factory": "com.qihoo.qsql.org.apache.calcite.adapter.elasticsearch.ElasticsearchTableFactory", "operand": { "dbName": "ecommerce", "tableName": "product", "esNodes": "10.121.8.5", "esPort": "9200", "esUser": "", "esPass": "", "esIndex": "ecommerce/product", "esScrollNum": "1" }, "columns": [ {"name": "desc:string"}, {"name": "name:string"}, {"name": "price:bigint"}, {"name": "producer:string"}, {"name": "tags:string"} ] } ] } ] } java.lang.RuntimeException: java.sql.SQLException: Error while executing SQL "SELECT COUNT(*) FROMecommerce.productASproduct`": Error while compiling generated Java code: com.qihoo.qsql.org.apache.calcite.DataContext root;

public com.qihoo.qsql.org.apache.calcite.linq4j.Enumerable bind(final com.qihoo.qsql.org.apache.calcite.DataContext root0) { root = root0; return ((com.qihoo.qsql.org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable) com.qihoo.qsql.org.apache.calcite.schema.Schemas.queryable(root, root.getRootSchema().getSubSchema("ecommerce"), java.lang.Object[].class, "product")).find(java.util.Arrays.asList(new String[] {}), java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] { new com.qihoo.qsql.org.apache.calcite.util.Pair( "expr_col0", long.class)}), java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] {}), java.util.Collections.EMPTY_LIST, java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] { new com.qihoo.qsql.org.apache.calcite.util.Pair( "expr_col0", "{\"value_count\":{\"field\": \"_id\" }}")}), null, null); }

public Class getElementType() { return long.class; }

at com.qihoo.qsql.exec.JdbcPipeline.establishStatement(JdbcPipeline.java:372)
at com.qihoo.qsql.exec.JdbcPipeline.collect(JdbcPipeline.java:266)
at com.qihoo.qsql.server.QuicksqlServerMeta.getJDBCResultSet(QuicksqlServerMeta.java:807)
at com.qihoo.qsql.server.QuicksqlServerMeta.getExecuteResultSet(QuicksqlServerMeta.java:768)
at com.qihoo.qsql.server.QuicksqlServerMeta.prepareAndExecute(QuicksqlServerMeta.java:747)
at org.apache.calcite.avatica.remote.LocalService.apply(LocalService.java:206)
at org.apache.calcite.avatica.remote.Service$PrepareAndExecuteRequest.accept(Service.java:927)
at org.apache.calcite.avatica.remote.Service$PrepareAndExecuteRequest.accept(Service.java:879)
at org.apache.calcite.avatica.remote.AbstractHandler.apply(AbstractHandler.java:94)
at org.apache.calcite.avatica.remote.JsonHandler.apply(JsonHandler.java:52)
at org.apache.calcite.avatica.server.AvaticaJsonHandler.handle(AvaticaJsonHandler.java:130)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.sql.SQLException: Error while executing SQL "SELECT COUNT(*) FROM ecommerce.product AS product": Error while compiling generated Java code: com.qihoo.qsql.org.apache.calcite.DataContext root;

public com.qihoo.qsql.org.apache.calcite.linq4j.Enumerable bind(final com.qihoo.qsql.org.apache.calcite.DataContext root0) { root = root0; return ((com.qihoo.qsql.org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable) com.qihoo.qsql.org.apache.calcite.schema.Schemas.queryable(root, root.getRootSchema().getSubSchema("ecommerce"), java.lang.Object[].class, "product")).find(java.util.Arrays.asList(new String[] {}), java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] { new com.qihoo.qsql.org.apache.calcite.util.Pair( "expr_col0", long.class)}), java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] {}), java.util.Collections.EMPTY_LIST, java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] { new com.qihoo.qsql.org.apache.calcite.util.Pair( "expr_col0", "{\"value_count\":{\"field\": \"_id\" }}")}), null, null); }

public Class getElementType() { return long.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 com.qihoo.qsql.exec.JdbcPipeline.establishStatement(JdbcPipeline.java:370)
... 19 more

Caused by: java.lang.RuntimeException: Error while compiling generated Java code: com.qihoo.qsql.org.apache.calcite.DataContext root;

public com.qihoo.qsql.org.apache.calcite.linq4j.Enumerable bind(final com.qihoo.qsql.org.apache.calcite.DataContext root0) { root = root0; return ((com.qihoo.qsql.org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable) com.qihoo.qsql.org.apache.calcite.schema.Schemas.queryable(root, root.getRootSchema().getSubSchema("ecommerce"), java.lang.Object[].class, "product")).find(java.util.Arrays.asList(new String[] {}), java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] { new com.qihoo.qsql.org.apache.calcite.util.Pair( "expr_col0", long.class)}), java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] {}), java.util.Collections.EMPTY_LIST, java.util.Arrays.asList(new com.qihoo.qsql.org.apache.calcite.util.Pair[] { new com.qihoo.qsql.org.apache.calcite.util.Pair( "expr_col0", "{\"value_count\":{\"field\": \"_id\" }}")}), null, null); }

public Class getElementType() { return long.class; }

at org.apache.calcite.avatica.Helper.wrap(Helper.java:37)
at com.qihoo.qsql.org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:108)
at com.qihoo.qsql.org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1238)
at com.qihoo.qsql.org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:331)
at com.qihoo.qsql.org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230)
at com.qihoo.qsql.org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
at com.qihoo.qsql.org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
at com.qihoo.qsql.org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606)
at com.qihoo.qsql.org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at com.qihoo.qsql.org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 21 more

Caused by: org.codehaus.commons.compiler.CompileException: Line 5, Column 170: No applicable constructor/method found for actual parameters "com.qihoo.qsql.org.apache.calcite.DataContext, com.qihoo.qsql.org.apache.calcite.schema.Schema, java.lang.Class, java.lang.String"; candidates are: "public static com.qihoo.qsql.org.apache.calcite.linq4j.Queryable com.qihoo.qsql.org.apache.calcite.schema.Schemas.queryable(com.qihoo.qsql.org.apache.calcite.DataContext, com.qihoo.qsql.org.apache.calcite.schema.SchemaPlus, java.lang.Class, java.lang.String)", "public static com.qihoo.qsql.org.apache.calcite.linq4j.Queryable com.qihoo.qsql.org.apache.calcite.schema.Schemas.queryable(com.qihoo.qsql.org.apache.calcite.DataContext, java.lang.Class, java.lang.String[])", "public static com.qihoo.qsql.org.apache.calcite.linq4j.Queryable com.qihoo.qsql.org.apache.calcite.schema.Schemas.queryable(com.qihoo.qsql.org.apache.calcite.DataContext, java.lang.Class, java.lang.Iterable)" at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:11004) at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:8307) at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:8169) at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:8071) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4421) at org.codehaus.janino.UnitCompiler.access$7500(UnitCompiler.java:206) at org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:3774) at org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:3762) at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:4328) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:3762) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:4933) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4380) at org.codehaus.janino.UnitCompiler.access$7000(UnitCompiler.java:206) at org.codehaus.janino.UnitCompiler$12.visitCast(UnitCompiler.java:3769) at org.codehaus.janino.UnitCompiler$12.visitCast(UnitCompiler.java:3762) at org.codehaus.janino.Java$Cast.accept(Java.java:4183) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:3762) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4416) at org.codehaus.janino.UnitCompiler.access$9200(UnitCompiler.java:206) at org.codehaus.janino.UnitCompiler$12.visitParenthesizedExpression(UnitCompiler.java:3797) at org.codehaus.janino.UnitCompiler$12.visitParenthesizedExpression(UnitCompiler.java:3762) at org.codehaus.janino.Java$ParenthesizedExpression.accept(Java.java:4205) at org.codehaus.janino.Java$Lvalue.accept(Java.java:3563) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:3762) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:4933) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4476) at org.codehaus.janino.UnitCompiler.access$7500(UnitCompiler.java:206) at org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:3774) at org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:3762) at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:4328) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:3762) at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:4933) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2396) at org.codehaus.janino.UnitCompiler.access$2700(UnitCompiler.java:206) at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1387) at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1370) at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3011) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1370) at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1450) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:2811) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1262) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1234) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:538) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:420) at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:206) at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:374) at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:369) at org.codehaus.janino.Java$AbstractPackageMemberClassDeclaration.accept(Java.java:1309) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:369) at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:345) at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:396) at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:311) at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:229) at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:196) at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:49) at org.codehaus.janino.ClassBodyEvaluator.createInstance(ClassBodyEvaluator.java:345) at com.qihoo.qsql.org.apache.calcite.adapter.enumerable.EnumerableInterpretable.getBindable(EnumerableInterpretable.java:140) at com.qihoo.qsql.org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:105) ... 31 more`

Jack0000007 commented 4 years ago

用的是release-0.7版本