You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Danny Chan (Jira)" <ji...@apache.org> on 2019/08/28 11:28:00 UTC
[jira] [Commented] (CALCITE-3304) SqlValidatorException when use
calcite view
[ https://issues.apache.org/jira/browse/CALCITE-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16917694#comment-16917694 ]
Danny Chan commented on CALCITE-3304:
-------------------------------------
This is because you config the FrameworkConfig to match identifier case-sensitively. To match the id correctly, either to config it be case-insensitive or add quotes character to the identifier.
> 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}Problem 1:{color}*
> *{color:#de350b}When I use calcite view (as in the blow, v_emp is a view ), it occurs such problem, why ?(The test SQL is{color}*
> ”select empid from v_emp where v_emp.empid in(select empid from emp where empid=1)”
> *{color:#de350b}){color}*
> !image-2019-08-28-19-17-40-352.png!
> -------------------------------------------------------
> My Config is blow, since I have set *CaseSensitive is false.*
> final FrameworkConfig fromworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().{color:#de350b}*setCaseSensitive(false)*.{color}build()).defaultSchema(rootSchema).traitDefs(ConventionTraitDef.INSTANCE, RelDistributionTraitDef.INSTANCE).build();
>
>
> *{color:#de350b}Problem 2:{color}*
> *{color:#de350b}when I use view, how I can get RelDataType? Thanks a lot.{color}*
>
> 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)