Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions presto-docs/src/main/sphinx/functions/aggregate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ an :ref:`order-by-clause` within the aggregate function::
General Aggregate Functions
---------------------------

.. function:: any_value(x) -> [same as input]

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

.. function:: arbitrary(x) -> [same as input]

Returns an arbitrary non-null value of ``x``, if one exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
import static com.facebook.presto.operator.aggregation.AlternativeArbitraryAggregationFunction.ALTERNATIVE_ARBITRARY_AGGREGATION;
import static com.facebook.presto.operator.aggregation.AlternativeMaxAggregationFunction.ALTERNATIVE_MAX;
import static com.facebook.presto.operator.aggregation.AlternativeMinAggregationFunction.ALTERNATIVE_MIN;
import static com.facebook.presto.operator.aggregation.ArbitraryAggregationFunction.ANY_VALUE_AGGREGATION;
import static com.facebook.presto.operator.aggregation.ArbitraryAggregationFunction.ARBITRARY_AGGREGATION;
import static com.facebook.presto.operator.aggregation.ChecksumAggregationFunction.CHECKSUM_AGGREGATION;
import static com.facebook.presto.operator.aggregation.CountColumn.COUNT_COLUMN;
Expand Down Expand Up @@ -893,6 +894,7 @@ private List<? extends SqlFunction> getBuildInFunctions(FeaturesConfig featuresC
.function(CHECKSUM_AGGREGATION)
.function(IDENTITY_CAST)
.function(ARBITRARY_AGGREGATION)
.function(ANY_VALUE_AGGREGATION)
.functions(GREATEST, LEAST)
.functions(MAX_BY, MIN_BY, MAX_BY_N_AGGREGATION, MIN_BY_N_AGGREGATION)
.functions(MAX_AGGREGATION, MIN_AGGREGATION, MAX_N_AGGREGATION, MIN_N_AGGREGATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class ArbitraryAggregationFunction
public static final ArbitraryAggregationFunction ARBITRARY_AGGREGATION = new ArbitraryAggregationFunction();
private static final String NAME = "arbitrary";

private static final String ANY_VALUE_NAME = "any_value";
public static final ArbitraryAggregationFunction ANY_VALUE_AGGREGATION = new ArbitraryAggregationFunction(ANY_VALUE_NAME);

private static final MethodHandle LONG_INPUT_FUNCTION = methodHandle(ArbitraryAggregationFunction.class, "input", Type.class, NullableLongState.class, Block.class, int.class);
private static final MethodHandle DOUBLE_INPUT_FUNCTION = methodHandle(ArbitraryAggregationFunction.class, "input", Type.class, NullableDoubleState.class, Block.class, int.class);
private static final MethodHandle BOOLEAN_INPUT_FUNCTION = methodHandle(ArbitraryAggregationFunction.class, "input", Type.class, NullableBooleanState.class, Block.class, int.class);
Expand All @@ -70,7 +73,12 @@ public class ArbitraryAggregationFunction

protected ArbitraryAggregationFunction()
{
super(NAME,
this(NAME);
}

protected ArbitraryAggregationFunction(String name)
{
super(name,
ImmutableList.of(typeVariable("T")),
ImmutableList.of(),
parseTypeSignature("T"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed 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.facebook.presto.operator.aggregation;

import com.facebook.presto.common.type.Type;
import com.facebook.presto.metadata.FunctionAndTypeManager;
import com.facebook.presto.metadata.MetadataManager;
import com.facebook.presto.spi.function.JavaAggregationFunctionImplementation;

import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes;

public class TestAnyValueAggregation
extends TestArbitraryAggregation
{
private static final MetadataManager metadata = MetadataManager.createTestMetadataManager();
private static final FunctionAndTypeManager FUNCTION_AND_TYPE_MANAGER = metadata.getFunctionAndTypeManager();

@Override
protected JavaAggregationFunctionImplementation getAggregation(Type... arguments)
{
return FUNCTION_AND_TYPE_MANAGER.getJavaAggregateFunctionImplementation(FUNCTION_AND_TYPE_MANAGER.lookupFunction("any_value", fromTypes(arguments)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void testValidInt()
createIntsBlock(3, 3, null));
}

private static JavaAggregationFunctionImplementation getAggregation(Type... arguments)
protected JavaAggregationFunctionImplementation getAggregation(Type... arguments)
{
return FUNCTION_AND_TYPE_MANAGER.getJavaAggregateFunctionImplementation(FUNCTION_AND_TYPE_MANAGER.lookupFunction("arbitrary", fromTypes(arguments)));
}
Expand Down