Search in sources :

Example 1 with ModifiableTable

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

the class EnumerableTableModifyRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final LogicalTableModify modify = (LogicalTableModify) rel;
    final ModifiableTable modifiableTable = modify.getTable().unwrap(ModifiableTable.class);
    if (modifiableTable == null) {
        return null;
    }
    final RelTraitSet traitSet = modify.getTraitSet().replace(EnumerableConvention.INSTANCE);
    return new EnumerableTableModify(modify.getCluster(), traitSet, modify.getTable(), modify.getCatalogReader(), convert(modify.getInput(), traitSet), modify.getOperation(), modify.getUpdateColumnList(), modify.getSourceExpressionList(), modify.isFlattened());
}
Also used : ModifiableTable(org.apache.calcite.schema.ModifiableTable) LogicalTableModify(org.apache.calcite.rel.logical.LogicalTableModify) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 2 with ModifiableTable

use of org.apache.calcite.schema.ModifiableTable 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

ModifiableTable (org.apache.calcite.schema.ModifiableTable)2 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelNode (org.apache.calcite.rel.RelNode)1 LogicalTableModify (org.apache.calcite.rel.logical.LogicalTableModify)1 RelDataType (org.apache.calcite.rel.type.RelDataType)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