Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1772

Add a hook to allow RelNode expressions to be executed by JDBC driver

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.13.0
    • Component/s: None
    • Labels:
      None

      Description

      Add a hook to allow RelNode expressions to be executed by JDBC driver in the same way that SQL would.

      If you set Hook.STRING_TO_QUERY you can provide a function that creates a CalcitePrepare.Query object; this can wrap a String (SQL query), RelNode tree or Queryable.

      In tests, you can call convenience method AssertQuery.withRel, whose implementation sets the hook. For example,

          sql("?")
              .withRel(new Function<RelBuilder, RelNode>() {
                public RelNode apply(RelBuilder b) {
                  // select count(*) as c
                  // from foodmart.foodmart
                  // where product_id < cast(10 as varchar)
                  return b.scan("foodmart", "foodmart")
                      .filter(
                          b.call(SqlStdOperatorTable.LESS_THAN,
                              b.field("product_id"),
                              b.getRexBuilder().makeCall(
                                  b.getTypeFactory().createSqlType(SqlTypeName.INTEGER),
                                  SqlStdOperatorTable.CAST,
                                  ImmutableList.<RexNode>of(b.literal("10")))))
                      .aggregate(b.groupKey(), b.countStar("c"))
                      .build();
                }
              })
          .returns("c=45");
      

        Issue Links

          Activity

          Show
          julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/9c10c3da .
          Hide
          bslim slim bouguerra added a comment -

          Julian Hyde i am not sure if i getting this right please help me,
          So i am trying to run this dummy test below

          @Test public void testPushNumericCastOverLiteral() {
              sql("?")
                  .withRel(new Function<RelBuilder, RelNode>() {
                    public RelNode apply(RelBuilder b) {
                      // select count(*) as c
                      // from foodmart.foodmart
                      // where product_id = 'id'
                      return b.scan("foodmart", "foodmart")
                          .filter(b.call(SqlStdOperatorTable.EQUALS, b.field("product_id"), b.literal("id")))
                          .aggregate(b.groupKey(), b.countStar("c"))
                          .build();
                    }
                  })
                  .queryContains(druidChecker("'queryType':'timeseries'"));
            }
           
          

          The issue when i run this none of the druid rules is triggered and the execution ends up with a select * from druid_backed_table then do the rest by calcite. I am not sure why the re-writing of the query to timeserises is not happening.
          Am i missing something ?

          Show
          bslim slim bouguerra added a comment - Julian Hyde i am not sure if i getting this right please help me, So i am trying to run this dummy test below @Test public void testPushNumericCastOverLiteral() { sql( "?" ) .withRel( new Function<RelBuilder, RelNode>() { public RelNode apply(RelBuilder b) { // select count(*) as c // from foodmart.foodmart // where product_id = 'id' return b.scan( "foodmart" , "foodmart" ) .filter(b.call(SqlStdOperatorTable.EQUALS, b.field( "product_id" ), b.literal( "id" ))) .aggregate(b.groupKey(), b.countStar( "c" )) .build(); } }) .queryContains(druidChecker( "'queryType':'timeseries'" )); } The issue when i run this none of the druid rules is triggered and the execution ends up with a select * from druid_backed_table then do the rest by calcite. I am not sure why the re-writing of the query to timeserises is not happening. Am i missing something ?
          Hide
          julianhyde Julian Hyde added a comment -

          I'm looking into this... let's continue discussion on CALCITE-1769 since we're working on the test case for that issue.

          Show
          julianhyde Julian Hyde added a comment - I'm looking into this... let's continue discussion on CALCITE-1769 since we're working on the test case for that issue.
          Hide
          jcamachorodriguez Jesus Camacho Rodriguez added a comment -

          Resolved in release 1.13.0 (2017-06-26).

          Show
          jcamachorodriguez Jesus Camacho Rodriguez added a comment - Resolved in release 1.13.0 (2017-06-26).

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              julianhyde Julian Hyde
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development