Search in sources :

Example 76 with SqlIdentifier

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;
}
Also used : SqlJoin(org.apache.calcite.sql.SqlJoin) ArrayList(java.util.ArrayList) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 77 with SqlIdentifier

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());
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlCall(org.apache.calcite.sql.SqlCall) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Example 78 with SqlIdentifier

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();
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlCall(org.apache.calcite.sql.SqlCall) SqlValidator(org.apache.calcite.sql.validate.SqlValidator) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 79 with SqlIdentifier

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());
            }
        }
    }
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) SqlInsert(org.apache.calcite.sql.SqlInsert) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlWriter(org.apache.calcite.sql.SqlWriter) SqlValidatorScope(org.apache.calcite.sql.validate.SqlValidatorScope) RESOURCE(com.hazelcast.jet.sql.impl.parse.ParserResource.RESOURCE) Collectors(java.util.stream.Collectors) QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) ArrayList(java.util.ArrayList) TableField(com.hazelcast.sql.impl.schema.TableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) List(java.util.List) SqlLiteral(org.apache.calcite.sql.SqlLiteral) SqlNode(org.apache.calcite.sql.SqlNode) ImmutableList(com.google.common.collect.ImmutableList) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Map(java.util.Map) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlValidator(org.apache.calcite.sql.validate.SqlValidator) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) SqlNode(org.apache.calcite.sql.SqlNode)

Example 80 with SqlIdentifier

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;
}
Also used : ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) SqlCall(org.apache.calcite.sql.SqlCall) SqlOperator(org.apache.calcite.sql.SqlOperator) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) HazelcastTableSourceFunction(com.hazelcast.jet.sql.impl.schema.HazelcastTableSourceFunction) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlConnectorUtil.getJetSqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil.getJetSqlConnector) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) SqlBasicVisitor(org.apache.calcite.sql.util.SqlBasicVisitor)

Aggregations

SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)131 SqlNode (org.apache.calcite.sql.SqlNode)84 RelDataType (org.apache.calcite.rel.type.RelDataType)46 SqlNodeList (org.apache.calcite.sql.SqlNodeList)43 ArrayList (java.util.ArrayList)41 SqlCall (org.apache.calcite.sql.SqlCall)32 BitString (org.apache.calcite.util.BitString)28 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)21 SqlSelect (org.apache.calcite.sql.SqlSelect)21 SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)12 SchemaPlus (org.apache.calcite.schema.SchemaPlus)11 SqlOperator (org.apache.calcite.sql.SqlOperator)11 NlsString (org.apache.calcite.util.NlsString)11 List (java.util.List)9 Map (java.util.Map)9 RelOptTable (org.apache.calcite.plan.RelOptTable)9 RexNode (org.apache.calcite.rex.RexNode)9 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)9 ImmutableList (com.google.common.collect.ImmutableList)8 RelNode (org.apache.calcite.rel.RelNode)7