Search in sources :

Example 1 with ModifiableView

use of org.apache.calcite.schema.ModifiableView in project calcite by apache.

the class SqlToRelConverter method createModify.

/**
 * Creates a relational expression to modify a table or modifiable view.
 */
private RelNode createModify(RelOptTable targetTable, RelNode source) {
    final ModifiableTable modifiableTable = targetTable.unwrap(ModifiableTable.class);
    if (modifiableTable != null && modifiableTable == targetTable.unwrap(Table.class)) {
        return modifiableTable.toModificationRel(cluster, targetTable, catalogReader, source, LogicalTableModify.Operation.INSERT, null, null, false);
    }
    final ModifiableView modifiableView = targetTable.unwrap(ModifiableView.class);
    if (modifiableView != null) {
        final Table delegateTable = modifiableView.getTable();
        final RelDataType delegateRowType = delegateTable.getRowType(typeFactory);
        final RelOptTable delegateRelOptTable = RelOptTableImpl.create(null, delegateRowType, delegateTable, modifiableView.getTablePath());
        final RelNode newSource = createSource(targetTable, source, modifiableView, delegateRowType);
        return createModify(delegateRelOptTable, newSource);
    }
    return LogicalTableModify.create(targetTable, catalogReader, source, LogicalTableModify.Operation.INSERT, null, null, false);
}
Also used : Table(org.apache.calcite.schema.Table) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) TranslatableTable(org.apache.calcite.schema.TranslatableTable) ModifiableTable(org.apache.calcite.schema.ModifiableTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) RelNode(org.apache.calcite.rel.RelNode) ModifiableTable(org.apache.calcite.schema.ModifiableTable) RelDataType(org.apache.calcite.rel.type.RelDataType) RelOptTable(org.apache.calcite.plan.RelOptTable) ModifiableView(org.apache.calcite.schema.ModifiableView)

Aggregations

RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelNode (org.apache.calcite.rel.RelNode)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 ModifiableTable (org.apache.calcite.schema.ModifiableTable)1 ModifiableView (org.apache.calcite.schema.ModifiableView)1 Table (org.apache.calcite.schema.Table)1 TranslatableTable (org.apache.calcite.schema.TranslatableTable)1 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)1 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)1 SqlValidatorTable (org.apache.calcite.sql.validate.SqlValidatorTable)1