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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.13.0
    • None
    • 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");
      

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              julianhyde Julian Hyde
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: