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

Compile-time evaluation of SPLIT function returns incorrect result

    XMLWordPrintableJSON

Details

    Description

      The compile-time evaluation of SPLIT functions produces wrong results. Here is an example test for RelOptRulesTest:

      @Test public void testSplit2() {
          final String query = "select split('1|2|3', '|')";
          sql(query)
              .withFactory(
                  t -> t.withOperatorTable(opTab ->
                      SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
                          SqlLibrary.BIG_QUERY))) // needed for SPLIT function
              .withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
              .check();
        }
      

      The result is expected to be an ARRAY containing strings '1', '2', '3', but the result is:

      LogicalProject(EXPR$0=[ARRAY('1    ', '2    ', '3    ')])
        LogicalValues(tuples=[[{ 0 }]])
      

      This probably happens because the type inference rule for the SPLIT operator is (SqlLibraryOperators.java):

       @LibraryOperator(libraries = {BIG_QUERY})
        public static final SqlFunction SPLIT =
            SqlBasicFunction.create("SPLIT",
                ReturnTypes.ARG0
                    .andThen(SqlLibraryOperators::deriveTypeSplit)
                    .andThen(SqlTypeTransforms.TO_ARRAY),
                ...
      

      Thus, when ARG0 is CHAR(4) the return type is also inferred to be CHAR(4).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: