0

I want to perform a search operation on Elasticsearch using RelNode objects and not the traditional SQL query method.

I tried building RelNode objects by providing projections and filters but it didn't work saying no input fields found.

   SchemaPlus postschema = con.getRootSchema().getSubSchema("twitter2");

    FrameworkConfig postConfig = Frameworks.newConfigBuilder()
            .defaultSchema(postschema)
            .build();
    RelBuilder postBuilder = RelBuilder.create(postConfig);

   RelNode relSelect = postBuilder.scan("user").project(testBuilder.scan("user").field("name)).build();

I have used following Schema:

+ "{
"
                    + "  version: '1.0',
"
                    + "  defaultSchema: 'BASEJDBC',
"
                    + "  schemas: [
"
                    + "     {
"
                    + "       type: 'custom',
"
                    + "       name: 'twitter2',
"
                    + "       factory: '" + "org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory" + "',
"
                    + "       operand:  { 
"
                    + "         "coordinates": " + " "{'localhost': 9200}",
 "
                    + "         "userConfig": " + " "{'admin': 'admin'}",
 "
                    + "         "index":  "twitter2" 
"
                    + "       }
"
                    + "     },
"

I am able to fetch proper resultset using following RexNode objects in filter:

   final RexNode condition1 =
            rexbuilder.makeCall(SqlStdOperatorTable.EQUALS,
                            rexbuilder.makeCall(SqlStdOperatorTable.ITEM,rexbuilder.makeInputRef(relDataTypeFactory.createSqlType(SqlTypeName.ANY), 0),
                                    rexbuilder.makeLiteral("_id"))
                    ,
                    rexbuilder.makeLiteral("ss")
            );



 RelNode node = postBuilder.scan("user")
          .filter(condition1)
            //.project()
            .build();

Still I am unable to create projections RelNode objects. Is this the standard way to create filter RelNode objects???

Can you please provide details upon view and how to use it for query building??

Shlok
  • 1
  • 1
  • Elasticsearch schemas by default will have only one single column named `_MAP`. You'll need to provide a view to write queries using field names. Can you provide the schema definition you're using as well as the complete error message? – Michael Mior May 30 '19 at 18:55
  • I have tried something and it worked. Please review it and tell whether it is the standard practice or not as I am fairly new to Apache Calcite – Shlok Jun 01 '19 at 15:04

0 Answers0