Search in sources :

Example 1 with HazelcastRelOptCluster

use of org.apache.calcite.plan.HazelcastRelOptCluster in project hazelcast by hazelcast.

the class OptimizerContext method createCluster.

private static HazelcastRelOptCluster createCluster(VolcanoPlanner planner, DistributionTraitDef distributionTraitDef) {
    HazelcastRelOptCluster cluster = HazelcastRelOptCluster.create(planner, HazelcastRexBuilder.INSTANCE, distributionTraitDef);
    // Wire up custom metadata providers.
    cluster.setMetadataProvider(JaninoRelMetadataProvider.of(METADATA_PROVIDER));
    return cluster;
}
Also used : HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster)

Example 2 with HazelcastRelOptCluster

use of org.apache.calcite.plan.HazelcastRelOptCluster in project hazelcast by hazelcast.

the class SlidingWindow method windowPolicyProvider.

public final FunctionEx<ExpressionEvalContext, SlidingWindowPolicy> windowPolicyProvider() {
    QueryParameterMetadata parameterMetadata = ((HazelcastRelOptCluster) getCluster()).getParameterMetadata();
    RexToExpressionVisitor visitor = new RexToExpressionVisitor(FAILING_FIELD_TYPE_PROVIDER, parameterMetadata);
    if (operator() == HazelcastSqlOperatorTable.TUMBLE) {
        Expression<?> windowSizeExpression = operand(2).accept(visitor);
        return context -> tumblingWinPolicy(WindowUtils.extractMillis(windowSizeExpression, context));
    } else if (operator() == HazelcastSqlOperatorTable.HOP) {
        Expression<?> windowSizeExpression = operand(2).accept(visitor);
        Expression<?> slideSizeExpression = operand(3).accept(visitor);
        return context -> slidingWinPolicy(WindowUtils.extractMillis(windowSizeExpression, context), WindowUtils.extractMillis(slideSizeExpression, context));
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : SlidingWindowPolicy.slidingWinPolicy(com.hazelcast.jet.core.SlidingWindowPolicy.slidingWinPolicy) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) FAILING_FIELD_TYPE_PROVIDER(com.hazelcast.sql.impl.plan.node.PlanNodeFieldTypeProvider.FAILING_FIELD_TYPE_PROVIDER) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) RelColumnMapping(org.apache.calcite.rel.metadata.RelColumnMapping) RexNode(org.apache.calcite.rex.RexNode) SqlOperator(org.apache.calcite.sql.SqlOperator) RexToExpressionVisitor(com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpressionVisitor) Expression(com.hazelcast.sql.impl.expression.Expression) Preconditions.checkTrue(com.hazelcast.internal.util.Preconditions.checkTrue) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelOptCluster(org.apache.calcite.plan.RelOptCluster) FunctionEx(com.hazelcast.function.FunctionEx) TableFunctionScan(org.apache.calcite.rel.core.TableFunctionScan) RelDataType(org.apache.calcite.rel.type.RelDataType) Set(java.util.Set) RelNode(org.apache.calcite.rel.RelNode) RexInputRef(org.apache.calcite.rex.RexInputRef) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Type(java.lang.reflect.Type) HazelcastSqlOperatorTable(com.hazelcast.jet.sql.impl.validate.HazelcastSqlOperatorTable) SlidingWindowPolicy.tumblingWinPolicy(com.hazelcast.jet.core.SlidingWindowPolicy.tumblingWinPolicy) WindowUtils(com.hazelcast.jet.sql.impl.aggregate.WindowUtils) RexCall(org.apache.calcite.rex.RexCall) HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) RexToExpressionVisitor(com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpressionVisitor) Expression(com.hazelcast.sql.impl.expression.Expression) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata)

Example 3 with HazelcastRelOptCluster

use of org.apache.calcite.plan.HazelcastRelOptCluster in project hazelcast by hazelcast.

the class SlidingWindowAggregatePhysicalRel method timestampExpression.

public Expression<?> timestampExpression() {
    QueryParameterMetadata parameterMetadata = ((HazelcastRelOptCluster) getCluster()).getParameterMetadata();
    RexVisitor<Expression<?>> visitor = OptUtils.createRexToExpressionVisitor(schema(parameterMetadata), parameterMetadata);
    return timestampExpression.accept(visitor);
}
Also used : HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) Expression(com.hazelcast.sql.impl.expression.Expression) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata)

Example 4 with HazelcastRelOptCluster

use of org.apache.calcite.plan.HazelcastRelOptCluster in project hazelcast by hazelcast.

the class OptimizerContext method create.

public static OptimizerContext create(HazelcastSchema rootSchema, List<List<String>> schemaPaths, List<Object> arguments, int memberCount, IMapResolver iMapResolver) {
    DistributionTraitDef distributionTraitDef = new DistributionTraitDef(memberCount);
    Prepare.CatalogReader catalogReader = createCatalogReader(rootSchema, schemaPaths);
    HazelcastSqlValidator validator = new HazelcastSqlValidator(catalogReader, arguments, iMapResolver);
    VolcanoPlanner volcanoPlanner = createPlanner(distributionTraitDef);
    HazelcastRelOptCluster cluster = createCluster(volcanoPlanner, distributionTraitDef);
    QueryParser parser = new QueryParser(validator);
    QueryConverter converter = new QueryConverter(validator, catalogReader, cluster);
    QueryPlanner planner = new QueryPlanner(volcanoPlanner);
    return new OptimizerContext(cluster, parser, converter, planner);
}
Also used : HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) QueryParser(com.hazelcast.jet.sql.impl.parse.QueryParser) QueryConverter(com.hazelcast.jet.sql.impl.parse.QueryConverter) Prepare(org.apache.calcite.prepare.Prepare) HazelcastSqlValidator(com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) DistributionTraitDef(com.hazelcast.jet.sql.impl.opt.distribution.DistributionTraitDef)

Aggregations

HazelcastRelOptCluster (org.apache.calcite.plan.HazelcastRelOptCluster)4 QueryParameterMetadata (com.hazelcast.sql.impl.QueryParameterMetadata)2 Expression (com.hazelcast.sql.impl.expression.Expression)2 FunctionEx (com.hazelcast.function.FunctionEx)1 Preconditions.checkTrue (com.hazelcast.internal.util.Preconditions.checkTrue)1 SlidingWindowPolicy (com.hazelcast.jet.core.SlidingWindowPolicy)1 SlidingWindowPolicy.slidingWinPolicy (com.hazelcast.jet.core.SlidingWindowPolicy.slidingWinPolicy)1 SlidingWindowPolicy.tumblingWinPolicy (com.hazelcast.jet.core.SlidingWindowPolicy.tumblingWinPolicy)1 WindowUtils (com.hazelcast.jet.sql.impl.aggregate.WindowUtils)1 DistributionTraitDef (com.hazelcast.jet.sql.impl.opt.distribution.DistributionTraitDef)1 RexToExpressionVisitor (com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpressionVisitor)1 QueryConverter (com.hazelcast.jet.sql.impl.parse.QueryConverter)1 QueryParser (com.hazelcast.jet.sql.impl.parse.QueryParser)1 HazelcastSqlOperatorTable (com.hazelcast.jet.sql.impl.validate.HazelcastSqlOperatorTable)1 HazelcastSqlValidator (com.hazelcast.jet.sql.impl.validate.HazelcastSqlValidator)1 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)1 FAILING_FIELD_TYPE_PROVIDER (com.hazelcast.sql.impl.plan.node.PlanNodeFieldTypeProvider.FAILING_FIELD_TYPE_PROVIDER)1 Type (java.lang.reflect.Type)1 List (java.util.List)1 Set (java.util.Set)1