Skip to content

Commit

Permalink
Add BlockEncodingSerde to FunctionRegistry
Browse files Browse the repository at this point in the history
* So that BlockEncodingSerde is available for magic literal deserialization
  • Loading branch information
haozhun committed Apr 22, 2015
1 parent 3ef9ad5 commit 228ddd9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
Expand Up @@ -70,6 +70,7 @@
import com.facebook.presto.operator.window.RankFunction;
import com.facebook.presto.operator.window.RowNumberFunction;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.block.BlockEncodingSerde;
import com.facebook.presto.spi.type.StandardTypes;
import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.TypeManager;
Expand Down Expand Up @@ -203,12 +204,14 @@ public class FunctionRegistry
private static final Set<Class<?>> SUPPORTED_LITERAL_TYPES = ImmutableSet.<Class<?>>of(long.class, double.class, Slice.class, boolean.class);

private final TypeManager typeManager;
private final BlockEncodingSerde blockEncodingSerde;
private final LoadingCache<SpecializedFunctionKey, FunctionInfo> specializedFunctionCache;
private volatile FunctionMap functions = new FunctionMap();

public FunctionRegistry(TypeManager typeManager, boolean experimentalSyntaxEnabled)
public FunctionRegistry(TypeManager typeManager, BlockEncodingSerde blockEncodingSerde, boolean experimentalSyntaxEnabled)
{
this.typeManager = checkNotNull(typeManager, "typeManager is null");
this.blockEncodingSerde = checkNotNull(blockEncodingSerde, "blockEncodingSerde is null");

specializedFunctionCache = CacheBuilder.newBuilder()
.maximumSize(1000)
Expand Down
Expand Up @@ -103,7 +103,7 @@ public MetadataManager(FeaturesConfig featuresConfig, TypeManager typeManager, S
@Inject
public MetadataManager(FeaturesConfig featuresConfig, TypeManager typeManager, JsonCodec<ViewDefinition> viewCodec, SplitManager splitManager, BlockEncodingSerde blockEncodingSerde)
{
functions = new FunctionRegistry(typeManager, featuresConfig.isExperimentalSyntaxEnabled());
functions = new FunctionRegistry(typeManager, blockEncodingSerde, featuresConfig.isExperimentalSyntaxEnabled());
this.typeManager = checkNotNull(typeManager, "types is null");
this.viewCodec = checkNotNull(viewCodec, "viewCodec is null");
this.splitManager = checkNotNull(splitManager, "splitManager is null");
Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package com.facebook.presto.metadata;

import com.facebook.presto.block.BlockEncodingManager;
import com.facebook.presto.operator.scalar.CustomFunctions;
import com.facebook.presto.operator.scalar.ScalarFunction;
import com.facebook.presto.spi.type.StandardTypes;
Expand Down Expand Up @@ -43,7 +44,8 @@ public class TestFunctionRegistry
@Test
public void testIdentityCast()
{
FunctionRegistry registry = new FunctionRegistry(new TypeRegistry(), true);
TypeRegistry typeManager = new TypeRegistry();
FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), true);
FunctionInfo exactOperator = registry.getCoercion(HYPER_LOG_LOG, HYPER_LOG_LOG);
assertEquals(exactOperator.getSignature().getName(), mangleOperatorName(OperatorType.CAST.name()));
assertEquals(transform(exactOperator.getArgumentTypes(), Functions.toStringFunction()), ImmutableList.of(StandardTypes.HYPER_LOG_LOG));
Expand All @@ -54,7 +56,7 @@ public void testIdentityCast()
public void testExactMatchBeforeCoercion()
{
TypeRegistry typeManager = new TypeRegistry();
FunctionRegistry registry = new FunctionRegistry(typeManager, true);
FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), true);
boolean foundOperator = false;
for (ParametricFunction function : registry.listOperators()) {
OperatorType operatorType = unmangleOperator(function.getSignature().getName());
Expand All @@ -79,7 +81,8 @@ public void testMagicLiteralFunction()
assertEquals(signature.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);

FunctionRegistry registry = new FunctionRegistry(new TypeRegistry(), true);
TypeRegistry typeManager = new TypeRegistry();
FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), true);
FunctionInfo function = registry.resolveFunction(QualifiedName.of(signature.getName()), signature.getArgumentTypes(), false);
assertEquals(function.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);
Expand All @@ -95,7 +98,8 @@ public void testDuplicateFunctions()
.filter(input -> input.getSignature().getName().equals("custom_add"))
.collect(toImmutableList());

FunctionRegistry registry = new FunctionRegistry(new TypeRegistry(), true);
TypeRegistry typeManager = new TypeRegistry();
FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), true);
registry.addFunctions(functions);
registry.addFunctions(functions);
}
Expand All @@ -108,15 +112,17 @@ public void testConflictingScalarAggregation()
.scalar(ScalarSum.class)
.getFunctions();

FunctionRegistry registry = new FunctionRegistry(new TypeRegistry(), true);
TypeRegistry typeManager = new TypeRegistry();
FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), true);
registry.addFunctions(functions);
}

@Test
public void testListingHiddenFunctions()
throws Exception
{
FunctionRegistry registry = new FunctionRegistry(new TypeRegistry(), true);
TypeRegistry typeManager = new TypeRegistry();
FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), true);
List<ParametricFunction> functions = registry.list();
List<String> names = transform(functions, input -> input.getSignature().getName());

Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package com.facebook.presto.operator.aggregation;

import com.facebook.presto.block.BlockEncodingManager;
import com.facebook.presto.metadata.FunctionRegistry;
import com.facebook.presto.spi.block.Block;
import com.facebook.presto.spi.block.BlockBuilder;
Expand All @@ -32,7 +33,8 @@

public abstract class AbstractTestAggregationFunction
{
protected final FunctionRegistry functionRegistry = new FunctionRegistry(new TypeRegistry(), true);
protected final TypeRegistry typeRegistry = new TypeRegistry();
protected final FunctionRegistry functionRegistry = new FunctionRegistry(typeRegistry, new BlockEncodingManager(typeRegistry), true);
public abstract Block getSequenceBlock(int start, int length);

protected final InternalAggregationFunction getFunction()
Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package com.facebook.presto.operator.aggregation;

import com.facebook.presto.block.BlockEncodingManager;
import com.facebook.presto.metadata.FunctionRegistry;
import com.facebook.presto.spi.Page;
import com.facebook.presto.spi.PageBuilder;
Expand Down Expand Up @@ -44,7 +45,8 @@ public class TestNumericHistogramAggregation

public TestNumericHistogramAggregation()
{
FunctionRegistry functionRegistry = new FunctionRegistry(new TypeRegistry(), true);
TypeRegistry typeRegistry = new TypeRegistry();
FunctionRegistry functionRegistry = new FunctionRegistry(typeRegistry, new BlockEncodingManager(typeRegistry), true);
InternalAggregationFunction function = functionRegistry.resolveFunction(QualifiedName.of("numeric_histogram"), ImmutableList.of(BIGINT.getTypeSignature(), DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()), false).getAggregationFunction();
factory = function.bind(ImmutableList.of(0, 1, 2), Optional.empty(), Optional.empty(), 1.0);

Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package com.facebook.presto.sql;

import com.facebook.presto.block.BlockEncodingManager;
import com.facebook.presto.metadata.FunctionRegistry;
import com.facebook.presto.metadata.OperatorType;
import com.facebook.presto.metadata.Signature;
Expand All @@ -35,7 +36,7 @@ public class TestExpressionOptimizer
public void testPossibleExponentialOptimizationTime()
{
TypeRegistry typeManager = new TypeRegistry();
ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, false), typeManager, TEST_SESSION);
ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), false), typeManager, TEST_SESSION);
RowExpression expression = new ConstantExpression(1L, BIGINT);
for (int i = 0; i < 100; i++) {
Signature signature = Signature.internalOperator(OperatorType.ADD.name(), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT));
Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package com.facebook.presto.sql;

import com.facebook.presto.block.BlockEncodingManager;
import com.facebook.presto.metadata.FunctionRegistry;
import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.TypeManager;
Expand All @@ -31,7 +32,7 @@
public class TestSqlToRowExpressionTranslator
{
private static final TypeManager TYPE_MANAGER = new TypeRegistry();
private static final FunctionRegistry FUNCTION_REGISTRY = new FunctionRegistry(TYPE_MANAGER, true);
private static final FunctionRegistry FUNCTION_REGISTRY = new FunctionRegistry(TYPE_MANAGER, new BlockEncodingManager(TYPE_MANAGER), true);

@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime()
Expand Down

0 comments on commit 228ddd9

Please sign in to comment.