use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project streamline by hortonworks.
the class RuleParser method parseStreams.
private List<Stream> parseStreams(SqlSelect sqlSelect) throws Exception {
List<Stream> streams = new ArrayList<>();
SqlNode sqlFrom = sqlSelect.getFrom();
LOG.debug("from = {}", sqlFrom);
if (sqlFrom instanceof SqlJoin) {
throw new IllegalArgumentException("Sql join is not yet supported");
} else if (sqlFrom instanceof SqlIdentifier) {
streams.add(getStream(((SqlIdentifier) sqlFrom).getSimple()));
}
LOG.debug("Streams {}", streams);
return streams;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.
the class ParserNameResolutionTest method checkSuccess.
private static void checkSuccess(OptimizerContext context, String fieldName, String tableFqn, String... tableComponents) {
QueryParseResult res = context.parse(composeSelect(fieldName, tableComponents));
SqlSelect select = (SqlSelect) res.getNode();
SqlNodeList selectList = select.getSelectList();
assertEquals(1, selectList.size());
SqlIdentifier fieldIdentifier = (SqlIdentifier) selectList.get(0);
assertEquals(SqlIdentifier.getString(Arrays.asList(last(tableComponents), fieldName)), fieldIdentifier.toString());
SqlCall from = (SqlCall) select.getFrom();
assertEquals(from.getKind(), SqlKind.AS);
assertEquals(tableFqn, from.operand(0).toString());
assertEquals(last(tableComponents), from.operand(1).toString());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.
the class WindowUtils method getOrderingColumnType.
/**
* Return the datatype of the target column referenced by the DESCRIPTOR argument.
*/
public static RelDataType getOrderingColumnType(SqlCallBinding binding, int orderingColumnParameterIndex) {
SqlNode input = binding.operand(0);
SqlCall descriptor = (SqlCall) unwrapFunctionOperand(binding.operand(orderingColumnParameterIndex));
List<SqlNode> columnIdentifiers = descriptor.getOperandList();
if (columnIdentifiers.size() != 1) {
throw SqlUtil.newContextException(descriptor.getParserPosition(), ValidatorResource.RESOURCE.mustUseSingleOrderingColumn());
}
// `descriptor` is the DESCRIPTOR call, its operand is an SqlIdentifier having the column name
SqlIdentifier orderingColumnIdentifier = (SqlIdentifier) descriptor.getOperandList().get(0);
String orderingColumnName = orderingColumnIdentifier.getSimple();
SqlValidator validator = binding.getValidator();
RelDataTypeField columnField = validator.getValidatedNodeType(input).getField(orderingColumnName, validator.getCatalogReader().nameMatcher().isCaseSensitive(), false);
if (columnField == null) {
throw SqlUtil.newContextException(descriptor.getParserPosition(), RESOURCE.unknownIdentifier(orderingColumnName));
}
return columnField.getType();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier 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.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier 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;
}
Aggregations