luws created CALCITE-5172:
-----------------------------

             Summary: calcite-elasticsearch query failed with No applicable 
constructor
                 Key: CALCITE-5172
                 URL: https://issues.apache.org/jira/browse/CALCITE-5172
             Project: Calcite
          Issue Type: Bug
          Components: elasticsearch-adapter
    Affects Versions: 1.30.0
            Reporter: luws


{code:java}
package com.pupu.truck.impl.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.calcite.adapter.elasticsearch.ElasticsearchSchema;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class CalciteJdbcExample {


    public static void main(String[] args) throws Exception {
        RestClient restClient = RestClient.builder(new 
HttpHost("192.168.1.246", 9200)).build();
        ElasticsearchSchema elasticsearchSchema = new 
ElasticsearchSchema(restClient, new ObjectMapper(), "uba_flow_data");

        Properties info = new Properties();
        info.setProperty("caseSensitive", "false");

        Connection connection = DriverManager.getConnection("jdbc:calcite:", 
info);
        CalciteConnection calciteConnection = 
connection.unwrap(CalciteConnection.class);


        SchemaPlus rootSchema = calciteConnection.getRootSchema();
        rootSchema.add("es", elasticsearchSchema);
        
        String sql = "SELECT * FROM es.uba_flow_data";
        Statement statement = calciteConnection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);

        System.out.println(ResultSetUtil.resultString(resultSet));
    }
}
 {code}
After running the main function, i caught:

 
{code:java}
Exception in thread "main" java.sql.SQLException: Error while executing SQL 
"SELECT * FROM es.uba_flow_data": Error while compiling generated Java code:
public org.apache.calcite.linq4j.Enumerable bind(final 
org.apache.calcite.DataContext root) {
  final java.util.List sort = java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {});
  return 
((org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable)
 org.apache.calcite.schema.Schemas.queryable(root, 
root.getRootSchema().getSubSchema("es"), java.lang.Object[].class, 
"uba_flow_data")).find(java.util.Collections.EMPTY_LIST, 
java.util.Arrays.asList(new org.apache.calcite.util.Pair[] {
      new org.apache.calcite.util.Pair(
        "_MAP",
        java.util.Map.class)}), sort, java.util.Collections.EMPTY_LIST, sort, 
com.google.common.collect.ImmutableMap.of(), null, null);
}
public Class getElementType() {
  return java.util.Map.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.pupu.truck.impl.util.CalciteJdbcExample.main(CalciteJdbcExample.java:51)
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 java.util.List sort = java.util.Arrays.asList(new 
org.apache.calcite.util.Pair[] {});
  return 
((org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.ElasticsearchQueryable)
 org.apache.calcite.schema.Schemas.queryable(root, 
root.getRootSchema().getSubSchema("es"), java.lang.Object[].class, 
"uba_flow_data")).find(java.util.Collections.EMPTY_LIST, 
java.util.Arrays.asList(new org.apache.calcite.util.Pair[] {
      new org.apache.calcite.util.Pair(
        "_MAP",
        java.util.Map.class)}), sort, java.util.Collections.EMPTY_LIST, sort, 
com.google.common.collect.ImmutableMap.of(), null, null);
}
public Class getElementType() {
  return java.util.Map.class;
}    at org.apache.calcite.avatica.Helper.wrap(Helper.java:37)
    at 
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:130)
    at 
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1131)
    at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:324)
    at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:220)
    at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:648)
    at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:514)
    at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:484)
    at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:234)
    at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:623)
    at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:674)
    at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
    ... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: Line 3, Column 140: 
No applicable constructor/method found for actual parameters 
"org.apache.calcite.DataContext, org.apache.calcite.schema.Schema, 
java.lang.Class, java.lang.String"; candidates are: "public static 
org.apache.calcite.linq4j.Queryable 
org.apache.calcite.schema.Schemas.queryable(org.apache.calcite.DataContext, 
java.lang.Class, java.lang.Iterable)", "public static 
org.apache.calcite.linq4j.Queryable 
org.apache.calcite.schema.Schemas.queryable(org.apache.calcite.DataContext, 
java.lang.Class, java.lang.String[])", "public static 
org.apache.calcite.linq4j.Queryable 
org.apache.calcite.schema.Schemas.queryable(org.apache.calcite.DataContext, 
org.apache.calcite.schema.SchemaPlus, java.lang.Class, java.lang.String)"
    at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:11821)
    at 
org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:8910)
    at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:8770)
    at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:8672)
    at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4737)
    at org.codehaus.janino.UnitCompiler.access$8300(UnitCompiler.java:212)
    at 
org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:4097)
    at 
org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:4070)
    at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:4902)
    at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4070)
    at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5253)
    at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4696)
    at org.codehaus.janino.UnitCompiler.access$7800(UnitCompiler.java:212)
    at org.codehaus.janino.UnitCompiler$12.visitCast(UnitCompiler.java:4092)
    at org.codehaus.janino.UnitCompiler$12.visitCast(UnitCompiler.java:4070)
    at org.codehaus.janino.Java$Cast.accept(Java.java:4727)
    at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4070)
    at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4732)
    at org.codehaus.janino.UnitCompiler.access$7300(UnitCompiler.java:212)
    at 
org.codehaus.janino.UnitCompiler$12$1.visitParenthesizedExpression(UnitCompiler.java:4083)
    at 
org.codehaus.janino.UnitCompiler$12$1.visitParenthesizedExpression(UnitCompiler.java:4074)
    at org.codehaus.janino.Java$ParenthesizedExpression.accept(Java.java:4753)
    at org.codehaus.janino.UnitCompiler$12.visitLvalue(UnitCompiler.java:4074)
    at org.codehaus.janino.UnitCompiler$12.visitLvalue(UnitCompiler.java:4070)
    at org.codehaus.janino.Java$Lvalue.accept(Java.java:3977)
    at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4070)
    at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5253)
    at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:4792)
    at org.codehaus.janino.UnitCompiler.access$8300(UnitCompiler.java:212)
    at 
org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:4097)
    at 
org.codehaus.janino.UnitCompiler$12.visitMethodInvocation(UnitCompiler.java:4070)
    at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:4902)
    at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4070)
    at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5253)
    at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2628)
    at org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:212)
    at 
org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1483)
    at 
org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1466)
    at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3392)
    at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1466)
    at 
org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1546)
    at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3075)
    at 
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1336)
    at 
org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1309)
    at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:799)
    at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:411)
    at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:212)
    at 
org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:390)
    at 
org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:385)
    at 
org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1405)
    at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:385)
    at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:357)
    at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:234)
    at 
org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:446)
    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:204)
    at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:52)
    at 
org.codehaus.janino.ClassBodyEvaluator.createInstance(ClassBodyEvaluator.java:347)
    at 
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.getBindable(EnumerableInterpretable.java:166)
    at 
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:127)
    ... 12 more {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to