Search in sources :

Example 96 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project hazelcast by hazelcast.

the class HazelcastSqlOperatorTableTest method testReturnTypeInference.

@Test
public void testReturnTypeInference() {
    for (SqlOperator operator : HazelcastSqlOperatorTable.instance().getOperatorList()) {
        if (operator instanceof HazelcastTableFunction || operator instanceof HazelcastWindowTableFunction || operator == HazelcastSqlOperatorTable.IN || operator == HazelcastSqlOperatorTable.NOT_IN || operator == HazelcastSqlOperatorTable.UNION || operator == HazelcastSqlOperatorTable.UNION_ALL || operator == HazelcastSqlOperatorTable.ARGUMENT_ASSIGNMENT) {
            continue;
        }
        boolean valid = operator.getReturnTypeInference() instanceof HazelcastReturnTypeInference;
        assertTrue("Operator must have " + HazelcastReturnTypeInference.class.getSimpleName() + ": " + operator.getClass().getSimpleName(), valid);
    }
}
Also used : HazelcastWindowTableFunction(com.hazelcast.jet.sql.impl.aggregate.function.HazelcastWindowTableFunction) HazelcastTableFunction(com.hazelcast.jet.sql.impl.schema.HazelcastTableFunction) SqlOperator(org.apache.calcite.sql.SqlOperator) HazelcastReturnTypeInference(com.hazelcast.jet.sql.impl.validate.operators.typeinference.HazelcastReturnTypeInference) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 97 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project hazelcast by hazelcast.

the class HazelcastSqlToRelConverter method constructComparisons.

/**
 * Constructs comparisons between
 * left-hand operand (as a rule, SqlIdentifier) and right-hand list.
 */
private List<RexNode> constructComparisons(Blackboard bb, List<RexNode> leftKeys, SqlNodeList valuesList) {
    final List<RexNode> comparisons = new ArrayList<>();
    for (SqlNode rightValues : valuesList) {
        RexNode rexComparison;
        final SqlOperator comparisonOp = SqlStdOperatorTable.EQUALS;
        if (leftKeys.size() == 1) {
            rexComparison = rexBuilder.makeCall(comparisonOp, leftKeys.get(0), ensureSqlType(leftKeys.get(0).getType(), bb.convertExpression(rightValues)));
        } else {
            assert rightValues instanceof SqlCall;
            final SqlBasicCall basicCall = (SqlBasicCall) rightValues;
            assert basicCall.getOperator() instanceof SqlRowOperator && basicCall.operandCount() == leftKeys.size();
            rexComparison = RexUtil.composeConjunction(rexBuilder, Pair.zip(leftKeys, basicCall.getOperandList()).stream().map(pair -> rexBuilder.makeCall(comparisonOp, pair.left, ensureSqlType(pair.left.getType(), bb.convertExpression(pair.right)))).collect(Collectors.toList()));
        }
        comparisons.add(rexComparison);
    }
    return comparisons;
}
Also used : RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) CalciteContextException(org.apache.calcite.runtime.CalciteContextException) LiteralUtils(com.hazelcast.jet.sql.impl.validate.literal.LiteralUtils) RelDataTypeFamily(org.apache.calcite.rel.type.RelDataTypeFamily) HazelcastResources(com.hazelcast.jet.sql.impl.validate.HazelcastResources) SqlCall(org.apache.calcite.sql.SqlCall) SqlJsonEmptyOrError(org.apache.calcite.sql.SqlJsonEmptyOrError) BigDecimal(java.math.BigDecimal) RexUtil(org.apache.calcite.rex.RexUtil) SqlNode(org.apache.calcite.sql.SqlNode) SqlUtil(org.apache.calcite.sql.SqlUtil) RexNode(org.apache.calcite.rex.RexNode) Arrays.asList(java.util.Arrays.asList) LocalTime(java.time.LocalTime) TableModify(org.apache.calcite.rel.core.TableModify) DAY(org.apache.calcite.avatica.util.TimeUnit.DAY) SqlValidator(org.apache.calcite.sql.validate.SqlValidator) YEAR(org.apache.calcite.avatica.util.TimeUnit.YEAR) RelOptCluster(org.apache.calcite.plan.RelOptCluster) SqlKind(org.apache.calcite.sql.SqlKind) IdentityHashMap(java.util.IdentityHashMap) HazelcastTypeUtils(com.hazelcast.jet.sql.impl.validate.types.HazelcastTypeUtils) HazelcastJsonParseFunction(com.hazelcast.jet.sql.impl.validate.operators.json.HazelcastJsonParseFunction) SqlOperandTypeChecker(org.apache.calcite.sql.type.SqlOperandTypeChecker) RexLiteral(org.apache.calcite.rex.RexLiteral) Set(java.util.Set) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) HazelcastJsonValueFunction(com.hazelcast.jet.sql.impl.validate.operators.json.HazelcastJsonValueFunction) List(java.util.List) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) SqlRowOperator(org.apache.calcite.sql.fun.SqlRowOperator) SqlErrorCode(com.hazelcast.sql.impl.SqlErrorCode) MONTH(org.apache.calcite.avatica.util.TimeUnit.MONTH) SqlInsert(org.apache.calcite.sql.SqlInsert) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) RelOptTable(org.apache.calcite.plan.RelOptTable) ArrayList(java.util.ArrayList) SqlJsonValueReturning(org.apache.calcite.sql.SqlJsonValueReturning) TimeString(org.apache.calcite.util.TimeString) SqlToRelConverter(org.apache.calcite.sql2rel.SqlToRelConverter) Lists(com.google.common.collect.Lists) SqlLiteral(org.apache.calcite.sql.SqlLiteral) ImmutableList(com.google.common.collect.ImmutableList) Pair(org.apache.calcite.util.Pair) Converter(com.hazelcast.sql.impl.type.converter.Converter) SqlOperator(org.apache.calcite.sql.SqlOperator) SqlBetweenOperator(org.apache.calcite.sql.fun.SqlBetweenOperator) QueryException(com.hazelcast.sql.impl.QueryException) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIntervalQualifier(org.apache.calcite.sql.SqlIntervalQualifier) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlExtendedInsert(com.hazelcast.jet.sql.impl.parse.SqlExtendedInsert) SqlTypeFamily(org.apache.calcite.sql.type.SqlTypeFamily) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) HazelcastReturnTypeInference(com.hazelcast.jet.sql.impl.validate.operators.typeinference.HazelcastReturnTypeInference) RexBuilder(org.apache.calcite.rex.RexBuilder) Literal(com.hazelcast.jet.sql.impl.validate.literal.Literal) SqlRexConvertletTable(org.apache.calcite.sql2rel.SqlRexConvertletTable) SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) SqlValidatorException(org.apache.calcite.sql.validate.SqlValidatorException) RelNode(org.apache.calcite.rel.RelNode) LogicalTableInsert(com.hazelcast.jet.sql.impl.opt.logical.LogicalTableInsert) Prepare(org.apache.calcite.prepare.Prepare) SECOND(org.apache.calcite.avatica.util.TimeUnit.SECOND) HazelcastBetweenOperator(com.hazelcast.jet.sql.impl.validate.operators.predicate.HazelcastBetweenOperator) SqlJsonValueEmptyOrErrorBehavior(org.apache.calcite.sql.SqlJsonValueEmptyOrErrorBehavior) SqlInOperator(org.apache.calcite.sql.fun.SqlInOperator) Converters(com.hazelcast.sql.impl.type.converter.Converters) Util(org.apache.calcite.util.Util) LogicalTableSink(com.hazelcast.jet.sql.impl.opt.logical.LogicalTableSink) Resources(org.apache.calcite.runtime.Resources) SqlNodeList(org.apache.calcite.sql.SqlNodeList) Collections(java.util.Collections) SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) SqlOperator(org.apache.calcite.sql.SqlOperator) SqlCall(org.apache.calcite.sql.SqlCall) ArrayList(java.util.ArrayList) SqlRowOperator(org.apache.calcite.sql.fun.SqlRowOperator) RexNode(org.apache.calcite.rex.RexNode) SqlNode(org.apache.calcite.sql.SqlNode)

Example 98 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project hazelcast by hazelcast.

the class HazelcastLikeOperator method reduceExpr.

@Override
public ReduceResult reduceExpr(int opOrdinal, TokenSequence list) {
    SqlNode exp0 = list.node(opOrdinal - 1);
    SqlOperator op = list.op(opOrdinal);
    assert op instanceof SqlLikeOperator;
    SqlNode exp1 = SqlParserUtil.toTreeEx(list, opOrdinal + 1, getRightPrec(), SqlKind.ESCAPE);
    SqlNode exp2 = null;
    if ((opOrdinal + 2) < list.size()) {
        if (list.isOp(opOrdinal + 2)) {
            SqlOperator op2 = list.op(opOrdinal + 2);
            if (op2.getKind() == SqlKind.ESCAPE) {
                exp2 = SqlParserUtil.toTreeEx(list, opOrdinal + 3, getRightPrec(), SqlKind.ESCAPE);
            }
        }
    }
    SqlNode[] operands;
    int end;
    if (exp2 != null) {
        operands = new SqlNode[] { exp0, exp1, exp2 };
        end = opOrdinal + 4;
    } else {
        operands = new SqlNode[] { exp0, exp1 };
        end = opOrdinal + 2;
    }
    SqlCall call = createCall(SqlParserPos.ZERO, operands);
    return new ReduceResult(opOrdinal - 1, end, call);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlCall(org.apache.calcite.sql.SqlCall) SqlLikeOperator(org.apache.calcite.sql.fun.SqlLikeOperator) SqlNode(org.apache.calcite.sql.SqlNode)

Example 99 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project hazelcast by hazelcast.

the class RexToExpression method convertCall.

/**
 * Converts a {@link RexCall} to {@link Expression}.
 *
 * @param call the call to convert.
 * @return the resulting expression.
 * @throws QueryException if the given {@link RexCall} can't be
 *                        converted.
 */
@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:MethodLength", "checkstyle:ReturnCount", "checkstyle:NPathComplexity", "checkstyle:MagicNumber" })
public static Expression<?> convertCall(RexCall call, Expression<?>[] operands) {
    SqlOperator operator = call.getOperator();
    QueryDataType resultType = HazelcastTypeUtils.toHazelcastType(call.getType());
    switch(operator.getKind()) {
        case DEFAULT:
            return ConstantExpression.create(null, resultType);
        case CAST:
            if (operands[0].getType().equals(resultType)) {
                // nullable ones after the conversion.
                return operands[0];
            }
            return CastExpression.create(operands[0], resultType);
        case AND:
            return AndPredicate.create(operands);
        case OR:
            return OrPredicate.create(operands);
        case NOT:
            return NotPredicate.create(operands[0]);
        case PLUS:
            return PlusFunction.create(operands[0], operands[1], resultType);
        case MINUS:
            return MinusFunction.create(operands[0], operands[1], resultType);
        case TIMES:
            return MultiplyFunction.create(operands[0], operands[1], resultType);
        case DIVIDE:
            return DivideFunction.create(operands[0], operands[1], resultType);
        case MOD:
            return RemainderFunction.create(operands[0], operands[1], resultType);
        case MINUS_PREFIX:
            return UnaryMinusFunction.create(operands[0], resultType);
        case PLUS_PREFIX:
            return operands[0];
        case FLOOR:
            return FloorCeilFunction.create(operands[0], resultType, false);
        case CEIL:
            return FloorCeilFunction.create(operands[0], resultType, true);
        case EQUALS:
            return ComparisonPredicate.create(operands[0], operands[1], ComparisonMode.EQUALS);
        case NOT_EQUALS:
            return ComparisonPredicate.create(operands[0], operands[1], ComparisonMode.NOT_EQUALS);
        case GREATER_THAN:
            return ComparisonPredicate.create(operands[0], operands[1], ComparisonMode.GREATER_THAN);
        case GREATER_THAN_OR_EQUAL:
            return ComparisonPredicate.create(operands[0], operands[1], ComparisonMode.GREATER_THAN_OR_EQUAL);
        case LESS_THAN:
            return ComparisonPredicate.create(operands[0], operands[1], ComparisonMode.LESS_THAN);
        case LESS_THAN_OR_EQUAL:
            return ComparisonPredicate.create(operands[0], operands[1], ComparisonMode.LESS_THAN_OR_EQUAL);
        case SEARCH:
            return SearchPredicate.create(operands[0], operands[1]);
        case IS_TRUE:
            return IsTruePredicate.create(operands[0]);
        case IS_NOT_TRUE:
            return IsNotTruePredicate.create(operands[0]);
        case IS_FALSE:
            return IsFalsePredicate.create(operands[0]);
        case IS_NOT_FALSE:
            return IsNotFalsePredicate.create(operands[0]);
        case IS_NULL:
            return IsNullPredicate.create(operands[0]);
        case IS_NOT_NULL:
            return IsNotNullPredicate.create(operands[0]);
        case LIKE:
            boolean negated = ((HazelcastLikeOperator) operator).isNegated();
            Expression<?> escape1 = operands.length == 2 ? null : operands[2];
            return LikeFunction.create(operands[0], operands[1], escape1, negated);
        case TRIM:
            assert operands.length == 3;
            assert operands[0] instanceof SymbolExpression;
            SqlTrimFunction.Flag trimFlag = ((SymbolExpression) operands[0]).getSymbol();
            return TrimFunction.create(operands[2], operands[1], trimFlag.getLeft() == 1, trimFlag.getRight() == 1);
        case EXTRACT:
            assert operands.length == 2;
            assert operands[0] instanceof SymbolExpression;
            TimeUnitRange field = ((SymbolExpression) operands[0]).getSymbol();
            ExtractField extractField = convertField(field);
            return ExtractFunction.create(operands[1], extractField);
        case CASE:
            return CaseExpression.create(operands);
        case COALESCE:
            return CaseExpression.coalesce(operands);
        case NULLIF:
            return CaseExpression.nullif(operands[0], operands[1]);
        case OTHER:
            if (operator == HazelcastSqlOperatorTable.CONCAT) {
                assert operands.length == 2;
                return ConcatFunction.create(operands[0], operands[1]);
            }
            if (operator == HazelcastSqlOperatorTable.NOT_LIKE) {
                assert ((HazelcastLikeOperator) operator).isNegated();
                Expression<?> escape2 = operands.length == 2 ? null : operands[2];
                return LikeFunction.create(operands[0], operands[1], escape2, true);
            }
            break;
        case POSITION:
        case OTHER_FUNCTION:
            SqlFunction function = (SqlFunction) operator;
            // Math.
            if (function == HazelcastSqlOperatorTable.POWER) {
                assert operands.length == 2;
                return DoubleBiFunction.create(operands[0], operands[1], DoubleBiFunction.POWER);
            } else if (function == HazelcastSqlOperatorTable.SQUARE) {
                return DoubleFunction.create(operands[0], DoubleFunction.SQUARE);
            } else if (function == HazelcastSqlOperatorTable.SQRT) {
                return DoubleFunction.create(operands[0], DoubleFunction.SQRT);
            } else if (function == HazelcastSqlOperatorTable.CBRT) {
                return DoubleFunction.create(operands[0], DoubleFunction.CBRT);
            } else if (function == HazelcastSqlOperatorTable.COS) {
                return DoubleFunction.create(operands[0], DoubleFunction.COS);
            } else if (function == HazelcastSqlOperatorTable.SIN) {
                return DoubleFunction.create(operands[0], DoubleFunction.SIN);
            } else if (function == HazelcastSqlOperatorTable.TAN) {
                return DoubleFunction.create(operands[0], DoubleFunction.TAN);
            } else if (function == HazelcastSqlOperatorTable.COT) {
                return DoubleFunction.create(operands[0], DoubleFunction.COT);
            } else if (function == HazelcastSqlOperatorTable.ACOS) {
                return DoubleFunction.create(operands[0], DoubleFunction.ACOS);
            } else if (function == HazelcastSqlOperatorTable.ASIN) {
                return DoubleFunction.create(operands[0], DoubleFunction.ASIN);
            } else if (function == HazelcastSqlOperatorTable.ATAN) {
                return DoubleFunction.create(operands[0], DoubleFunction.ATAN);
            } else if (function == HazelcastSqlOperatorTable.ATAN2) {
                assert operands.length == 2;
                return DoubleBiFunction.create(operands[0], operands[1], DoubleBiFunction.ATAN2);
            } else if (function == HazelcastSqlOperatorTable.EXP) {
                return DoubleFunction.create(operands[0], DoubleFunction.EXP);
            } else if (function == HazelcastSqlOperatorTable.LN) {
                return DoubleFunction.create(operands[0], DoubleFunction.LN);
            } else if (function == HazelcastSqlOperatorTable.LOG10) {
                return DoubleFunction.create(operands[0], DoubleFunction.LOG10);
            } else if (function == HazelcastSqlOperatorTable.RAND) {
                return RandFunction.create(operands.length == 0 ? null : operands[0]);
            } else if (function == HazelcastSqlOperatorTable.ABS) {
                return AbsFunction.create(operands[0], resultType);
            } else if (function == SqlStdOperatorTable.PI) {
                return ConstantExpression.create(Math.PI, resultType);
            } else if (function == HazelcastSqlOperatorTable.SIGN) {
                return SignFunction.create(operands[0], resultType);
            } else if (function == HazelcastSqlOperatorTable.DEGREES) {
                return DoubleFunction.create(operands[0], DoubleFunction.DEGREES);
            } else if (function == HazelcastSqlOperatorTable.RADIANS) {
                return DoubleFunction.create(operands[0], DoubleFunction.RADIANS);
            } else if (function == HazelcastSqlOperatorTable.ROUND) {
                return RoundTruncateFunction.create(operands[0], operands.length == 1 ? null : operands[1], resultType, false);
            } else if (function == HazelcastSqlOperatorTable.TRUNCATE) {
                return RoundTruncateFunction.create(operands[0], operands.length == 1 ? null : operands[1], resultType, true);
            }
            if (function == CHAR_LENGTH || function == CHARACTER_LENGTH || function == LENGTH) {
                return CharLengthFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.UPPER) {
                return UpperFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.LOWER) {
                return LowerFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.INITCAP) {
                return InitcapFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.ASCII) {
                return AsciiFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.SUBSTRING) {
                Expression<?> input = operands[0];
                Expression<?> start = operands[1];
                Expression<?> length = operands.length > 2 ? operands[2] : null;
                return SubstringFunction.create(input, start, length);
            } else if (function == HazelcastSqlOperatorTable.LTRIM) {
                return TrimFunction.create(operands[0], null, true, false);
            } else if (function == HazelcastSqlOperatorTable.RTRIM) {
                return TrimFunction.create(operands[0], null, false, true);
            } else if (function == HazelcastSqlOperatorTable.BTRIM) {
                return TrimFunction.create(operands[0], null, true, true);
            } else if (function == HazelcastSqlOperatorTable.REPLACE) {
                return ReplaceFunction.create(operands[0], operands[1], operands[2]);
            } else if (function == HazelcastSqlOperatorTable.POSITION) {
                Expression<?> start = operands.length > 2 ? operands[2] : null;
                return PositionFunction.create(operands[0], operands[1], start);
            } else if (function == HazelcastSqlOperatorTable.TO_TIMESTAMP_TZ) {
                return ToTimestampTzFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.TO_EPOCH_MILLIS) {
                return ToEpochMillisFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.CONCAT_WS) {
                return ConcatWSFunction.create(operands);
            } else if (function == HazelcastSqlOperatorTable.JSON_QUERY) {
                final SqlJsonQueryWrapperBehavior wrapperBehavior = ((SymbolExpression) operands[2]).getSymbol();
                final SqlJsonQueryEmptyOrErrorBehavior onEmpty = ((SymbolExpression) operands[3]).getSymbol();
                final SqlJsonQueryEmptyOrErrorBehavior onError = ((SymbolExpression) operands[4]).getSymbol();
                return JsonQueryFunction.create(operands[0], operands[1], wrapperBehavior, onEmpty, onError);
            } else if (function == HazelcastJsonParseFunction.INSTANCE) {
                return JsonParseFunction.create(operands[0]);
            } else if (function == HazelcastSqlOperatorTable.JSON_VALUE) {
                final SqlJsonValueEmptyOrErrorBehavior onEmpty = ((SymbolExpression) operands[4]).getSymbol();
                final SqlJsonValueEmptyOrErrorBehavior onError = ((SymbolExpression) operands[5]).getSymbol();
                return JsonValueFunction.create(operands[0], operands[1], operands[2], operands[3], resultType, onEmpty, onError);
            } else if (function == HazelcastSqlOperatorTable.JSON_OBJECT) {
                final SqlJsonConstructorNullClause nullClause = ((SymbolExpression) operands[0]).getSymbol();
                final Expression<?>[] fields = Arrays.copyOfRange(operands, 1, operands.length);
                return JsonObjectFunction.create(fields, nullClause);
            } else if (function == HazelcastSqlOperatorTable.JSON_ARRAY) {
                final SqlJsonConstructorNullClause nullClause = ((SymbolExpression) operands[0]).getSymbol();
                final Expression<?>[] fields = Arrays.copyOfRange(operands, 1, operands.length);
                return JsonArrayFunction.create(fields, nullClause);
            }
            break;
        default:
            break;
    }
    throw QueryException.error("Unsupported operator: " + operator);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) TimeUnitRange(org.apache.calcite.avatica.util.TimeUnitRange) HazelcastLikeOperator(com.hazelcast.jet.sql.impl.validate.operators.string.HazelcastLikeOperator) SqlJsonQueryWrapperBehavior(org.apache.calcite.sql.SqlJsonQueryWrapperBehavior) SqlJsonQueryEmptyOrErrorBehavior(org.apache.calcite.sql.SqlJsonQueryEmptyOrErrorBehavior) SearchableExpression(com.hazelcast.sql.impl.expression.SearchableExpression) CastExpression(com.hazelcast.sql.impl.expression.CastExpression) CaseExpression(com.hazelcast.sql.impl.expression.CaseExpression) Expression(com.hazelcast.sql.impl.expression.Expression) SymbolExpression(com.hazelcast.sql.impl.expression.SymbolExpression) ConstantExpression(com.hazelcast.sql.impl.expression.ConstantExpression) SqlTrimFunction(org.apache.calcite.sql.fun.SqlTrimFunction) SymbolExpression(com.hazelcast.sql.impl.expression.SymbolExpression) ExtractField(com.hazelcast.sql.impl.expression.datetime.ExtractField) SqlJsonConstructorNullClause(org.apache.calcite.sql.SqlJsonConstructorNullClause) SqlJsonValueEmptyOrErrorBehavior(org.apache.calcite.sql.SqlJsonValueEmptyOrErrorBehavior) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 100 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator 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

SqlOperator (org.apache.calcite.sql.SqlOperator)129 ArrayList (java.util.ArrayList)44 RexNode (org.apache.calcite.rex.RexNode)41 RelDataType (org.apache.calcite.rel.type.RelDataType)25 SqlCall (org.apache.calcite.sql.SqlCall)24 RexCall (org.apache.calcite.rex.RexCall)21 SqlNode (org.apache.calcite.sql.SqlNode)21 SqlKind (org.apache.calcite.sql.SqlKind)15 List (java.util.List)13 SqlFunction (org.apache.calcite.sql.SqlFunction)13 RelNode (org.apache.calcite.rel.RelNode)12 RexBuilder (org.apache.calcite.rex.RexBuilder)11 RexInputRef (org.apache.calcite.rex.RexInputRef)11 NlsString (org.apache.calcite.util.NlsString)11 Test (org.junit.Test)11 SqlBasicCall (org.apache.calcite.sql.SqlBasicCall)10 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)10 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)9 SqlOperator (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator)9 RexLiteral (org.apache.calcite.rex.RexLiteral)9