Java Code Examples for org.apache.calcite.plan.RelOptUtil#createCastRel()
The following examples show how to use
org.apache.calcite.plan.RelOptUtil#createCastRel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewTable.java From Bats with Apache License 2.0 | 6 votes |
private RelRoot expandView(RelOptTable.ToRelContext context, RelDataType rowType, String queryString) { try { final RelRoot root = context.expandView(rowType, queryString, schemaPath, viewPath); 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); } }
Example 2
Source File: DrillViewTable.java From Bats with Apache License 2.0 | 6 votes |
@Override public RelNode toRel(ToRelContext context, RelOptTable relOptTable) { ViewExpansionContext.ViewExpansionToken token = null; try { RelDataType rowType = relOptTable.getRowType(); RelNode rel; if (viewExpansionContext.isImpersonationEnabled()) { token = viewExpansionContext.reserveViewExpansionToken(viewOwner); rel = expandViewForImpersonatedUser(context, rowType, view.getWorkspaceSchemaPath(), token.getSchemaTree()); } else { rel = context.expandView(rowType, view.getSql(), view.getWorkspaceSchemaPath(), ImmutableList.<String>of()).rel; } // If the View's field list is not "*", create a cast. if (!view.isDynamic() && !view.hasStar()) { rel = RelOptUtil.createCastRel(rel, rowType, true); } return rel; } finally { if (token != null) { token.release(); } } }
Example 3
Source File: ViewTable.java From calcite with Apache License 2.0 | 6 votes |
private RelRoot expandView(RelOptTable.ToRelContext context, RelDataType rowType, String queryString) { try { final RelRoot root = context.expandView(rowType, queryString, schemaPath, viewPath); 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); } }
Example 4
Source File: QueryOperationCatalogViewTable.java From flink with Apache License 2.0 | 5 votes |
@Override public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) { FlinkRelBuilder relBuilder = FlinkRelBuilder.of(context.getCluster(), relOptTable); RelNode relNode = relBuilder.tableOperation(catalogView.getQueryOperation()).build(); return RelOptUtil.createCastRel(relNode, rowType.apply(relBuilder.getTypeFactory()), false); }
Example 5
Source File: QueryOperationCatalogViewTable.java From flink with Apache License 2.0 | 5 votes |
@Override public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) { FlinkRelBuilder relBuilder = FlinkRelBuilder.of(context.getCluster(), relOptTable); RelNode relNode = relBuilder.queryOperation(catalogView.getQueryOperation()).build(); return RelOptUtil.createCastRel(relNode, rowType.apply(relBuilder.getTypeFactory()), false); }
Example 6
Source File: QueryOperationCatalogViewTable.java From flink with Apache License 2.0 | 5 votes |
@Override public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) { FlinkRelBuilder relBuilder = FlinkRelBuilder.of(context.getCluster(), relOptTable.getRelOptSchema()); RelNode relNode = relBuilder.tableOperation(catalogView.getQueryOperation()).build(); return RelOptUtil.createCastRel(relNode, rowType.apply(relBuilder.getTypeFactory()), false); }
Example 7
Source File: SqlCatalogViewTable.java From flink with Apache License 2.0 | 5 votes |
@Override public RelNode convertToRel(ToRelContext context) { RelNode original = context .expandView(rowType, view.getExpandedQuery(), viewPath, names) .project(); return RelOptUtil.createCastRel(original, rowType, true); }
Example 8
Source File: RelBuilder.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates a projection that converts the current relational expression's * output to a desired row type. * * @param castRowType row type after cast * @param rename if true, use field names from castRowType; if false, * preserve field names from rel */ public RelBuilder convert(RelDataType castRowType, boolean rename) { final RelNode r = build(); final RelNode r2 = RelOptUtil.createCastRel(r, castRowType, rename, struct.projectFactory); push(r2); return this; }
Example 9
Source File: RelBuilder.java From Bats with Apache License 2.0 | 3 votes |
/** * Creates a projection that converts the current relational expression's * output to a desired row type. * * @param castRowType row type after cast * @param rename if true, use field names from castRowType; if false, * preserve field names from rel */ public RelBuilder convert(RelDataType castRowType, boolean rename) { final RelNode r = build(); final RelNode r2 = RelOptUtil.createCastRel(r, castRowType, rename, projectFactory); push(r2); return this; }