Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static com.facebook.presto.benchmark.BenchmarkQueryRunner.createLocalQueryRunner;
import static com.facebook.presto.spi.type.BigintType.BIGINT;
import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;

public class CountAggregationBenchmark
extends AbstractSimpleOperatorBenchmark
Expand All @@ -45,7 +44,7 @@ protected List<? extends OperatorFactory> createOperatorFactories()
OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "orderkey");
FunctionManager functionManager = localQueryRunner.getMetadata().getFunctionManager();
InternalAggregationFunction countFunction = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(testSessionBuilder().build(), QualifiedName.of("count"), fromTypes(BIGINT)));
functionManager.lookupFunction(QualifiedName.of("count"), fromTypes(BIGINT)));
AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(countFunction.bind(ImmutableList.of(0), Optional.empty())), false);
return ImmutableList.of(tableScanOperator, aggregationOperator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static com.facebook.presto.benchmark.BenchmarkQueryRunner.createLocalQueryRunner;
import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;

public class DoubleSumAggregationBenchmark
extends AbstractSimpleOperatorBenchmark
Expand All @@ -46,7 +45,7 @@ protected List<? extends OperatorFactory> createOperatorFactories()
OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
FunctionManager functionManager = MetadataManager.createTestMetadataManager().getFunctionManager();
InternalAggregationFunction doubleSum = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(testSessionBuilder().build(), QualifiedName.of("sum"), fromTypes(DOUBLE)));
functionManager.lookupFunction(QualifiedName.of("sum"), fromTypes(DOUBLE)));
AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(doubleSum.bind(ImmutableList.of(0), Optional.empty())), false);
return ImmutableList.of(tableScanOperator, aggregationOperator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package com.facebook.presto.benchmark;

import com.facebook.presto.Session;
import com.facebook.presto.benchmark.HandTpchQuery1.TpchQuery1Operator.TpchQuery1OperatorFactory;
import com.facebook.presto.metadata.FunctionManager;
import com.facebook.presto.operator.DriverContext;
Expand Down Expand Up @@ -44,7 +43,6 @@
import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.google.common.base.Preconditions.checkState;
import static io.airlift.units.DataSize.Unit.MEGABYTE;
import static java.util.Objects.requireNonNull;
Expand All @@ -62,15 +60,14 @@ public HandTpchQuery1(LocalQueryRunner localQueryRunner)
super(localQueryRunner, "hand_tpch_query_1", 1, 5);

FunctionManager functionManager = localQueryRunner.getMetadata().getFunctionManager();
Session session = testSessionBuilder().setCatalog("tpch").setSchema("tiny").build();
longAverage = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(session, QualifiedName.of("avg"), fromTypes(BIGINT)));
functionManager.lookupFunction(QualifiedName.of("avg"), fromTypes(BIGINT)));
doubleAverage = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(session, QualifiedName.of("avg"), fromTypes(DOUBLE)));
functionManager.lookupFunction(QualifiedName.of("avg"), fromTypes(DOUBLE)));
doubleSum = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(session, QualifiedName.of("sum"), fromTypes(DOUBLE)));
functionManager.lookupFunction(QualifiedName.of("sum"), fromTypes(DOUBLE)));
countFunction = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(session, QualifiedName.of("count"), ImmutableList.of()));
functionManager.lookupFunction(QualifiedName.of("count"), ImmutableList.of()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package com.facebook.presto.benchmark;

import com.facebook.presto.Session;
import com.facebook.presto.metadata.FunctionManager;
import com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory;
import com.facebook.presto.operator.FilterAndProjectOperator;
Expand Down Expand Up @@ -46,7 +45,6 @@
import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes;
import static com.facebook.presto.sql.relational.Expressions.field;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static io.airlift.units.DataSize.Unit.BYTE;

public class HandTpchQuery6
Expand All @@ -58,9 +56,8 @@ public HandTpchQuery6(LocalQueryRunner localQueryRunner)
{
super(localQueryRunner, "hand_tpch_query_6", 10, 100);
FunctionManager functionManager = localQueryRunner.getMetadata().getFunctionManager();
Session session = testSessionBuilder().setCatalog("tpch").setSchema("tiny").build();
doubleSum = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(session, QualifiedName.of("sum"), fromTypes(DOUBLE)));
functionManager.lookupFunction(QualifiedName.of("sum"), fromTypes(DOUBLE)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static com.facebook.presto.benchmark.BenchmarkQueryRunner.createLocalQueryRunner;
import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static io.airlift.units.DataSize.Unit.MEGABYTE;

public class HashAggregationBenchmark
Expand All @@ -46,7 +45,7 @@ public HashAggregationBenchmark(LocalQueryRunner localQueryRunner)

FunctionManager functionManager = localQueryRunner.getMetadata().getFunctionManager();
doubleSum = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(testSessionBuilder().build(), QualifiedName.of("sum"), fromTypes(DOUBLE)));
functionManager.lookupFunction(QualifiedName.of("sum"), fromTypes(DOUBLE)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package com.facebook.presto.benchmark;

import com.facebook.presto.metadata.Metadata;
import com.facebook.presto.operator.FilterAndProjectOperator;
import com.facebook.presto.operator.OperatorFactory;
import com.facebook.presto.operator.project.PageProcessor;
Expand All @@ -29,10 +30,10 @@
import java.util.function.Supplier;

import static com.facebook.presto.benchmark.BenchmarkQueryRunner.createLocalQueryRunner;
import static com.facebook.presto.metadata.InternalSignatureUtils.internalOperator;
import static com.facebook.presto.spi.function.OperatorType.GREATER_THAN_OR_EQUAL;
import static com.facebook.presto.spi.type.BooleanType.BOOLEAN;
import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
import static com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes;
import static com.facebook.presto.sql.relational.Expressions.call;
import static com.facebook.presto.sql.relational.Expressions.constant;
import static com.facebook.presto.sql.relational.Expressions.field;
Expand All @@ -49,13 +50,14 @@ public PredicateFilterBenchmark(LocalQueryRunner localQueryRunner)
@Override
protected List<? extends OperatorFactory> createOperatorFactories()
{
Metadata metadata = localQueryRunner.getMetadata();
OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
RowExpression filter = call(
internalOperator(GREATER_THAN_OR_EQUAL, BOOLEAN.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature())),
metadata.getFunctionManager().resolveOperator(GREATER_THAN_OR_EQUAL, fromTypes(DOUBLE, DOUBLE)),
BOOLEAN,
field(0, DOUBLE),
constant(50000.0, DOUBLE));
ExpressionCompiler expressionCompiler = new ExpressionCompiler(localQueryRunner.getMetadata(), new PageFunctionCompiler(localQueryRunner.getMetadata(), 0));
ExpressionCompiler expressionCompiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, DOUBLE)));

FilterAndProjectOperator.FilterAndProjectOperatorFactory filterAndProjectOperator = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.List;
import java.util.Optional;

import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
import static com.facebook.presto.geospatial.KdbTree.buildKdbTree;
import static com.facebook.presto.geospatial.serde.GeometrySerde.serialize;
import static com.facebook.presto.operator.aggregation.AggregationTestUtils.createGroupByIdBlock;
Expand Down Expand Up @@ -99,7 +98,7 @@ private InternalAggregationFunction getFunction()
{
FunctionManager functionManager = functionAssertions.getMetadata().getFunctionManager();
return functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(TEST_SESSION, QualifiedName.of("spatial_partitioning"), fromTypes(GEOMETRY, INTEGER)));
functionManager.lookupFunction(QualifiedName.of("spatial_partitioning"), fromTypes(GEOMETRY, INTEGER)));
}

private List<OGCGeometry> makeGeometries()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.function.BiFunction;
import java.util.stream.Collectors;

import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
import static com.facebook.presto.metadata.FunctionExtractor.extractFunctions;
import static com.facebook.presto.operator.aggregation.AggregationTestUtils.assertAggregation;
import static com.facebook.presto.plugin.geospatial.GeometryType.GEOMETRY;
Expand All @@ -53,7 +52,7 @@ public void registerFunctions()
functionAssertions.getMetadata().addFunctions(extractFunctions(plugin.getFunctions()));
FunctionManager functionManager = functionAssertions.getMetadata().getFunctionManager();
function = functionManager.getAggregateFunctionImplementation(
functionManager.resolveFunction(TEST_SESSION, QualifiedName.of(getFunctionName()), fromTypes(GEOMETRY)));
functionManager.lookupFunction(QualifiedName.of(getFunctionName()), fromTypes(GEOMETRY)));
}

protected void assertAggregatedGeometries(String testDescription, String expectedWkt, String... wkts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import java.util.OptionalDouble;

import static com.facebook.presto.spi.function.OperatorType.CAST;
import static com.facebook.presto.metadata.CastType.CAST;
import static java.util.Collections.singletonList;

final class StatsUtil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.metadata;

import com.facebook.presto.spi.function.OperatorType;

import static com.facebook.presto.metadata.OperatorSignatureUtils.mangleOperatorName;
import static com.facebook.presto.operator.scalar.JsonStringToArrayCast.JSON_STRING_TO_ARRAY_NAME;
import static com.facebook.presto.operator.scalar.JsonStringToMapCast.JSON_STRING_TO_MAP_NAME;
import static com.facebook.presto.operator.scalar.JsonStringToRowCast.JSON_STRING_TO_ROW_NAME;
import static com.facebook.presto.operator.scalar.TryCastFunction.TRY_CAST_NAME;
import static java.lang.String.format;

public enum CastType
{
CAST(mangleOperatorName(OperatorType.CAST.name()), true),
SATURATED_FLOOR_CAST(mangleOperatorName(OperatorType.SATURATED_FLOOR_CAST.name()), true),
TRY_CAST(TRY_CAST_NAME, false),
JSON_TO_ARRAY_CAST(JSON_STRING_TO_ARRAY_NAME, false),
JSON_TO_MAP_CAST(JSON_STRING_TO_MAP_NAME, false),
JSON_TO_ROW_CAST(JSON_STRING_TO_ROW_NAME, false);

private final String castName;
private final boolean isOperatorType;

CastType(String castName, boolean isOperatorType)
{
this.castName = castName;
this.isOperatorType = isOperatorType;
}

public String getCastName()
{
return castName;
}

public boolean isOperatorType()
{
return isOperatorType;
}

public static OperatorType toOperatorType(CastType castType)
{
switch (castType) {
case CAST:
return OperatorType.CAST;
case SATURATED_FLOOR_CAST:
return OperatorType.SATURATED_FLOOR_CAST;
default:
throw new IllegalArgumentException(format("No OperatorType for CastType %s", castType));
}
}

public static CastType fromOperatorType(OperatorType operatorType)
{
if (operatorType == OperatorType.CAST) {
return CAST;
}
if (operatorType == OperatorType.SATURATED_FLOOR_CAST) {
return SATURATED_FLOOR_CAST;
}
throw new IllegalArgumentException((format("No CastType for OperatorType %s", operatorType)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.facebook.presto.spi.function.FunctionHandle;
import com.facebook.presto.spi.function.OperatorType;
import com.facebook.presto.spi.function.Signature;
import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.TypeManager;
import com.facebook.presto.spi.type.TypeSignature;
import com.facebook.presto.sql.analyzer.FeaturesConfig;
Expand Down Expand Up @@ -64,6 +63,19 @@ public List<SqlFunction> listFunctions()
return globalFunctionNamespace.listFunctions();
}

/**
* Lookup up a function with a fully qualified name and fully bound types.
* @throws PrestoException if function could not be found
*/
public FunctionHandle lookupFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes)
{
return globalFunctionNamespace.lookupFunction(name, parameterTypes);
}

/**
* Resolves a function using the SQL path, and implicit type coercions.
* @throws PrestoException if there are no matches or multiple matches
*/
public FunctionHandle resolveFunction(Session session, QualifiedName name, List<TypeSignatureProvider> parameterTypes)
{
// TODO Actually use session
Expand All @@ -74,11 +86,6 @@ public FunctionHandle resolveFunction(Session session, QualifiedName name, List<
return globalFunctionNamespace.resolveFunction(name, parameterTypes);
}

public Signature resolveFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes)
{
return globalFunctionNamespace.resolveFunction(name, parameterTypes).getSignature();
}

public WindowFunctionSupplier getWindowFunctionImplementation(FunctionHandle functionHandle)
{
return globalFunctionNamespace.getWindowFunctionImplementation(functionHandle);
Expand All @@ -104,17 +111,12 @@ public boolean isAggregationFunction(QualifiedName name)
return globalFunctionNamespace.isAggregationFunction(name);
}

public FunctionHandle resolveOperator(OperatorType operatorType, List<? extends Type> argumentTypes)
public FunctionHandle resolveOperator(OperatorType operatorType, List<TypeSignatureProvider> argumentTypes)
{
return globalFunctionNamespace.resolveOperator(operatorType, argumentTypes);
}

public boolean isRegistered(Signature signature)
{
return globalFunctionNamespace.isRegistered(signature);
}

public FunctionHandle lookupCast(OperatorType castType, TypeSignature fromType, TypeSignature toType)
public FunctionHandle lookupCast(CastType castType, TypeSignature fromType, TypeSignature toType)
{
return globalFunctionNamespace.lookupCast(castType, fromType, toType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.facebook.presto.spi.function.FunctionHandle;
import com.facebook.presto.spi.function.OperatorType;
import com.facebook.presto.spi.function.Signature;
import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.TypeSignature;
import com.facebook.presto.sql.analyzer.TypeSignatureProvider;
import com.facebook.presto.sql.tree.QualifiedName;
Expand Down Expand Up @@ -50,6 +49,11 @@ public List<SqlFunction> listFunctions()
return registry.list();
}

public FunctionHandle lookupFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes)
{
return registry.lookupFunction(name, parameterTypes);
}

public FunctionHandle resolveFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes)
{
return registry.resolveFunction(name, parameterTypes);
Expand All @@ -75,19 +79,14 @@ public boolean isAggregationFunction(QualifiedName name)
return registry.isAggregationFunction(name);
}

public FunctionHandle resolveOperator(OperatorType operatorType, List<? extends Type> argumentTypes)
public FunctionHandle resolveOperator(OperatorType operatorType, List<TypeSignatureProvider> argumentTypes)
throws OperatorNotFoundException
{
return registry.resolveOperator(operatorType, argumentTypes);
}

public FunctionHandle lookupCast(OperatorType castType, TypeSignature fromType, TypeSignature toType)
public FunctionHandle lookupCast(CastType castType, TypeSignature fromType, TypeSignature toType)
{
return registry.lookupCast(castType, fromType, toType);
}

public boolean isRegistered(Signature signature)
{
return registry.isRegistered(signature);
}
}
Loading