Search in sources :

Example 1 with HazelcastTableSourceFunction

use of com.hazelcast.jet.sql.impl.schema.HazelcastTableSourceFunction 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

SqlConnector (com.hazelcast.jet.sql.impl.connector.SqlConnector)1 SqlConnectorUtil.getJetSqlConnector (com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil.getJetSqlConnector)1 ViewTable (com.hazelcast.jet.sql.impl.connector.virtual.ViewTable)1 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)1 HazelcastTableSourceFunction (com.hazelcast.jet.sql.impl.schema.HazelcastTableSourceFunction)1 SqlCall (org.apache.calcite.sql.SqlCall)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 SqlOperator (org.apache.calcite.sql.SqlOperator)1 SqlBasicVisitor (org.apache.calcite.sql.util.SqlBasicVisitor)1 SqlValidatorTable (org.apache.calcite.sql.validate.SqlValidatorTable)1