@Override public final <T> T accept(ExpressionVisitor<T> visitor) { SingleAggregateFunction function = getDelegate(); List<T> l = acceptChildren(visitor, visitor.visitEnter(function)); T t = visitor.visitLeave(function, l); if (t == null) { t = visitor.defaultReturn(function, l); } return t; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (delegate == null) { return super.evaluate(tuple, ptr); } delegate.evaluate(tuple, ptr); if (PLong.INSTANCE.compareTo(ptr,ZERO) == 0) { return false; } return true; }
@Override public int compare(SingleAggregateFunction o1, SingleAggregateFunction o2) { boolean isNullable1 = o1.isNullable(); boolean isNullable2 = o2.isNullable(); if (isNullable1 != isNullable2) { return isNullable1 ? 1 : -1; } isNullable1 = o1.getAggregatorExpression().isNullable(); isNullable2 = o2.getAggregatorExpression().isNullable(); if (isNullable1 != isNullable2) { return isNullable1 ? 1 : -1; } // Ensures COUNT(1) sorts first TODO: unit test for this boolean isConstant1 = o1.isConstantExpression(); boolean isConstant2 = o2.isConstantExpression(); if (isConstant1 != isConstant2) { return isConstant1 ? 1 : -1; } PDataType r1 = o1.getAggregator().getDataType(); PDataType r2 = o2.getAggregator().getDataType(); if (r1.isFixedWidth() != r2.isFixedWidth()) { return r1.isFixedWidth() ? -1 : 1; } return r1.compareTo(r2); } };
private static int getMinNullableIndex(List<SingleAggregateFunction> aggFuncs, boolean isUngroupedAggregation) { int minNullableIndex = aggFuncs.size(); for (int i = 0; i < aggFuncs.size(); i++) { SingleAggregateFunction aggFunc = aggFuncs.get(i); if (isUngroupedAggregation ? aggFunc.getAggregator().isNullable() : aggFunc.getAggregatorExpression().isNullable()) { minNullableIndex = i; break; } } return minNullableIndex; }
for (int i = 0; i < aggregators.length; i++) { SingleAggregateFunction aggFunc = (SingleAggregateFunction)ExpressionType.values()[WritableUtils.readVInt(input)].newInstance(); aggFunc.readFields(input, conf); functions[i] = aggFunc; aggregators[i] = aggFunc.getAggregator(); expressions[i] = aggFunc.getAggregatorExpression();
public Aggregator[] newAggregators(Configuration conf) { Aggregator[] aggregators = new Aggregator[functions.length]; for (int i = 0; i < functions.length; i++) { aggregators[i] = functions[i].newServerAggregator(conf); } return aggregators; }
@Override public Aggregator[] newAggregators() { Aggregator[] aggregators = new Aggregator[functions.length]; for (int i = 0; i < functions.length; i++) { aggregators[i] = functions[i].newClientAggregator(); } return aggregators; }
private static Aggregator[] getAggregators(List<SingleAggregateFunction> aggFuncs) { Aggregator[] aggregators = new Aggregator[aggFuncs.size()]; for (int i = 0; i < aggregators.length; i++) { aggregators[i] = aggFuncs.get(i).getAggregator(); } return aggregators; }
@Override protected SingleAggregateFunction getDelegate() { return delegate != null ? delegate : super.getDelegate(); }
@Override public int hashCode() { return isConstantExpression() ? 0 : super.hashCode(); }
for (int i = 0; i < aggregators.length; i++) { SingleAggregateFunction aggFunc = (SingleAggregateFunction)ExpressionType.values()[WritableUtils.readVInt(input)].newInstance(); aggFunc.readFields(input, conf); functions[i] = aggFunc; aggregators[i] = aggFunc.getAggregator(); expressions[i] = aggFunc.getAggregatorExpression();
/** * Create the aggregator to do client-side aggregation * based on the results returned from the aggregating * coprocessor. The data type of the returned Aggregator * must match the data type returned by {@link #newServerAggregator(Configuration)} * @return the aggregator to use on the client-side */ public Aggregator newClientAggregator() { return newServerAggregator(null); }
private static int getMinNullableIndex(List<SingleAggregateFunction> aggFuncs, boolean isUngroupedAggregation) { int minNullableIndex = aggFuncs.size(); for (int i = 0; i < aggFuncs.size(); i++) { SingleAggregateFunction aggFunc = aggFuncs.get(i); if (isUngroupedAggregation ? aggFunc.getAggregator().isNullable() : aggFunc.getAggregatorExpression().isNullable()) { minNullableIndex = i; break; } } return minNullableIndex; }
private SingleAggregateFunction(List<Expression> children, boolean isConstant) { super(children); this.isConstant = isConstant; this.aggregator = newClientAggregator(); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { return getAggregator().evaluate(tuple, ptr); }
@Override protected SingleAggregateFunction getDelegate() { return delegate != null ? delegate : super.getDelegate(); }
@Override public int hashCode() { return isConstantExpression() ? 0 : super.hashCode(); }
@Override public int compare(SingleAggregateFunction o1, SingleAggregateFunction o2) { boolean isNullable1 = o1.isNullable(); boolean isNullable2 = o2.isNullable(); if (isNullable1 != isNullable2) { return isNullable1 ? 1 : -1; } isNullable1 = o1.getAggregatorExpression().isNullable(); isNullable2 = o2.getAggregatorExpression().isNullable(); if (isNullable1 != isNullable2) { return isNullable1 ? 1 : -1; } // Ensures COUNT(1) sorts first TODO: unit test for this boolean isConstant1 = o1.isConstantExpression(); boolean isConstant2 = o2.isConstantExpression(); if (isConstant1 != isConstant2) { return isConstant1 ? 1 : -1; } PDataType r1 = o1.getAggregator().getDataType(); PDataType r2 = o2.getAggregator().getDataType(); if (r1.isFixedWidth() != r2.isFixedWidth()) { return r1.isFixedWidth() ? -1 : 1; } return r1.compareTo(r2); } };
for (int i = 0; i < aggregators.length; i++) { SingleAggregateFunction aggFunc = (SingleAggregateFunction)ExpressionType.values()[WritableUtils.readVInt(input)].newInstance(); aggFunc.readFields(input, conf); functions[i] = aggFunc; aggregators[i] = aggFunc.getAggregator(); expressions[i] = aggFunc.getAggregatorExpression();
public Aggregator newServerAggregator(Configuration config, ImmutableBytesWritable ptr) { Aggregator agg = newServerAggregator(config); agg.aggregate(null, ptr); return agg; }