本文介绍了Apache Calcite Geode JDBC Adapte无法与Gemfire 8.x和9.X一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用apache方解石geode采用者来连接Gemfire 8.2.按照下面的日志,它的连接正确,但是尝试执行获取异常的查询.

I am trying to connect Gemfire 8.2 using apache calcite geode adopter.As per following logs its connectied properly but while try to execute query getting exception .

此外,在其中添加了一个新的适配器,用于从Apache Geode读取数据 这个版本.此外,在 现有的适配器

Moreover, a new adapter to read data from Apache Geode was added in this release. In addition, more progress has been made for the existing adapters

1)连接类

package com.khan.vaquar;

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

import com.google.common.collect.ImmutableMap;

public class GemfireJDBCTest1 {

    public static void main(String[] args) {
        //
        new GemfireJDBCTest1().connection1();
        //
        //new GemfireJDBCTest1().connection2();
    }

    /***
     * 
     */
    public void connection1() {
        try {
            Class.forName(org.apache.calcite.jdbc.Driver.class.getName());
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Properties info = new Properties();
        info.setProperty("lex", "JAVA"); // Enables case sensitivity
        info.setProperty("model",
                "C://Users//vkhan//Documents//scala-workspace//CalciteGemfire//src//com//khan//vaquar//myModel.json "); // See
                                                                                                                            // section
                                                                                                                            // below
        try {
            Connection connection = DriverManager.getConnection("jdbc:calcite:", info);

            Statement statement = connection.createStatement();

            ResultSet resultset = statement.executeQuery("select * from account"); //("select * from \"account\"");

            final StringBuilder buf = new StringBuilder();

            while (resultset.next()) {

                ResultSetMetaData metaData = resultset.getMetaData();
                /*
                for (int i = 1; i <= metaData.getColumnCount(); i++) {

                }
                */
            }

            System.out.println("Conected---------------------------");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


}

2)JSON"myModel.json"

{
  "version": "1.0",
  "defaultSchema": "geode",
  "schemas": [
    {
      "name": "geode_raw",
      "type": "custom",
      "factory": "org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory",
      "operand": {
        "locatorHost": "localhost",
        "locatorPort": "10334",
        "regions": "account",
        "pdxSerializablePackagePath": ".*"
      }
    }
  ]
}

Jars

aggdesigner-algorithm-6.0.jar
antlr-2.7.7.jar
avatica-core-1.11.0.jar
avatica-metrics-1.11.0.jar
calcite-core-1.16.0.jar
calcite-geode-1.16.0.jar
calcite-linq4j-1.16.0.jar
commons-beanutils-1.9.3.jar
commons-codec-1.9.jar
commons-collections-3.2.2.jar
commons-compiler-2.7.6.jar
commons-dbcp-1.4.jar
commons-digester-2.1.jar
commons-io-2.5.jar
commons-lang-2.6.jar
commons-lang3-3.2.jar
commons-logging-1.1.3.jar
commons-pool-1.5.4.jar
commons-validator-1.6.jar
esri-geometry-api-2.0.0.jar
fast-classpath-scanner-2.0.11.jar
fastutil-7.1.0.jar
findbugs-annotations-1.3.9-1.jar
geode-common-1.3.0.jar
geode-core-1.3.0.jar
geode-json-1.3.0.jar
guava-19.0.jar
httpclient-4.5.2.jar
httpcore-4.4.4.jar
jackson-annotations-2.9.4.jar
jackson-core-2.9.4.jar
jackson-databind-2.9.4.jar
janino-2.7.6.jar
javax.resource-api-1.7.jar
javax.transaction-api-1.2.jar
jgroups-3.6.10.Final.jar
jna-4.0.0.jar
jopt-simple-5.0.3.jar
jsr305-3.0.1.jar
log4j-api-2.8.2.jar
log4j-core-2.8.2.jar
memory-0.9.0.jar
protobuf-java-3.3.0.jar
shiro-core-1.3.2.jar
sketches-core-0.9.0.jar
slf4j-api-1.7.13.jar

Gemfire 8.2(Geode)

Gemfire 8.2 (Geode)

使用此查询时出现以下异常

When using this query getting following exception

(1)ResultSet结果集= statement.executeQuery(从帐户中选择*");

(1) ResultSet resultset = statement.executeQuery("select * from account");

例外:

Build-Date: 2017-10-26 21:57:38 +0530
Build-Id: sbawaskar 0
Build-Java-Version: 1.8.0_121
Build-Platform: Mac OS X 10.12.6 x86_64
Product-Name: Apache Geode
Product-Version: 1.3.0
Source-Date: 2017-10-18 22:02:15 +0530
Source-Repository: release/1.3.0
Source-Revision: 59f2a73d108101744ed7b2d88e8d1c948d19781c
Native version: native code unavailable
Running on: /3.142.66.67, 4 cpu(s), amd64 Windows 7 6.1 
Communications version: 70
Process ID: 16120
User: VKhan
Current dir: C:\Users\VKhan\Documents\scala-workspace\CalciteGemfire
Home dir: C:\Users\VKhan
Command Line Parameters:
  -Dfile.encoding=Cp1252
Class Path:
  C:\Users\VKhan\Documents\scala-workspace\CalciteGemfire\bin
  C:\jars\aggdesigner-algorithm-6.0.jar
  C:\jars\antlr-2.7.7.jar
  C:\jars\avatica-core-1.11.0.jar
  C:\jars\avatica-metrics-1.11.0.jar
  C:\jars\calcite-core-1.16.0.jar
  C:\jars\calcite-geode-1.16.0.jar
  C:\jars\calcite-linq4j-1.16.0.jar
  C:\jars\commons-beanutils-1.9.3.jar
  C:\jars\commons-codec-1.9.jar
  C:\jars\commons-collections-3.2.2.jar
  C:\jars\commons-compiler-2.7.6.jar
  C:\jars\commons-dbcp-1.4.jar
  C:\jars\commons-digester-2.1.jar
  C:\jars\commons-io-2.5.jar
  C:\jars\commons-lang-2.6.jar
  C:\jars\commons-lang3-3.2.jar
  C:\jars\commons-logging-1.1.3.jar
  C:\jars\commons-pool-1.5.4.jar
  C:\jars\commons-validator-1.6.jar
  C:\jars\esri-geometry-api-2.0.0.jar
  C:\jars\fast-classpath-scanner-2.0.11.jar
  C:\jars\fastutil-7.1.0.jar
  C:\jars\findbugs-annotations-1.3.9-1.jar
  C:\jars\geode-common-1.3.0.jar
  C:\jars\geode-core-1.3.0.jar
  C:\jars\geode-json-1.3.0.jar
  C:\jars\guava-19.0.jar
  C:\jars\httpclient-4.5.2.jar
  C:\jars\httpcore-4.4.4.jar
  C:\jars\jackson-annotations-2.9.4.jar
  C:\jars\jackson-core-2.9.4.jar
  C:\jars\jackson-databind-2.9.4.jar
  C:\jars\janino-2.7.6.jar
  C:\jars\javax.resource-api-1.7.jar
  C:\jars\javax.transaction-api-1.2.jar
  C:\jars\jgroups-3.6.10.Final.jar
  C:\jars\jna-4.0.0.jar
  C:\jars\jopt-simple-5.0.3.jar
  C:\jars\jsr305-3.0.1.jar
  C:\jars\log4j-api-2.8.2.jar
  C:\jars\log4j-core-2.8.2.jar
  C:\jars\memory-0.9.0.jar
  C:\jars\protobuf-java-3.3.0.jar
  C:\jars\shiro-core-1.3.2.jar
  C:\jars\sketches-core-0.9.0.jar
  C:\jars\slf4j-api-1.7.13.jar
Library Path:
  C:\Program Files\Java\jdk1.8.0_131\jre\bin
  C:\WINDOWS\Sun\Java\bin
  C:\WINDOWS\system32
  C:\WINDOWS
  C:/Program Files (x86)/Java/jre1.8.0_161/bin/client
  C:/Program Files (x86)/Java/jre1.8.0_161/bin
  C:/Program Files (x86)/Java/jre1.8.0_161/lib/i386
  C:\ProgramData\Oracle\Java\javapath
  C:\Program Files (x86)\RSA SecurID Token Common
  C:\WINDOWS\system32
  C:\WINDOWS
  C:\WINDOWS\System32\Wbem
  C:\WINDOWS\System32\WindowsPowerShell\v1.0\
  C:\Program Files (x86)\WebEx\Productivity Tools
  C:\Program Files (x86)\Extra!\
  C:\Program Files (x86)\WebEx\PTools020000000
  C:\SUPPORT\apache-maven-3.3.9\bin
  C:\Program Files\TortoiseSVN\bin
  C:\Program Files\Cloud Foundry
  C:\Users\VKhan\AppData\Roaming\Cloud Foundry
  C:\Program Files (x86)\Sennheiser\SoftphoneSDK\
  C:\Program Files (x86)\PuTTY\
  C:\Program Files\Git\cmd
  C:\spark\video\softwareandcode\Spark\bin
  C:\hadoop\bin
  C:\Program Files (x86)\sbt\bin
  C:\vaquarkhan\sts-bundle\sts-3.8.4.RELEASE
  .
System Properties:
    awt.toolkit = sun.awt.windows.WToolkit
    file.encoding = Cp1252
    file.encoding.pkg = sun.io
    file.separator = \
    java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
    java.awt.printerjob = sun.awt.windows.WPrinterJob
    java.class.version = 52.0
    java.endorsed.dirs = C:\Program Files\Java\jdk1.8.0_131\jre\lib\endorsed
    java.ext.dirs = C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
    java.home = C:\Program Files\Java\jdk1.8.0_131\jre
    java.io.tmpdir = C:\Users\VKhan\AppData\Local\Temp\
    java.runtime.name = Java(TM) SE Runtime Environment
    java.runtime.version = 1.8.0_131-b11
    java.specification.name = Java Platform API Specification
    java.specification.vendor = Oracle Corporation
    java.specification.version = 1.8
    java.vendor = Oracle Corporation
    java.vendor.url = http://java.oracle.com/
    java.vendor.url.bug = http://bugreport.sun.com/bugreport/
    java.version = 1.8.0_131
    java.vm.info = mixed mode
    java.vm.name = Java HotSpot(TM) 64-Bit Server VM
    java.vm.specification.name = Java Virtual Machine Specification
    java.vm.specification.vendor = Oracle Corporation
    java.vm.specification.version = 1.8
    java.vm.vendor = Oracle Corporation
    java.vm.version = 25.131-b11
    line.separator = 
    os.version = 6.1
    path.separator = ;
    sun.arch.data.model = 64
    sun.boot.class.path = C:\Program Files\Java\jdk1.8.0_131\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_131\jre\classes
    sun.boot.library.path = C:\Program Files\Java\jdk1.8.0_131\jre\bin
    sun.cpu.endian = little
    sun.cpu.isalist = amd64
    sun.desktop = windows
    sun.io.unicode.encoding = UnicodeLittle
    sun.java.command = com.khan.vaquar.GemfireJDBCTest1
    sun.java.launcher = SUN_STANDARD
    sun.jnu.encoding = Cp1252
    sun.management.compiler = HotSpot 64-Bit Tiered Compilers
    sun.nio.ch.bugLevel = 
    sun.os.patch.level = Service Pack 1
    user.country = US
    user.language = en
    user.script = 
    user.timezone = America/Chicago
    user.variant = 
Log4J 2 Configuration:
    jar:file:/C:/jars/geode-core-1.3.0.jar!/log4j2.xml
---------------------------------------------------------------------------


[info 2018/03/21 10:41:02.553 CDT <main> tid=0x1] Running in client mode

[info 2018/03/21 10:41:02.646 CDT <main> tid=0x1] Requesting cluster configuration

[info 2018/03/21 10:41:02.646 CDT <main> tid=0x1] Loading previously deployed jars

[info 2018/03/21 10:41:02.709 CDT <main> tid=0x1] AutoConnectionSource UpdateLocatorListTask started with interval=10,000 ms.

[info 2018/03/21 10:41:02.709 CDT <main> tid=0x1] Pool DEFAULT started with multiuser-authentication=false

java.sql.SQLException: Error while executing SQL "select * from account": From line 1, column 15 to line 1, column 21: Object 'account' not found
    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:156)
    at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
    at com.khan.vaquar.GemfireJDBCTest1.connection1(GemfireJDBCTest1.java:43)
    at com.khan.vaquar.GemfireJDBCTest1.main(GemfireJDBCTest1.java:17)
Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 15 to line 1, column 21: Object 'account' not found
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
    at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:803)
    at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:788)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:4706)
    at org.apache.calcite.sql.validate.IdentifierNamespace.resolveImpl(IdentifierNamespace.java:172)
    at org.apache.calcite.sql.validate.IdentifierNamespace.validateImpl(IdentifierNamespace.java:177)
    at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:947)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:928)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2975)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2960)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3219)
    at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
    at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:947)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:928)
    at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:226)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
    at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
    at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
    at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
    at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230)
    at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
    at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
    at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
    at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
    at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
    at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
    at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
    ... 3 more
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Object 'account' not found
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
    at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
    ... 31 more
[info 2018/03/21 10:41:03.427 CDT <Distributed system shutdown hook> tid=0xc] VM is exiting - shutting down distributed system

[info 2018/03/21 10:41:03.427 CDT <Distributed system shutdown hook> tid=0xc] GemFireCache[id = 657069980; isClosing = true; isShutDownAll = false; created = Wed Mar 21 10:41:02 CDT 2018; server = false; copyOnRead = false; lockLease = 120; lockTimeout = 60]: Now closing.

[info 2018/03/21 10:41:03.505 CDT <Distributed system shutdown hook> tid=0xc] Destroying connection pool DEFAULT

[info 2018/03/21 10:41:05.581 CDT <poolTimer-DEFAULT-2> tid=0x18] AutoConnectionSource discovered new locators [XXXX/XXXX:10334]

[info 2018/03/21 10:41:05.613 CDT <poolTimer-DEFAULT-3> tid=0x19] Updating membership port.  Port changed from 0 to 64,781.  ID is now XXXXXX(16120:loner):0:8b803849

2)使用以下样式时,出现以下异常

2) When using following style getting following exception

ResultSet resultset = statement.executeQuery("select * from \"account\"");

例外:

[info 2018/03/21 11:00:09.274 CDT <main> tid=0x1] Running in client mode

[info 2018/03/21 11:00:09.352 CDT <main> tid=0x1] Requesting cluster configuration

[info 2018/03/21 11:00:09.368 CDT <main> tid=0x1] Loading previously deployed jars

[info 2018/03/21 11:00:09.430 CDT <main> tid=0x1] AutoConnectionSource UpdateLocatorListTask started with interval=10,000 ms.

[info 2018/03/21 11:00:09.430 CDT <main> tid=0x1] Pool DEFAULT started with multiuser-authentication=false

java.sql.SQLException: Error while executing SQL "select * from "account"": parse failed: Encountered "from \"" at line 1, column 10.
Was expecting one of:
    <EOF> 
    "ORDER" ...
    "LIMIT" ...
    "OFFSET" ...
    "FETCH" ...
    "FROM" <IDENTIFIER> ...
    "FROM" <QUOTED_IDENTIFIER> ...
    "FROM" <BACK_QUOTED_IDENTIFIER> ...
    "FROM" <BRACKET_QUOTED_IDENTIFIER> ...
    "FROM" <UNICODE_QUOTED_IDENTIFIER> ...
    "FROM" "LATERAL" ...
    "FROM" "(" ...
    "FROM" "UNNEST" ...
    "FROM" "TABLE" ...
    "," ...
    "AS" ...
    <IDENTIFIER> ...
    <QUOTED_IDENTIFIER> ...
    <BACK_QUOTED_IDENTIFIER> ...
    <BRACKET_QUOTED_IDENTIFIER> ...
    <UNICODE_QUOTED_IDENTIFIER> ...
    "UNION" ...
    "INTERSECT" ...
    "EXCEPT" ...
    "MINUS" ...

    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:156)
    at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
    at com.khan.vaquar.GemfireJDBCTest1.connection1(GemfireJDBCTest1.java:43)
    at com.khan.vaquar.GemfireJDBCTest1.main(GemfireJDBCTest1.java:17)
Caused by: java.lang.RuntimeException: parse failed: Encountered "from \"" at line 1, column 10.
Was expecting one of:
    <EOF> 
    "ORDER" ...
    "LIMIT" ...
    "OFFSET" ...
    "FETCH" ...
    "FROM" <IDENTIFIER> ...
    "FROM" <QUOTED_IDENTIFIER> ...
    "FROM" <BACK_QUOTED_IDENTIFIER> ...
    "FROM" <BRACKET_QUOTED_IDENTIFIER> ...
    "FROM" <UNICODE_QUOTED_IDENTIFIER> ...
    "FROM" "LATERAL" ...
    "FROM" "(" ...
    "FROM" "UNNEST" ...
    "FROM" "TABLE" ...
    "," ...
    "AS" ...
    <IDENTIFIER> ...
    <QUOTED_IDENTIFIER> ...
    <BACK_QUOTED_IDENTIFIER> ...
    <BRACKET_QUOTED_IDENTIFIER> ...
    <UNICODE_QUOTED_IDENTIFIER> ...
    "UNION" ...
    "INTERSECT" ...
    "EXCEPT" ...
    "MINUS" ...

    at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:760)
    at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
    at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
    at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
    at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
    at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
    at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
    ... 3 more
Caused by: org.apache.calcite.sql.parser.SqlParseException: Encountered "from \"" at line 1, column 10.
Was expecting one of:
    <EOF> 
    "ORDER" ...
    "LIMIT" ...
    "OFFSET" ...
    "FETCH" ...
    "FROM" <IDENTIFIER> ...
    "FROM" <QUOTED_IDENTIFIER> ...
    "FROM" <BACK_QUOTED_IDENTIFIER> ...
    "FROM" <BRACKET_QUOTED_IDENTIFIER> ...
    "FROM" <UNICODE_QUOTED_IDENTIFIER> ...
    "FROM" "LATERAL" ...
    "FROM" "(" ...
    "FROM" "UNNEST" ...
    "FROM" "TABLE" ...
    "," ...
    "AS" ...
    <IDENTIFIER> ...
    <QUOTED_IDENTIFIER> ...
    <BACK_QUOTED_IDENTIFIER> ...
    <BRACKET_QUOTED_IDENTIFIER> ...
    <UNICODE_QUOTED_IDENTIFIER> ...
    "UNION" ...
    "INTERSECT" ...
    "EXCEPT" ...
    "MINUS" ...

    at org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:350)
    at org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:131)
    at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:138)
    at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:163)
    at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:756)
    ... 9 more
Caused by: org.apache.calcite.sql.parser.impl.ParseException: Encountered "from \"" at line 1, column 10.
Was expecting one of:
    <EOF> 
    "ORDER" ...
    "LIMIT" ...
    "OFFSET" ...
    "FETCH" ...
    "FROM" <IDENTIFIER> ...
    "FROM" <QUOTED_IDENTIFIER> ...
    "FROM" <BACK_QUOTED_IDENTIFIER> ...
    "FROM" <BRACKET_QUOTED_IDENTIFIER> ...
    "FROM" <UNICODE_QUOTED_IDENTIFIER> ...
    "FROM" "LATERAL" ...
    "FROM" "(" ...
    "FROM" "UNNEST" ...
    "FROM" "TABLE" ...
    "," ...
    "AS" ...
    <IDENTIFIER> ...
    <QUOTED_IDENTIFIER> ...
    <BACK_QUOTED_IDENTIFIER> ...
    <BRACKET_QUOTED_IDENTIFIER> ...
    <UNICODE_QUOTED_IDENTIFIER> ...
    "UNION" ...
    "INTERSECT" ...
    "EXCEPT" ...
    "MINUS" ...

    at org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:22776)
    at org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:22593)
    at org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtEof(SqlParserImpl.java:873)
    at org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtEof(SqlParserImpl.java:187)
    at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:131)
    ... 11 more
[info 2018/03/21 11:00:09.994 CDT <Distributed system shutdown hook> tid=0xc] VM is exiting - shutting down distributed system

已更新

我尝试了Christian在Gemfire 9.0和9.2.2中提供的旧代码和git示例代码,但出现了相同的异常

I have tried old code and git example code provided by Christian with Gemfire 9.0 and 9.2.2 but getting same exception

1)git中的示例

package com.khan.vaquar;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
 * Example of using Geode via JDBC.
 *
 * <p>Before using this example, you need to populate Geode, as follows:
 *
 * <blockquote><code>
 * git clone https://github.com/vlsi/calcite-test-dataset<br>
 * cd calcite-test-dataset<br>
 * mvn install
 * </code></blockquote>
 *
 * <p>This will create a virtual machine with Geode and the "bookshop" and "zips"
 * test data sets.
 */
public class RelationalJdbcExample {

  protected static final Logger LOGGER = LoggerFactory.getLogger(
      RelationalJdbcExample.class.getName());

  private RelationalJdbcExample() {
  }

  public static void main(String[] args) throws Exception {

    final String geodeModelJson =
        "inline:"
            + "{\n"
            + "  version: '1.0',\n"
            + "  schemas: [\n"
            + "     {\n"
            + "       type: 'custom',\n"
            + "       name: 'TEST',\n"
            + "       factory: 'org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory',\n"
            + "       operand: {\n"
            + "         locatorHost: 'localhost', \n"
            + "         locatorPort: '10334', \n"
            + "         regions: 'account,BookMaster,BookCustomer,BookInventory,BookOrder', \n"
            + "         pdxSerializablePackagePath: 'org.apache.calcite.adapter.geode.domain.*' \n"
            + "       }\n"
            + "     }\n"
            + "   ]\n"
            + "}";

    Class.forName("org.apache.calcite.jdbc.Driver");

    Properties info = new Properties();
    info.put("model", geodeModelJson);

    Connection connection = DriverManager.getConnection("jdbc:calcite:", info);

    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery(
        /*"SELECT \"b\".\"author\", \"b\".\"retailCost\", \"i\".\"quantityInStock\"\n"
            + "FROM \"TEST\".\"BookMaster\" AS \"b\" "
            + " INNER JOIN \"TEST\".\"BookInventory\" AS \"i\""
            + "  ON \"b\".\"itemNumber\" = \"i\".\"itemNumber\"\n "
            + "WHERE  \"b\".\"retailCost\" > 0"
        */    

            "SELECT \"b\".\"*\"  FROM \"account\" AS \"b\" "



            );

    final StringBuilder buf = new StringBuilder();
    while (resultSet.next()) {
      ResultSetMetaData metaData = resultSet.getMetaData();
      for (int i = 1; i <= metaData.getColumnCount(); i++) {
        buf.append(i > 1 ? "; " : "")
            .append(metaData.getColumnLabel(i)).append("=").append(resultSet.getObject(i));
      }
      LOGGER.info("Result entry: " + buf.toString());
      buf.setLength(0);
    }
    resultSet.close();
    statement.close();
    connection.close();
  }
}

2)git中的示例

package com.khan.vaquar;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
 * Example of using Geode via JDBC.
 */
public class SimpleJdbcExample {

  protected static final Logger LOGGER =
      LoggerFactory.getLogger(SimpleJdbcExample.class.getName());

  private SimpleJdbcExample() {
  }

  public static void main(String[] args) throws Exception {

    Properties info = new Properties();
    final String model = "inline:"
        + "{\n"
        + "  version: '1.0',\n"
        + "  schemas: [\n"
        + "     {\n"
        + "       type: 'custom',\n"
        + "       name: 'TEST',\n"
        + "       factory: 'org.apache.calcite.adapter.geode.simple"
        + ".GeodeSimpleSchemaFactory',\n"
        + "       operand: {\n"
        + "         locatorHost: 'localhost',\n"
        + "         locatorPort: '10334',\n"
        + "         regions: 'account,BookMaster',\n"
        + "         pdxSerializablePackagePath: 'org.apache.calcite.adapter.geode.domain.*'\n"
        + "       }\n"
        + "     }\n"
        + "  ]\n"
        + "}";
    info.put("model", model);

    Class.forName("org.apache.calcite.jdbc.Driver");

    Connection connection = DriverManager.getConnection("jdbc:calcite:", info);

    Statement statement = connection.createStatement();

    ResultSet resultSet = statement.executeQuery("SELECT * FROM \"account\"");

    final StringBuilder buf = new StringBuilder();

    while (resultSet.next()) {

      int columnCount = resultSet.getMetaData().getColumnCount();

      for (int i = 1; i <= columnCount; i++) {

        buf.append(i > 1 ? "; " : "")
            .append(resultSet.getMetaData().getColumnLabel(i))
            .append("=")
            .append(resultSet.getObject(i));
      }

      LOGGER.info("Entry: " + buf.toString());

      buf.setLength(0);
    }

    resultSet.close();
    statement.close();
    connection.close();
  }
}

推荐答案

我对代码进行了以下更改,以使用apache方解石连接Gemfire 9.6.

I have made following changes into my code to connect Gemfire 9.6 using apache calcite.

1)Geode或Gemfire没有架构概念,但是在Apache方解石中,我们必须对其进行定义,例如

1) Geode or Gemfire has no concepts of schema however in apache calcite we have to define it,example

final String geodeModelJson =
        "inline:"
            + "{\n"
            + "  version: '1.0',\n"
            + "  schemas: [\n"
            + "     {\n"
            + "       type: 'custom',\n"
            + "       name: 'TEST',\n"
            + "       factory: 'org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory',\n"
            + "       operand: {\n"
            + "         locatorHost: 'localhost', \n"
            + "         locatorPort: '10334', \n"
            + "         regions: 'test1', \n"
            + "         pdxSerializablePackagePath: 'org.apache.calcite.adapter.geode.domain.*' \n"
            + "       }\n"
            + "     }\n"
            + "   ]\n"
            + "}";

在这里您可以看到架构名称= TEST,这是连接gemfire所必需的,否则将报错,找不到对象.

Here you can see schema name =TEST , this is mandatory to connect gemfire else will get error no object found.

然后您必须在sql中使用

Then you have to use in sql

   ResultSet resultSet = statement.executeQuery("select * from \"TEST\".\"test1\"");

2)您需要在"中定义您的区域名称,否则它将转换为大写字母,gemfire区域名称区分大小写,因此account,ACCOUNT,Account是gemfire中的三个不同区域

2) You need to define your region name in "" else it will convert to uppercase and gemfire region name is case sensetive so account ,ACCOUNT,Account are three diffrent region in gemfire

\"TEST\".\"test1\"

在这里找到完整的Java代码:

Here you find full Java code :

Jar文件:

package com.khan.vaquar;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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


public class RelationalJdbcExample {

  protected static final Logger LOGGER = LoggerFactory.getLogger(
      RelationalJdbcExample.class.getName());

  private RelationalJdbcExample() {
  }

  public static void main(String[] args) throws Exception {

    final String geodeModelJson =
        "inline:"
            + "{\n"
            + "  version: '1.0',\n"
            + "  schemas: [\n"
            + "     {\n"
            + "       type: 'custom',\n"
            + "       name: 'TEST',\n"
            + "       factory: 'org.apache.calcite.adapter.geode.rel.GeodeSchemaFactory',\n"
            + "       operand: {\n"
            + "         locatorHost: 'localhost', \n"
            + "         locatorPort: '10334', \n"
            + "         regions: 'test1', \n"
            + "         pdxSerializablePackagePath: 'org.apache.calcite.adapter.geode.domain.*' \n"
            + "       }\n"
            + "     }\n"
            + "   ]\n"
            + "}";

    Class.forName("org.apache.calcite.jdbc.Driver");

    Properties info = new Properties();
    info.put("model", geodeModelJson);

    Connection connection = DriverManager.getConnection("jdbc:calcite:", info);

    Statement statement = connection.createStatement();


   ResultSet resultSet = statement.executeQuery("select * from \"TEST\".\"test1\"");



    final StringBuilder buf = new StringBuilder();
    while (resultSet.next()) {
      ResultSetMetaData metaData = resultSet.getMetaData();
      System.out.println("metaData="+metaData.getColumnCount());
      System.out.println("metaData1="+metaData.getColumnName(1));
      System.out.println("metaData2="+metaData.getColumnName(2));


      //
      for (int i = 1; i <= metaData.getColumnCount(); i++) {
        buf.append(i > 1 ? "; " : "")
            .append(metaData.getColumnLabel(i)).append("=").append(resultSet.getObject(i));
      }
      LOGGER.info("Result entry: " + buf.toString());
      buf.setLength(0);
    }
    resultSet.close();
    statement.close();
    connection.close();
  }
}

Gemfire:

start locator --name=locator1 --port=10334 --initial-heap=256m --max-heap=256m --log-level=DEBUG

start server --name=server1 --log-level=DEBUG

 create region --name=test1 --type=PARTITION --redundant-copies=1  --total- 
num-buckets=1

query --query='select count(*)  from /test1'


stop server --name=server1
stop locator --name=locator1    

这篇关于Apache Calcite Geode JDBC Adapte无法与Gemfire 8.x和9.X一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 13:20