use of org.apache.calcite.sql.validate.SqlValidatorTable in project calcite by apache.
the class SqlToRelConverter method convertIdentifier.
private void convertIdentifier(Blackboard bb, SqlIdentifier id, SqlNodeList extendedColumns) {
final SqlValidatorNamespace fromNamespace = validator.getNamespace(id).resolve();
if (fromNamespace.getNode() != null) {
convertFrom(bb, fromNamespace.getNode());
return;
}
final String datasetName = datasetStack.isEmpty() ? null : datasetStack.peek();
final boolean[] usedDataset = { false };
RelOptTable table = SqlValidatorUtil.getRelOptTable(fromNamespace, catalogReader, datasetName, usedDataset);
if (extendedColumns != null && extendedColumns.size() > 0) {
assert table != null;
final SqlValidatorTable validatorTable = table.unwrap(SqlValidatorTable.class);
final List<RelDataTypeField> extendedFields = SqlValidatorUtil.getExtendedColumns(validator.getTypeFactory(), validatorTable, extendedColumns);
table = table.extend(extendedFields);
}
final RelNode tableRel;
if (config.isConvertTableAccess()) {
tableRel = toRel(table);
} else {
tableRel = LogicalTableScan.create(cluster, table);
}
bb.setRoot(tableRel, true);
if (usedDataset[0]) {
bb.setDataset(datasetName);
}
}
use of org.apache.calcite.sql.validate.SqlValidatorTable in project druid by druid-io.
the class SqlResourceCollectorShuttle method visit.
@Override
public SqlNode visit(SqlIdentifier id) {
// raw tables and views and such will have a IdentifierNamespace
// since we are scoped to identifiers here, we should only pick up these
SqlValidatorNamespace namespace = validator.getNamespace(id);
if (namespace != null && namespace.isWrapperFor(IdentifierNamespace.class)) {
SqlValidatorTable validatorTable = namespace.getTable();
// this should not probably be null if the namespace was not null,
if (validatorTable != null) {
List<String> qualifiedNameParts = validatorTable.getQualifiedName();
// 'schema'.'identifier'
if (qualifiedNameParts.size() == 2) {
final String schema = qualifiedNameParts.get(0);
final String resourceName = qualifiedNameParts.get(1);
final String resourceType = plannerContext.getSchemaResourceType(schema, resourceName);
if (resourceType != null) {
resourceActions.add(new ResourceAction(new Resource(resourceName, resourceType), Action.READ));
}
} else if (qualifiedNameParts.size() > 2) {
// Don't expect to see more than 2 names (catalog?).
throw new ISE("Cannot analyze table idetifier %s", qualifiedNameParts);
}
}
}
return super.visit(id);
}
use of org.apache.calcite.sql.validate.SqlValidatorTable in project hazelcast by hazelcast.
the class SqlExtendedInsert method validate.
@Override
public void validate(SqlValidator validator, SqlValidatorScope scope) {
SqlValidatorTable table0 = validator.getCatalogReader().getTable(tableNames());
if (table0 == null) {
super.validate(validator, scope);
// should have failed with "Object not found"
assert false;
}
HazelcastTable table = table0.unwrap(HazelcastTable.class);
if (getTargetColumnList() == null) {
RelDataType rowType = table.getRowType(validator.getTypeFactory());
List<SqlNode> columnListWithoutHidden = new ArrayList<>();
for (RelDataTypeField f : rowType.getFieldList()) {
if (!table.isHidden(f.getName())) {
columnListWithoutHidden.add(new SqlIdentifier(f.getName(), SqlParserPos.ZERO));
}
}
overrideColumnList = new SqlNodeList(columnListWithoutHidden, SqlParserPos.ZERO);
}
super.validate(validator, scope);
Map<String, TableField> fieldsMap = table.getTarget().getFields().stream().collect(Collectors.toMap(TableField::getName, f -> f));
for (SqlNode fieldNode : getTargetColumnList()) {
TableField field = fieldsMap.get(((SqlIdentifier) fieldNode).getSimple());
if (field instanceof MapTableField) {
QueryPath path = ((MapTableField) field).getPath();
if (path.getPath() == null && field.getType().getTypeFamily() == QueryDataTypeFamily.OBJECT) {
throw validator.newValidationError(fieldNode, RESOURCE.insertToTopLevelObject());
}
}
}
}
use of org.apache.calcite.sql.validate.SqlValidatorTable in project hazelcast by hazelcast.
the class HazelcastSqlValidator method containsStreamingSource.
/**
* Goes over all the referenced tables in the given {@link SqlNode}
* and returns true if any of them uses a streaming connector.
*/
public boolean containsStreamingSource(SqlNode node) {
class FindStreamingTablesVisitor extends SqlBasicVisitor<Void> {
boolean found;
@Override
public Void visit(SqlIdentifier id) {
SqlValidatorTable table = getCatalogReader().getTable(id.names);
// not every identifier is a table
if (table != null) {
HazelcastTable hazelcastTable = table.unwrap(HazelcastTable.class);
if (hazelcastTable.getTarget() instanceof ViewTable) {
found = ((ViewTable) hazelcastTable.getTarget()).isStream();
return null;
}
SqlConnector connector = getJetSqlConnector(hazelcastTable.getTarget());
if (connector.isStream()) {
found = true;
return null;
}
}
return super.visit(id);
}
@Override
public Void visit(SqlCall call) {
SqlOperator operator = call.getOperator();
if (operator instanceof HazelcastTableSourceFunction) {
if (((HazelcastTableSourceFunction) operator).isStream()) {
found = true;
return null;
}
}
return super.visit(call);
}
}
FindStreamingTablesVisitor visitor = new FindStreamingTablesVisitor();
node.accept(visitor);
return visitor.found;
}
use of org.apache.calcite.sql.validate.SqlValidatorTable in project hazelcast by hazelcast.
the class HazelcastSqlValidator method isHiddenColumn.
private boolean isHiddenColumn(SqlNode node, SelectScope scope) {
if (!(node instanceof SqlIdentifier)) {
return false;
}
SqlIdentifier identifier = (SqlIdentifier) node;
String fieldName = extractFieldName(identifier, scope);
if (fieldName == null) {
return false;
}
SqlValidatorTable table = scope.fullyQualify(identifier).namespace.getTable();
if (table == null) {
return false;
}
HazelcastTable unwrappedTable = table.unwrap(HazelcastTable.class);
if (unwrappedTable == null) {
return false;
}
return unwrappedTable.isHidden(fieldName);
}
Aggregations