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

Prefix minus operator failed between BETWEEN and AND

    XMLWordPrintableJSON

    Details

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

      Description

      We can reproduce it like this

      public static void main(String[] args) {
      		try {
      			SchemaPlus rootSchema = Frameworks.createRootSchema(true);
      
      			rootSchema.add("TABLE_RESULT", new AbstractTable() {
      				public RelDataType getRowType(final RelDataTypeFactory typeFactory) {
      					RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
      
      					RelDataType t1 = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true);
      					RelDataType t2 = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR), true);
      					RelDataType t3 = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true);
      
      					builder.add("ID", t1);
      					builder.add("NAME", t2);
      					builder.add("SCORE", t3);;
      					return builder.build();
      				}
      			});
      			final FrameworkConfig config = Frameworks.newConfigBuilder()
      					.parserConfig(SqlParser.Config.DEFAULT)
      					.defaultSchema(rootSchema)
      					.build();
      			Planner planner = Frameworks.getPlanner(config);
      
      			String sql = "select id, score between - score * 5 and 100 from table_result";
      
      
      			SqlNode parse = planner.parse(sql);
      			SqlNode validate = planner.validate(parse);
      
      			RelRoot root = planner.rel(validate);
      
      		} catch (Exception e) {
      			e.printStackTrace();
      		}
      	}
      

      the above code will cause the following problem:

      org.apache.calcite.sql.parser.SqlParseException: Encountered "- score" at line 1, column 26.
      Was expecting one of:
          "SYMMETRIC" ...
          "ASYMMETRIC" ...
          "+" ...
          "-" ...
          "-" <UNSIGNED_INTEGER_LITERAL> ...
          "-" <DECIMAL_NUMERIC_LITERAL> ...
          "-" <APPROX_NUMERIC_LITERAL> ...
          <UNSIGNED_INTEGER_LITERAL> ...
          <DECIMAL_NUMERIC_LITERAL> ...
          <APPROX_NUMERIC_LITERAL> ...
          <BINARY_STRING_LITERAL> ...
          <PREFIXED_STRING_LITERAL> ...
          <QUOTED_STRING> ...
          <UNICODE_STRING_LITERAL> ...
          "TRUE" ...
          "FALSE" ...
          "UNKNOWN" ...
          "NULL" ...
          <LBRACE_D> ...
          <LBRACE_T> ...
          <LBRACE_TS> ...
          "DATE" ...
          "TIME" ...
          "TIMESTAMP" ...
          "INTERVAL" ...
          "?" ...
          "CAST" ...
          "EXTRACT" ...
          "POSITION" ...
          "CONVERT" ...
          "TRANSLATE" ...
          "OVERLAY" ...
          "FLOOR" ...
          "CEIL" ...
          "CEILING" ...
          "SUBSTRING" ...
          "TRIM" ...
          "CLASSIFIER" ...
          "MATCH_NUMBER" ...
          "RUNNING" ...
          "PREV" ...
          "NEXT" ...
          <LBRACE_FN> ...
          "MULTISET" ...
          "ARRAY" ...
          "PERIOD" ...
          "SPECIFIC" ...
          <IDENTIFIER> ...
          <QUOTED_IDENTIFIER> ...
          <BACK_QUOTED_IDENTIFIER> ...
          <BRACKET_QUOTED_IDENTIFIER> ...
          <UNICODE_QUOTED_IDENTIFIER> ...
          "ABS" ...
          "AVG" ...
          "CARDINALITY" ...
          "CHAR_LENGTH" ...
          "CHARACTER_LENGTH" ...
          "COALESCE" ...
          "COLLECT" ...
          "COVAR_POP" ...
          "COVAR_SAMP" ...
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: