You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by xuedong luan <lu...@gmail.com> on 2016/08/18 12:34:12 UTC
Error on testing elasticsearch adapter
Dear all:
There is a SqlValidatorException when i am testing
the elasticsearch adapter.Can anybody help me? Here is my java code:
public class EsCalciteTest {
public static Logger logger = LoggerFactory.getLogger(EsCalciteTest.class);
public static void main(String[] args){
Properties properties = new Properties();
properties.setProperty("caseSensitive", "false");
PreparedStatement statement2 = null;
CalciteConnection calciteConnection = null;
try {
Connection conn =
DriverManager.getConnection("jdbc:calcite:", properties);
calciteConnection = conn.unwrap(CalciteConnection.class);
Schema schema = new
ElasticsearchSchemaFactory().create(calciteConnection.getRootSchema(),
"elasticsearch", getOperand());
calciteConnection.getRootSchema().add("elasticsearch",schema);
String sql = "select name from \"external\"";
statement2 = calciteConnection.prepareStatement(sql);
ResultSet set = statement2.executeQuery();
while(set.next()){
logger.info(set.getString(1));
}
}catch (SQLException e){
e.printStackTrace();
}finally {
if(statement2 != null){
try {
statement2.close();
}catch (SQLException e){
logger.error(e.getMessage());
}
}
if(calciteConnection != null){
try{
calciteConnection.close();
}catch (SQLException e){
logger.error(e.getMessage());
}
}
}
}
public static Map<String,Object> getOperand(){
String coordinates = "{'127.0.0.1':9300}";
String userConfig = "{'cluster.name': 'luan'}";
String index = "customer";
Map<String,Object> map = new HashMap<String,Object>();
map.put("coordinates",coordinates);
map.put("userConfig",userConfig);
map.put("index",index);
return map;
}
}
And exception:
016-08-18 20:21:42,202 DEBUG [main] org.elasticsearch.common.netty: using
gathering [true]
2016-08-18 20:21:42,250 DEBUG [main] org.elasticsearch.client.transport:
[Infant Terrible] node_sampler_interval[5s]
2016-08-18 20:21:42,286 DEBUG [main]
org.elasticsearch.netty.channel.socket.nio.SelectorUtil: Using select
timeout of 500
2016-08-18 20:21:42,286 DEBUG [main]
org.elasticsearch.netty.channel.socket.nio.SelectorUtil: Epoll-bug
workaround enabled = false
2016-08-18 20:21:42,317 DEBUG [main] org.elasticsearch.client.transport:
[Infant Terrible] adding address [{#transport#-1}{127.0.0.1}{127.0.0.1:9300
}]
2016-08-18 20:21:42,530 DEBUG [main] org.elasticsearch.transport.netty:
[Infant Terrible] connected to node [{#transport#-1}{127.0.0.1}{
127.0.0.1:9300}]
2016-08-18 20:21:42,788 DEBUG [main] org.elasticsearch.transport.netty:
[Infant Terrible] connected to node
[{Aralune}{HDpwBvvXS7Kp2kpe9yjO3g}{127.0.0.1}{127.0.0.1:9300}]
2016-08-18 20:21:42,824 DEBUG [elasticsearch[Infant
Terrible][transport_client_worker][T#8]{New I/O worker #8}]
org.elasticsearch.common.compress.lzf: using decoder[VanillaChunkDecoder]
2016-08-18 20:21:43,460 DEBUG [main] org.apache.calcite.sql.parser: Reduced
NAME
2016-08-18 20:21:43,463 DEBUG [main] org.apache.calcite.sql.parser: Reduced
SELECT `NAME`
FROM `external`
2016-08-18 20:21:43,798 ERROR [main]
org.apache.calcite.runtime.CalciteException:
org.apache.calcite.sql.validate.SqlValidatorException: Table 'external' not
found
2016-08-18 20:21:43,800 ERROR [main]
org.apache.calcite.runtime.CalciteException:
org.apache.calcite.runtime.CalciteContextException: From line 1, column 18
to line 1, column 27: Table 'external' not found
java.sql.SQLException: Error while preparing statement [select name from
"external"]
at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:204)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:185)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:86)
at
org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:163)
at com.vip.bigdata.EsCalciteTest.main(EsCalciteTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1,
column 18 to line 1, column 27: Table 'external' 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:422)
at
org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:405)
at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:800)
at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:785)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:3989)
at
org.apache.calcite.sql.validate.IdentifierNamespace.validateImpl(IdentifierNamespace.java:106)
at
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:86)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:864)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:845)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2775)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2760)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:2988)
at
org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
at
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:86)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:864)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:845)
at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:208)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:820)
at
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:536)
at
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:577)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:224)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:193)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:724)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:591)
at
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:561)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:215)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:196)
... 9 more
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Table
'external' 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:422)
at
org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:405)
at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:514)
... 34 more
Process finished with exit code 0
thks very much
Re: Error on testing elasticsearch adapter
Posted by Julian Hyde <jh...@apache.org>.
In getOperand, the userConfig and coordinates values should each be a LinkedHashMap, not a String. Also, I am concerned that you create the schema AFTER you create a connection.
Both problems might be solved if you create the connection using a model.json file similar to elasticsearch-zips-model.json[1].
Also, it shouldn’t be necessary, but try qualifying the table name:
> String sql = "select name from \”elasticsearch\”.\"external\"";
Julian
[1] https://github.com/apache/calcite/blob/HEAD/elasticsearch/src/test/resources/elasticsearch-zips-model.json <https://github.com/apache/calcite/blob/HEAD/elasticsearch/src/test/resources/elasticsearch-zips-model.json>
> On Aug 18, 2016, at 5:34 AM, xuedong luan <lu...@gmail.com> wrote:
>
> Dear all:
> There is a SqlValidatorException when i am testing
> the elasticsearch adapter.Can anybody help me? Here is my java code:
>
> public class EsCalciteTest {
>
> public static Logger logger = LoggerFactory.getLogger(EsCalciteTest.class);
>
> public static void main(String[] args){
> Properties properties = new Properties();
> properties.setProperty("caseSensitive", "false");
> PreparedStatement statement2 = null;
> CalciteConnection calciteConnection = null;
> try {
> Connection conn =
> DriverManager.getConnection("jdbc:calcite:", properties);
> calciteConnection = conn.unwrap(CalciteConnection.class);
> Schema schema = new
> ElasticsearchSchemaFactory().create(calciteConnection.getRootSchema(),
> "elasticsearch", getOperand());
> calciteConnection.getRootSchema().add("elasticsearch",schema);
> String sql = "select name from \"external\"";
> statement2 = calciteConnection.prepareStatement(sql);
> ResultSet set = statement2.executeQuery();
> while(set.next()){
> logger.info(set.getString(1));
> }
> }catch (SQLException e){
> e.printStackTrace();
> }finally {
> if(statement2 != null){
> try {
> statement2.close();
> }catch (SQLException e){
> logger.error(e.getMessage());
> }
>
> }
> if(calciteConnection != null){
> try{
> calciteConnection.close();
> }catch (SQLException e){
> logger.error(e.getMessage());
> }
> }
> }
> }
>
> public static Map<String,Object> getOperand(){
> String coordinates = "{'127.0.0.1':9300}";
> String userConfig = "{'cluster.name': 'luan'}";
> String index = "customer";
> Map<String,Object> map = new HashMap<String,Object>();
> map.put("coordinates",coordinates);
> map.put("userConfig",userConfig);
> map.put("index",index);
> return map;
> }
> }
>
> And exception:
>
> 016-08-18 20:21:42,202 DEBUG [main] org.elasticsearch.common.netty: using
> gathering [true]
> 2016-08-18 20:21:42,250 DEBUG [main] org.elasticsearch.client.transport:
> [Infant Terrible] node_sampler_interval[5s]
> 2016-08-18 20:21:42,286 DEBUG [main]
> org.elasticsearch.netty.channel.socket.nio.SelectorUtil: Using select
> timeout of 500
> 2016-08-18 20:21:42,286 DEBUG [main]
> org.elasticsearch.netty.channel.socket.nio.SelectorUtil: Epoll-bug
> workaround enabled = false
> 2016-08-18 20:21:42,317 DEBUG [main] org.elasticsearch.client.transport:
> [Infant Terrible] adding address [{#transport#-1}{127.0.0.1}{127.0.0.1:9300
> }]
> 2016-08-18 20:21:42,530 DEBUG [main] org.elasticsearch.transport.netty:
> [Infant Terrible] connected to node [{#transport#-1}{127.0.0.1}{
> 127.0.0.1:9300}]
> 2016-08-18 20:21:42,788 DEBUG [main] org.elasticsearch.transport.netty:
> [Infant Terrible] connected to node
> [{Aralune}{HDpwBvvXS7Kp2kpe9yjO3g}{127.0.0.1}{127.0.0.1:9300}]
> 2016-08-18 20:21:42,824 DEBUG [elasticsearch[Infant
> Terrible][transport_client_worker][T#8]{New I/O worker #8}]
> org.elasticsearch.common.compress.lzf: using decoder[VanillaChunkDecoder]
> 2016-08-18 20:21:43,460 DEBUG [main] org.apache.calcite.sql.parser: Reduced
> NAME
> 2016-08-18 20:21:43,463 DEBUG [main] org.apache.calcite.sql.parser: Reduced
> SELECT `NAME`
> FROM `external`
> 2016-08-18 20:21:43,798 ERROR [main]
> org.apache.calcite.runtime.CalciteException:
> org.apache.calcite.sql.validate.SqlValidatorException: Table 'external' not
> found
> 2016-08-18 20:21:43,800 ERROR [main]
> org.apache.calcite.runtime.CalciteException:
> org.apache.calcite.runtime.CalciteContextException: From line 1, column 18
> to line 1, column 27: Table 'external' not found
> java.sql.SQLException: Error while preparing statement [select name from
> "external"]
> at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
> at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:204)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:185)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:86)
> at
> org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:163)
> at com.vip.bigdata.EsCalciteTest.main(EsCalciteTest.java:34)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:497)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
> Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1,
> column 18 to line 1, column 27: Table 'external' 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:422)
> at
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:405)
> at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:800)
> at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:785)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:3989)
> at
> org.apache.calcite.sql.validate.IdentifierNamespace.validateImpl(IdentifierNamespace.java:106)
> at
> org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:86)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:864)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:845)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2775)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:2760)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:2988)
> at
> org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
> at
> org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:86)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:864)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:845)
> at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:208)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:820)
> at
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:536)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:577)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:224)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:193)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:724)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:591)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:561)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:215)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:196)
> ... 9 more
> Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Table
> 'external' 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:422)
> at
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:405)
> at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:514)
> ... 34 more
>
> Process finished with exit code 0
>
>
> thks very much