Skip to content

Commit

Permalink
Replace boolean min/max with bool_and/bool_or
Browse files Browse the repository at this point in the history
Also, add standard aggregation function 'every'.
  • Loading branch information
electrum committed Jan 2, 2015
1 parent 58a3c20 commit 0816a2f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
12 changes: 12 additions & 0 deletions presto-docs/src/main/sphinx/functions/aggregate.rst
Expand Up @@ -21,6 +21,14 @@ General Aggregate Functions

Returns the average (arithmetic mean) of all input values.

.. function:: bool_and(boolean) -> boolean

Returns ``TRUE`` if every input value is ``TRUE``, otherwise ``FALSE``.

.. function:: bool_or(boolean) -> boolean

Returns ``TRUE`` if any input value is ``TRUE``, otherwise ``FALSE``.

.. function:: count(*) -> bigint

Returns the number of input rows.
Expand All @@ -34,6 +42,10 @@ General Aggregate Functions
Returns the number of ``TRUE`` input values.
This function is equivalent to ``count(CASE WHEN x THEN 1 END)``.

.. function:: every(boolean) -> boolean

This is an alias for :func:`bool_and`.

.. function:: max_by(x, y) -> [same as x]

Returns the value of ``x`` associated with the maximum value of ``y`` over all input values.
Expand Down
4 changes: 3 additions & 1 deletion presto-docs/src/main/sphinx/release/release-0.90.rst
Expand Up @@ -2,12 +2,14 @@
Release 0.90
============


General Changes
---------------
* Add ConnectorPageSink which is a more efficient interface for column-oriented sources.
* Add property ``task.writer-count`` to configure the number of writers per task.
* Added :doc:`/sql/set-session`, :doc:`/sql/reset-session` and :doc:`/sql/show-session`
* Replace ``min(boolean)`` with :func:`bool_and`.
* Replace ``max(boolean)`` with :func:`bool_or`.
* Add standard SQL function :func:`every` as an alias for :func:`bool_and`.

SPI Changes
-----------
Expand Down
Expand Up @@ -22,8 +22,8 @@
import com.facebook.presto.operator.aggregation.ApproximateSetAggregation;
import com.facebook.presto.operator.aggregation.ApproximateSumAggregations;
import com.facebook.presto.operator.aggregation.AverageAggregations;
import com.facebook.presto.operator.aggregation.BooleanMaxAggregation;
import com.facebook.presto.operator.aggregation.BooleanMinAggregation;
import com.facebook.presto.operator.aggregation.BooleanOrAggregation;
import com.facebook.presto.operator.aggregation.BooleanAndAggregation;
import com.facebook.presto.operator.aggregation.CountAggregation;
import com.facebook.presto.operator.aggregation.CountIfAggregation;
import com.facebook.presto.operator.aggregation.DoubleMaxAggregation;
Expand Down Expand Up @@ -245,8 +245,8 @@ public FunctionRegistry(TypeManager typeManager, boolean experimentalSyntaxEnabl
.aggregate(ApproximateLongPercentileAggregations.class)
.aggregate(ApproximateDoublePercentileAggregations.class)
.aggregate(CountIfAggregation.class)
.aggregate(BooleanMinAggregation.class)
.aggregate(BooleanMaxAggregation.class)
.aggregate(BooleanAndAggregation.class)
.aggregate(BooleanOrAggregation.class)
.aggregate(DoubleMinAggregation.class)
.aggregate(DoubleMaxAggregation.class)
.aggregate(LongMinAggregation.class)
Expand Down
Expand Up @@ -21,21 +21,21 @@
import static com.facebook.presto.operator.aggregation.state.TriStateBooleanState.NULL_VALUE;
import static com.facebook.presto.operator.aggregation.state.TriStateBooleanState.TRUE_VALUE;

@AggregationFunction("min")
public final class BooleanMinAggregation
@AggregationFunction(value = "bool_and", alias = "every")
public final class BooleanAndAggregation
{
private BooleanMinAggregation() {}
private BooleanAndAggregation() {}

@InputFunction
@IntermediateInputFunction
public static void min(TriStateBooleanState state, @SqlType(StandardTypes.BOOLEAN) boolean value)
public static void booleanAnd(TriStateBooleanState state, @SqlType(StandardTypes.BOOLEAN) boolean value)
{
// if value is false, update the min to false
// if the value is false, the result is false
if (!value) {
state.setByte(FALSE_VALUE);
}
else {
// if the current value is null, set the min to true
// if the current value is unset, set result to true
if (state.getByte() == NULL_VALUE) {
state.setByte(TRUE_VALUE);
}
Expand Down
Expand Up @@ -21,21 +21,21 @@
import static com.facebook.presto.operator.aggregation.state.TriStateBooleanState.NULL_VALUE;
import static com.facebook.presto.operator.aggregation.state.TriStateBooleanState.TRUE_VALUE;

@AggregationFunction("max")
public final class BooleanMaxAggregation
@AggregationFunction("bool_or")
public final class BooleanOrAggregation
{
private BooleanMaxAggregation() {}
private BooleanOrAggregation() {}

@InputFunction
@IntermediateInputFunction
public static void max(TriStateBooleanState state, @SqlType(StandardTypes.BOOLEAN) boolean value)
public static void booleanOr(TriStateBooleanState state, @SqlType(StandardTypes.BOOLEAN) boolean value)
{
// if value is true, update the max to true
// if value is true, the result is true
if (value) {
state.setByte(TRUE_VALUE);
}
else {
// if the current value is null, set the max to false
// if the current value is unset, set result to false
if (state.getByte() == NULL_VALUE) {
state.setByte(FALSE_VALUE);
}
Expand Down
Expand Up @@ -25,7 +25,7 @@
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;

public class TestBooleanMinAggregation
public class TestBooleanAndAggregation
extends AbstractTestAggregationFunction
{
@Override
Expand All @@ -51,7 +51,7 @@ public Boolean getExpectedValue(int start, int length)
@Override
protected String getFunctionName()
{
return "min";
return "bool_and";
}

@Override
Expand Down
Expand Up @@ -25,7 +25,7 @@
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;

public class TestBooleanMaxAggregation
public class TestBooleanOrAggregation
extends AbstractTestAggregationFunction
{
@Override
Expand All @@ -51,7 +51,7 @@ public Boolean getExpectedValue(int start, int length)
@Override
protected String getFunctionName()
{
return "max";
return "bool_or";
}

@Override
Expand Down

0 comments on commit 0816a2f

Please sign in to comment.