Search in sources :

Example 11 with LogicalAggregate

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalAggregate in project calcite by apache.

the class RelWriterTest method testWriter.

/**
 * Unit test for {@link org.apache.calcite.rel.externalize.RelJsonWriter} on
 * a simple tree of relational expressions, consisting of a table, a filter
 * and an aggregate node.
 */
@Test
public void testWriter() {
    String s = Frameworks.withPlanner(new Frameworks.PlannerAction<String>() {

        public String apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
            rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
            LogicalTableScan scan = LogicalTableScan.create(cluster, relOptSchema.getTableForMember(Arrays.asList("hr", "emps")));
            final RexBuilder rexBuilder = cluster.getRexBuilder();
            LogicalFilter filter = LogicalFilter.create(scan, rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, rexBuilder.makeFieldAccess(rexBuilder.makeRangeReference(scan), "deptno", true), rexBuilder.makeExactLiteral(BigDecimal.TEN)));
            final RelJsonWriter writer = new RelJsonWriter();
            final RelDataType bigIntType = cluster.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
            LogicalAggregate aggregate = LogicalAggregate.create(filter, ImmutableBitSet.of(0), null, ImmutableList.of(AggregateCall.create(SqlStdOperatorTable.COUNT, true, false, ImmutableList.of(1), -1, bigIntType, "c"), AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, ImmutableList.<Integer>of(), -1, bigIntType, "d")));
            aggregate.explain(writer);
            return writer.asString();
        }
    });
    assertThat(s, is(XX));
}
Also used : LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) SchemaPlus(org.apache.calcite.schema.SchemaPlus) ReflectiveSchema(org.apache.calcite.adapter.java.ReflectiveSchema) RelDataType(org.apache.calcite.rel.type.RelDataType) RelJsonWriter(org.apache.calcite.rel.externalize.RelJsonWriter) LogicalTableScan(org.apache.calcite.rel.logical.LogicalTableScan) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) JdbcTest(org.apache.calcite.test.JdbcTest) Frameworks(org.apache.calcite.tools.Frameworks) RexBuilder(org.apache.calcite.rex.RexBuilder) JdbcTest(org.apache.calcite.test.JdbcTest) Test(org.junit.Test)

Example 12 with LogicalAggregate

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalAggregate in project flink by apache.

the class WrapJsonAggFunctionArgumentsRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final LogicalAggregate aggregate = call.rel(0);
    final AggregateCall aggCall = aggregate.getAggCallList().get(0);
    final RelNode aggInput = aggregate.getInput();
    final RelBuilder relBuilder = call.builder().push(aggInput);
    final List<Integer> affectedArgs = getAffectedArgs(aggCall);
    addProjections(aggregate.getCluster(), relBuilder, affectedArgs);
    final TargetMapping argsMapping = getAggArgsMapping(aggInput.getRowType().getFieldCount(), affectedArgs);
    final AggregateCall newAggregateCall = aggCall.transform(argsMapping);
    final LogicalAggregate newAggregate = aggregate.copy(aggregate.getTraitSet(), relBuilder.build(), aggregate.getGroupSet(), aggregate.getGroupSets(), Collections.singletonList(newAggregateCall));
    call.transformTo(newAggregate.withHints(Collections.singletonList(MARKER_HINT)));
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) RelBuilder(org.apache.calcite.tools.RelBuilder) TargetMapping(org.apache.calcite.util.mapping.Mappings.TargetMapping) RelNode(org.apache.calcite.rel.RelNode)

Example 13 with LogicalAggregate

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalAggregate in project drill by apache.

the class DrillAggregateRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final LogicalAggregate aggregate = call.rel(0);
    final RelNode input = call.rel(1);
    if (aggregate.containsDistinctCall()) {
        // currently, don't use this rule if any of the aggregates contains DISTINCT
        return;
    }
    final RelTraitSet traits = aggregate.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
    final RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify());
    call.transformTo(new DrillAggregateRel(aggregate.getCluster(), traits, convertedInput, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList()));
}
Also used : LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

LogicalAggregate (org.apache.calcite.rel.logical.LogicalAggregate)11 RelNode (org.apache.calcite.rel.RelNode)7 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)4 ArrayList (java.util.ArrayList)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RexBuilder (org.apache.calcite.rex.RexBuilder)3 ResolvedComputedColumn (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedComputedColumn)2 InvalidRelException (org.apache.calcite.rel.InvalidRelException)2 AggregateCall (org.apache.calcite.rel.core.AggregateCall)2 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)2 LogicalTableScan (org.apache.calcite.rel.logical.LogicalTableScan)2 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)2 RexNode (org.apache.calcite.rex.RexNode)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1 ResolvedAggregateFunctionCall (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedAggregateFunctionCall)1 ResolvedExpr (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedExpr)1