Search in sources :

Example 61 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class SqlValidatorImpl method validateUpdate.

public void validateUpdate(SqlUpdate call) {
    final SqlValidatorNamespace targetNamespace = getNamespace(call);
    validateNamespace(targetNamespace, unknownType);
    final RelOptTable relOptTable = SqlValidatorUtil.getRelOptTable(targetNamespace, catalogReader.unwrap(Prepare.CatalogReader.class), null, null);
    final SqlValidatorTable table = relOptTable == null ? targetNamespace.getTable() : relOptTable.unwrap(SqlValidatorTable.class);
    final RelDataType targetRowType = createTargetRowType(table, call.getTargetColumnList(), true);
    final SqlSelect select = call.getSourceSelect();
    validateSelect(select, targetRowType);
    final RelDataType sourceRowType = getNamespace(call).getRowType();
    checkTypeAssignment(sourceRowType, targetRowType, call);
    checkConstraint(table, call, targetRowType);
    validateAccess(call.getTargetTable(), table, SqlAccessEnum.UPDATE);
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) RelDataType(org.apache.calcite.rel.type.RelDataType) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 62 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class SqlValidatorImpl method validateSequenceValue.

public void validateSequenceValue(SqlValidatorScope scope, SqlIdentifier id) {
    // Resolve identifier as a table.
    final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl();
    scope.resolveTable(id.names, catalogReader.nameMatcher(), SqlValidatorScope.Path.EMPTY, resolved);
    if (resolved.count() != 1) {
        throw newValidationError(id, RESOURCE.tableNameNotFound(id.toString()));
    }
    // We've found a table. But is it a sequence?
    final SqlValidatorNamespace ns = resolved.only().namespace;
    if (ns instanceof TableNamespace) {
        final Table table = ((RelOptTable) ns.getTable()).unwrap(Table.class);
        switch(table.getJdbcTableType()) {
            case SEQUENCE:
            case TEMPORARY_SEQUENCE:
                return;
        }
    }
    throw newValidationError(id, RESOURCE.notASequence(id.toString()));
}
Also used : Table(org.apache.calcite.schema.Table) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 63 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class SqlValidatorUtil method getTargetField.

/**
 * Resolve a target column name in the target table.
 *
 * @return the target field or null if the name cannot be resolved
 * @param rowType the target row type
 * @param id      the target column identifier
 * @param table   the target table or null if it is not a RelOptTable instance
 */
public static RelDataTypeField getTargetField(RelDataType rowType, RelDataTypeFactory typeFactory, SqlIdentifier id, SqlValidatorCatalogReader catalogReader, RelOptTable table) {
    final Table t = table == null ? null : table.unwrap(Table.class);
    if (!(t instanceof CustomColumnResolvingTable)) {
        final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
        return nameMatcher.field(rowType, id.getSimple());
    }
    final List<Pair<RelDataTypeField, List<String>>> entries = ((CustomColumnResolvingTable) t).resolveColumn(rowType, typeFactory, id.names);
    switch(entries.size()) {
        case 1:
            if (!entries.get(0).getValue().isEmpty()) {
                return null;
            }
            return entries.get(0).getKey();
        default:
            return null;
    }
}
Also used : CustomColumnResolvingTable(org.apache.calcite.schema.CustomColumnResolvingTable) Table(org.apache.calcite.schema.Table) ExtensibleTable(org.apache.calcite.schema.ExtensibleTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) RelOptTable(org.apache.calcite.plan.RelOptTable) CustomColumnResolvingTable(org.apache.calcite.schema.CustomColumnResolvingTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Pair(org.apache.calcite.util.Pair)

Example 64 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class TableNamespace method extend.

/**
 * Creates a TableNamespace based on the same table as this one, but with
 * extended fields.
 *
 * <p>Extended fields are "hidden" or undeclared fields that may nevertheless
 * be present if you ask for them. Phoenix uses them, for instance, to access
 * rarely used fields in the underlying HBase table.
 */
public TableNamespace extend(SqlNodeList extendList) {
    final List<SqlNode> identifierList = Util.quotientList(extendList.getList(), 2, 0);
    SqlValidatorUtil.checkIdentifierListForDuplicates(identifierList, validator.getValidationErrorFunction());
    final ImmutableList.Builder<RelDataTypeField> builder = ImmutableList.builder();
    builder.addAll(this.extendedFields);
    builder.addAll(SqlValidatorUtil.getExtendedColumns(validator.getTypeFactory(), getTable(), extendList));
    final List<RelDataTypeField> extendedFields = builder.build();
    final Table schemaTable = table.unwrap(Table.class);
    if (schemaTable != null && table instanceof RelOptTable && (schemaTable instanceof ExtensibleTable || schemaTable instanceof ModifiableViewTable)) {
        checkExtendedColumnTypes(extendList);
        final RelOptTable relOptTable = ((RelOptTable) table).extend(extendedFields);
        final SqlValidatorTable validatorTable = relOptTable.unwrap(SqlValidatorTable.class);
        return new TableNamespace(validator, validatorTable, ImmutableList.<RelDataTypeField>of());
    }
    return new TableNamespace(validator, table, extendedFields);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Table(org.apache.calcite.schema.Table) ExtensibleTable(org.apache.calcite.schema.ExtensibleTable) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) RelOptTable(org.apache.calcite.plan.RelOptTable) ImmutableList(com.google.common.collect.ImmutableList) RelOptTable(org.apache.calcite.plan.RelOptTable) ExtensibleTable(org.apache.calcite.schema.ExtensibleTable) ModifiableViewTable(org.apache.calcite.schema.impl.ModifiableViewTable) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

RelOptTable (org.apache.calcite.plan.RelOptTable)63 RelDataType (org.apache.calcite.rel.type.RelDataType)20 RexNode (org.apache.calcite.rex.RexNode)18 RelNode (org.apache.calcite.rel.RelNode)17 Table (org.apache.calcite.schema.Table)15 ArrayList (java.util.ArrayList)14 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)12 RelTraitSet (org.apache.calcite.plan.RelTraitSet)10 SqlNode (org.apache.calcite.sql.SqlNode)10 RelOptCluster (org.apache.calcite.plan.RelOptCluster)9 ImmutableList (com.google.common.collect.ImmutableList)8 NlsString (org.apache.calcite.util.NlsString)8 List (java.util.List)6 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)6 SchemaPlus (org.apache.calcite.schema.SchemaPlus)6 RelOptSchema (org.apache.calcite.plan.RelOptSchema)5 Project (org.apache.calcite.rel.core.Project)5 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)5 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)5 Test (org.junit.Test)5