use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable in project calcite by apache.
the class MockCatalogReader method init2.
/**
* Adds some extra tables to the mock catalog. These increase the time and
* complexity of initializing the catalog (because they contain views whose
* SQL needs to be parsed) and so are not used for all tests.
*/
public MockCatalogReader init2() {
MockSchema salesSchema = new MockSchema("SALES");
// Same as "EMP_20" except it uses ModifiableViewTable which populates
// constrained columns with default values on INSERT and has a single constraint on DEPTNO.
List<String> empModifiableViewNames = ImmutableList.of(salesSchema.getCatalogName(), salesSchema.name, "EMP_MODIFIABLEVIEW");
TableMacro empModifiableViewMacro = MockModifiableViewRelOptTable.viewMacro(rootSchema, "select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, SLACKER from EMPDEFAULTS" + " where DEPTNO = 20", empModifiableViewNames.subList(0, 2), ImmutableList.of(empModifiableViewNames.get(2)), true);
TranslatableTable empModifiableView = empModifiableViewMacro.apply(ImmutableList.of());
MockModifiableViewRelOptTable mockEmpViewTable = MockModifiableViewRelOptTable.create((MockModifiableViewRelOptTable.MockModifiableViewTable) empModifiableView, this, empModifiableViewNames.get(0), empModifiableViewNames.get(1), empModifiableViewNames.get(2), false, 20, null);
registerTable(mockEmpViewTable);
// Same as "EMP_MODIFIABLEVIEW" except that all columns are in the view, columns are reordered,
// and there is an `extra` extended column.
List<String> empModifiableViewNames2 = ImmutableList.of(salesSchema.getCatalogName(), salesSchema.name, "EMP_MODIFIABLEVIEW2");
TableMacro empModifiableViewMacro2 = MockModifiableViewRelOptTable.viewMacro(rootSchema, "select ENAME, EMPNO, JOB, DEPTNO, SLACKER, SAL, EXTRA, HIREDATE, MGR, COMM" + " from EMPDEFAULTS extend (EXTRA boolean)" + " where DEPTNO = 20", empModifiableViewNames2.subList(0, 2), ImmutableList.of(empModifiableViewNames.get(2)), true);
TranslatableTable empModifiableView2 = empModifiableViewMacro2.apply(ImmutableList.of());
MockModifiableViewRelOptTable mockEmpViewTable2 = MockModifiableViewRelOptTable.create((MockModifiableViewRelOptTable.MockModifiableViewTable) empModifiableView2, this, empModifiableViewNames2.get(0), empModifiableViewNames2.get(1), empModifiableViewNames2.get(2), false, 20, null);
registerTable(mockEmpViewTable2);
// Same as "EMP_MODIFIABLEVIEW" except that comm is not in the view.
List<String> empModifiableViewNames3 = ImmutableList.of(salesSchema.getCatalogName(), salesSchema.name, "EMP_MODIFIABLEVIEW3");
TableMacro empModifiableViewMacro3 = MockModifiableViewRelOptTable.viewMacro(rootSchema, "select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, SLACKER from EMPDEFAULTS" + " where DEPTNO = 20", empModifiableViewNames3.subList(0, 2), ImmutableList.of(empModifiableViewNames3.get(2)), true);
TranslatableTable empModifiableView3 = empModifiableViewMacro3.apply(ImmutableList.of());
MockModifiableViewRelOptTable mockEmpViewTable3 = MockModifiableViewRelOptTable.create((MockModifiableViewRelOptTable.MockModifiableViewTable) empModifiableView3, this, empModifiableViewNames3.get(0), empModifiableViewNames3.get(1), empModifiableViewNames3.get(2), false, 20, null);
registerTable(mockEmpViewTable3);
MockSchema structTypeSchema = new MockSchema("STRUCT");
registerSchema(structTypeSchema);
final Fixture f = new Fixture();
final List<CompoundNameColumn> columnsExtended = Arrays.asList(new CompoundNameColumn("", "K0", f.varchar20TypeNull), new CompoundNameColumn("", "C1", f.varchar20TypeNull), new CompoundNameColumn("F0", "C0", f.intType), new CompoundNameColumn("F1", "C1", f.intTypeNull));
final List<CompoundNameColumn> extendedColumns = new ArrayList<CompoundNameColumn>(columnsExtended);
extendedColumns.add(new CompoundNameColumn("F2", "C2", f.varchar20Type));
final CompoundNameColumnResolver structExtendedTableResolver = new CompoundNameColumnResolver(extendedColumns, "F0");
final MockTable structExtendedTypeTable = MockTable.create(this, structTypeSchema, "T_EXTEND", false, 100, structExtendedTableResolver);
for (CompoundNameColumn column : columnsExtended) {
structExtendedTypeTable.addColumn(column.getName(), column.type);
}
registerTable(structExtendedTypeTable);
return this;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable in project calcite by apache.
the class SqlCreateView method execute.
public void execute(CalcitePrepare.Context context) {
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
final SchemaPlus schemaPlus = pair.left.plus();
for (Function function : schemaPlus.getFunctions(pair.right)) {
if (function.getParameters().isEmpty()) {
if (!getReplace()) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.viewExists(pair.right));
}
pair.left.removeFunction(pair.right);
}
}
final SqlNode q = SqlDdlNodes.renameColumns(columnList, query);
final String sql = q.toSqlString(CalciteSqlDialect.DEFAULT).getSql();
final ViewTableMacro viewTableMacro = ViewTable.viewMacro(schemaPlus, sql, pair.left.path(null), context.getObjectPath(), false);
final TranslatableTable x = viewTableMacro.apply(ImmutableList.of());
Util.discard(x);
schemaPlus.add(pair.right, viewTableMacro);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable in project calcite by apache.
the class SqlToRelConverter method convertCollectionTable.
protected void convertCollectionTable(Blackboard bb, SqlCall call) {
final SqlOperator operator = call.getOperator();
if (operator == SqlStdOperatorTable.TABLESAMPLE) {
final String sampleName = SqlLiteral.unchain(call.operand(0)).getValueAs(String.class);
datasetStack.push(sampleName);
SqlCall cursorCall = call.operand(1);
SqlNode query = cursorCall.operand(0);
RelNode converted = convertQuery(query, false, false).rel;
bb.setRoot(converted, false);
datasetStack.pop();
return;
}
replaceSubQueries(bb, call, RelOptUtil.Logic.TRUE_FALSE_UNKNOWN);
// Expand table macro if possible. It's more efficient than
// LogicalTableFunctionScan.
final SqlCallBinding callBinding = new SqlCallBinding(bb.scope.getValidator(), bb.scope, call);
if (operator instanceof SqlUserDefinedTableMacro) {
final SqlUserDefinedTableMacro udf = (SqlUserDefinedTableMacro) operator;
final TranslatableTable table = udf.getTable(typeFactory, callBinding.operands());
final RelDataType rowType = table.getRowType(typeFactory);
RelOptTable relOptTable = RelOptTableImpl.create(null, rowType, table, udf.getNameAsId().names);
RelNode converted = toRel(relOptTable);
bb.setRoot(converted, true);
return;
}
Type elementType;
if (operator instanceof SqlUserDefinedTableFunction) {
SqlUserDefinedTableFunction udtf = (SqlUserDefinedTableFunction) operator;
elementType = udtf.getElementType(typeFactory, callBinding.operands());
} else {
elementType = null;
}
RexNode rexCall = bb.convertExpression(call);
final List<RelNode> inputs = bb.retrieveCursors();
Set<RelColumnMapping> columnMappings = getColumnMappings(operator);
LogicalTableFunctionScan callRel = LogicalTableFunctionScan.create(cluster, inputs, rexCall, elementType, validator.getValidatedNodeType(call), columnMappings);
bb.setRoot(callRel, true);
afterTableFunction(bb, call, callRel);
}
Aggregations