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

SqlValidatorException when use calcite view

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Bug
    • Affects Version/s: None
    • Fix Version/s: 1.21.0
    • Component/s: None
    • Labels:
      None

      Description

      v_emp:'s sql :  select * from emp where empid>10.

       

      Problem 1:

      When I use calcite view (as in the blow, v_emp is a view ), it occurs such problem, why ?(The test SQL is

      ”select empid from v_emp where v_emp.empid in(select empid from emp where empid=1)”

      -------------------------------------------------------

      My Config is blow, since I have set CaseSensitive is false.

      final FrameworkConfig fromworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setCaseSensitive(false).build()).defaultSchema(rootSchema).traitDefs(ConventionTraitDef.INSTANCE, RelDistributionTraitDef.INSTANCE).build();

       

       

      Problem 2:

      when I use view, how I can get RelDataType? Thanks a lot.

       

      public class MyViewTable extends AbstractTable implements TranslatableTable {

      private final String vName;
      private final String viewSql;

      public MyViewTable (String vName, String viewSql)

      { super(); this.vName = vName; this.viewSql = viewSql; }

      public String getVName()

      { return vName; }

      @Override
      public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable)

      { return expandView(context, relOptTable.getRowType(), viewSql).rel; }

      @Override
      public RelDataType getRowType(final RelDataTypeFactory typeFactory) {

                return ???
      }

      @Override
      public Schema.TableType getJdbcTableType()

      { return Schema.TableType.VIEW; }

      private RelRoot expandView(RelOptTable.ToRelContext context, RelDataType rowType, String queryString) {
      try {
      final RelRoot root = context.expandView(rowType, queryString, null, null);
      final RelNode rel = RelOptUtil.createCastRel(root.rel, rowType, true);
      // Expand any views
      final RelNode rel2 = rel.accept(new RelShuttleImpl() {
      @Override
      public RelNode visit(TableScan scan) {
      final RelOptTable table = scan.getTable();
      final TranslatableTable translatableTable = table.unwrap(TranslatableTable.class);
      if (translatableTable != null)

      { return translatableTable.toRel(context, table); }

      return super.visit(scan);
      }
      });
      return root.withRel(rel2);
      } catch (Exception e)

      { throw new RuntimeException("Error while parsing view definition: " + queryString, e); }

      }
      }

       

       

       

        Attachments

        1. image-2019-08-28-19-17-40-352.png
          103 kB
          Water Cut Off
        2. image-2019-08-28-19-16-22-659.png
          50 kB
          Water Cut Off
        3. image-2019-08-28-19-15-23-485.png
          46 kB
          Water Cut Off

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Water Cut Off Water Cut Off
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: