com.hazelcast.org.apache.calcite.rel.mutable.MutableAggregate Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.org.apache.calcite.rel.mutable;
import com.hazelcast.org.apache.calcite.rel.core.Aggregate;
import com.hazelcast.org.apache.calcite.rel.core.AggregateCall;
import com.hazelcast.org.apache.calcite.rel.type.RelDataType;
import com.hazelcast.org.apache.calcite.util.ImmutableBitSet;
import com.hazelcast.com.google.common.collect.ImmutableList;
import com.hazelcast.org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.Objects;
/** Mutable equivalent of {@link com.hazelcast.org.apache.calcite.rel.core.Aggregate}. */
public class MutableAggregate extends MutableSingleRel {
public final ImmutableBitSet groupSet;
public final ImmutableList groupSets;
public final List aggCalls;
private MutableAggregate(MutableRel input, RelDataType rowType,
ImmutableBitSet groupSet,
@Nullable List groupSets, List aggCalls) {
super(MutableRelType.AGGREGATE, rowType, input);
this.groupSet = groupSet;
this.groupSets = groupSets == null
? ImmutableList.of(groupSet)
: ImmutableList.copyOf(groupSets);
assert ImmutableBitSet.ORDERING.isStrictlyOrdered(
this.groupSets) : this.groupSets;
for (ImmutableBitSet set : this.groupSets) {
assert groupSet.contains(set);
}
this.aggCalls = aggCalls;
}
/**
* Creates a MutableAggregate.
*
* @param input Input relational expression
* @param groupSet Bit set of grouping fields
* @param groupSets List of all grouping sets; null for just {@code groupSet}
* @param aggCalls Collection of calls to aggregate functions
*/
public static MutableAggregate of(MutableRel input, ImmutableBitSet groupSet,
@Nullable ImmutableList groupSets, List aggCalls) {
RelDataType rowType =
Aggregate.deriveRowType(input.cluster.getTypeFactory(),
input.rowType, false, groupSet, groupSets, aggCalls);
return new MutableAggregate(input, rowType, groupSet,
groupSets, aggCalls);
}
@Override public boolean equals(@Nullable Object obj) {
return obj == this
|| obj instanceof MutableAggregate
&& groupSet.equals(((MutableAggregate) obj).groupSet)
&& groupSets.equals(((MutableAggregate) obj).groupSets)
&& aggCalls.equals(((MutableAggregate) obj).aggCalls)
&& input.equals(((MutableAggregate) obj).input);
}
@Override public int hashCode() {
return Objects.hash(input, groupSet, groupSets, aggCalls);
}
@Override public StringBuilder digest(StringBuilder buf) {
return buf.append("Aggregate(groupSet: ").append(groupSet)
.append(", groupSets: ").append(groupSets)
.append(", calls: ").append(aggCalls).append(")");
}
public Aggregate.Group getGroupType() {
return Aggregate.Group.induce(groupSet, groupSets);
}
@Override public MutableRel clone() {
return MutableAggregate.of(input.clone(), groupSet, groupSets, aggCalls);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy