You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Water Cut Off (Jira)" <ji...@apache.org> on 2019/08/28 11:24:00 UTC

[jira] [Updated] (CALCITE-3304) SqlValidatorException when use calcite view

     [ https://issues.apache.org/jira/browse/CALCITE-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Water Cut Off updated CALCITE-3304:
-----------------------------------
    Description: 
*{color:#00875a}v_emp:'s sql :  select * from emp where empid>10.{color}*

 

{color:#de350b}When I use calcite view (as in the blow, v_emp is a view ), it occurs such problem, why ?{color}

!image-2019-08-28-19-17-40-352.png!

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

My Config is blow:

final FrameworkConfig fromworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().{color:#de350b}*setCaseSensitive(false)*.{color}build()).defaultSchema(rootSchema).traitDefs(ConventionTraitDef.INSTANCE, RelDistributionTraitDef.INSTANCE).build();

 

Can someone explain why this happens, and 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
 {color:#de350b}public RelDataType getRowType(final RelDataTypeFactory typeFactory) {{color}

         {color:#de350b} return *???*{color}
{color:#de350b} }{color}


 @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);
 }
 }
}

 

 

 

  was:
*{color:#00875a}v_emp:'s sql :  select * from emp where empid>10.{color}*

 

{color:#de350b}When I use calcite view (as in the blow, v_emp is a view ), it occurs such problem:{color}

!image-2019-08-28-19-17-40-352.png!

!image-2019-08-28-19-16-22-659.png!


> SqlValidatorException when use calcite view
> -------------------------------------------
>
>                 Key: CALCITE-3304
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3304
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Water Cut Off
>            Priority: Major
>         Attachments: image-2019-08-28-19-15-23-485.png, image-2019-08-28-19-16-22-659.png, image-2019-08-28-19-17-40-352.png
>
>
> *{color:#00875a}v_emp:'s sql :  select * from emp where empid>10.{color}*
>  
> {color:#de350b}When I use calcite view (as in the blow, v_emp is a view ), it occurs such problem, why ?{color}
> !image-2019-08-28-19-17-40-352.png!
> -------------------------------------------------------
> My Config is blow:
> final FrameworkConfig fromworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().{color:#de350b}*setCaseSensitive(false)*.{color}build()).defaultSchema(rootSchema).traitDefs(ConventionTraitDef.INSTANCE, RelDistributionTraitDef.INSTANCE).build();
>  
> Can someone explain why this happens, and 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
>  {color:#de350b}public RelDataType getRowType(final RelDataTypeFactory typeFactory) {{color}
>          {color:#de350b} return *???*{color}
> {color:#de350b} }{color}
>  @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);
>  }
>  }
> }
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.2#803003)