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);
}
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()));
}
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;
}
}
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);
}
Aggregations