Search in sources :

Example 36 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestDeterminismEvaluator method testDeterminismEvaluator.

@Test
public void testDeterminismEvaluator() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    RowExpressionDeterminismEvaluator determinismEvaluator = new RowExpressionDeterminismEvaluator(functionAndTypeManager);
    CallExpression random = new CallExpression("random", functionAndTypeManager.lookupFunction("random", fromTypes(BIGINT)), BIGINT, singletonList(constant(10L, BIGINT)));
    assertFalse(determinismEvaluator.isDeterministic(random));
    InputReferenceExpression col0 = field(0, BIGINT);
    FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
    CallExpression lessThanExpression = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(col0, constant(10L, BIGINT)));
    assertTrue(determinismEvaluator.isDeterministic(lessThanExpression));
    CallExpression lessThanRandomExpression = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(col0, random));
    assertFalse(determinismEvaluator.isDeterministic(lessThanRandomExpression));
}
Also used : InputReferenceExpression(com.facebook.presto.spi.relation.InputReferenceExpression) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) CallExpression(com.facebook.presto.spi.relation.CallExpression) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Example 37 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestFunctionResolution method setup.

@BeforeClass
public void setup() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    functionResolution = new FunctionResolution(functionAndTypeManager);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) StandardFunctionResolution(com.facebook.presto.spi.function.StandardFunctionResolution) BeforeClass(org.testng.annotations.BeforeClass)

Example 38 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class JsonToRowCast method specialize.

@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    checkArgument(arity == 1, "Expected arity to be 1");
    RowType rowType = (RowType) boundVariables.getTypeVariable("T");
    checkCondition(canCastFromJson(rowType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", rowType);
    List<Field> rowFields = rowType.getFields();
    BlockBuilderAppender[] fieldAppenders = rowFields.stream().map(rowField -> createBlockBuilderAppender(rowField.getType())).toArray(BlockBuilderAppender[]::new);
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(rowType).bindTo(fieldAppenders).bindTo(getFieldNameToIndex(rowFields));
    return new BuiltInScalarFunctionImplementation(true, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) MethodHandle(java.lang.invoke.MethodHandle) StandardTypes(com.facebook.presto.common.type.StandardTypes) Slice(io.airlift.slice.Slice) Field(com.facebook.presto.common.type.RowType.Field) BlockBuilderAppender.createBlockBuilderAppender(com.facebook.presto.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender) SqlOperator(com.facebook.presto.metadata.SqlOperator) SingleRowBlockWriter(com.facebook.presto.common.block.SingleRowBlockWriter) PrestoException(com.facebook.presto.spi.PrestoException) JsonUtil.canCastFromJson(com.facebook.presto.util.JsonUtil.canCastFromJson) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Reflection.methodHandle(com.facebook.presto.util.Reflection.methodHandle) START_OBJECT(com.fasterxml.jackson.core.JsonToken.START_OBJECT) Map(java.util.Map) JsonUtil.createJsonParser(com.facebook.presto.util.JsonUtil.createJsonParser) JsonToken(com.fasterxml.jackson.core.JsonToken) BlockBuilderAppender(com.facebook.presto.util.JsonUtil.BlockBuilderAppender) RETURN_NULL_ON_NULL(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.RETURN_NULL_ON_NULL) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode) Failures.checkCondition(com.facebook.presto.util.Failures.checkCondition) JsonUtil.parseJsonToSingleRowBlock(com.facebook.presto.util.JsonUtil.parseJsonToSingleRowBlock) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) BoundVariables(com.facebook.presto.metadata.BoundVariables) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonCastException(com.facebook.presto.util.JsonCastException) SqlFunctionProperties(com.facebook.presto.common.function.SqlFunctionProperties) INVALID_CAST_ARGUMENT(com.facebook.presto.spi.StandardErrorCode.INVALID_CAST_ARGUMENT) JsonUtil.truncateIfNecessaryForErrorMessage(com.facebook.presto.util.JsonUtil.truncateIfNecessaryForErrorMessage) OperatorType(com.facebook.presto.common.function.OperatorType) JsonUtil.getFieldNameToIndex(com.facebook.presto.util.JsonUtil.getFieldNameToIndex) String.format(java.lang.String.format) ArgumentProperty.valueTypeArgumentProperty(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty.valueTypeArgumentProperty) List(java.util.List) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) START_ARRAY(com.fasterxml.jackson.core.JsonToken.START_ARRAY) Optional(java.util.Optional) Signature.withVariadicBound(com.facebook.presto.spi.function.Signature.withVariadicBound) JSON_FACTORY(com.facebook.presto.util.JsonUtil.JSON_FACTORY) Block(com.facebook.presto.common.block.Block) RowType(com.facebook.presto.common.type.RowType) Field(com.facebook.presto.common.type.RowType.Field) BlockBuilderAppender.createBlockBuilderAppender(com.facebook.presto.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender) BlockBuilderAppender(com.facebook.presto.util.JsonUtil.BlockBuilderAppender) RowType(com.facebook.presto.common.type.RowType) MethodHandle(java.lang.invoke.MethodHandle)

Example 39 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestCreateMaterializedViewTask method setUp.

@BeforeMethod
public void setUp() {
    CatalogManager catalogManager = new CatalogManager();
    Catalog testCatalog = createBogusTestingCatalog(CATALOG_NAME);
    catalogManager.registerCatalog(testCatalog);
    TablePropertyManager tablePropertyManager = new TablePropertyManager();
    tablePropertyManager.addProperties(testCatalog.getConnectorId(), ImmutableList.of(stringProperty("baz", "test property", null, false)));
    ColumnPropertyManager columnPropertyManager = new ColumnPropertyManager();
    columnPropertyManager.addProperties(testCatalog.getConnectorId(), ImmutableList.of());
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    transactionManager = createTestTransactionManager(catalogManager);
    testSession = testSessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    accessControl = new AllowAllAccessControl();
    executorService = newCachedThreadPool(daemonThreadsNamed("test-%s"));
    metadata = new MockMetadata(functionAndTypeManager, tablePropertyManager, columnPropertyManager, testCatalog.getConnectorId());
}
Also used : ColumnPropertyManager(com.facebook.presto.metadata.ColumnPropertyManager) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AbstractMockMetadata(com.facebook.presto.metadata.AbstractMockMetadata) TablePropertyManager(com.facebook.presto.metadata.TablePropertyManager) CatalogManager(com.facebook.presto.metadata.CatalogManager) Catalog(com.facebook.presto.metadata.Catalog) TestingSession.createBogusTestingCatalog(com.facebook.presto.testing.TestingSession.createBogusTestingCatalog) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 40 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestInCodeGenerator method testInteger.

@Test
public void testInteger() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    List<RowExpression> values = new ArrayList<>();
    values.add(constant((long) Integer.MIN_VALUE, INTEGER));
    values.add(constant((long) Integer.MAX_VALUE, INTEGER));
    values.add(constant(3L, INTEGER));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    values.add(constant(null, INTEGER));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    values.add(new CallExpression(CAST.name(), functionAndTypeManager.lookupCast(CAST, DOUBLE.getTypeSignature(), INTEGER.getTypeSignature()), INTEGER, Collections.singletonList(constant(12345678901234.0, DOUBLE))));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    for (int i = 6; i <= 32; ++i) {
        values.add(constant((long) i, INTEGER));
    }
    assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
    values.add(constant(33L, INTEGER));
    assertEquals(checkSwitchGenerationCase(INTEGER, values), SET_CONTAINS);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) ArrayList(java.util.ArrayList) RowExpression(com.facebook.presto.spi.relation.RowExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Aggregations

FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)62 Test (org.testng.annotations.Test)31 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)26 Type (com.facebook.presto.common.type.Type)24 RowExpression (com.facebook.presto.spi.relation.RowExpression)13 ImmutableList (com.google.common.collect.ImmutableList)13 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)12 CallExpression (com.facebook.presto.spi.relation.CallExpression)12 Block (com.facebook.presto.common.block.Block)11 ArrayType (com.facebook.presto.common.type.ArrayType)11 Optional (java.util.Optional)11 BeforeClass (org.testng.annotations.BeforeClass)11 Page (com.facebook.presto.common.Page)10 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)10 List (java.util.List)10 DBI (org.skife.jdbi.v2.DBI)8 Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)6 JsonBinder.jsonBinder (com.facebook.airlift.json.JsonBinder.jsonBinder)6 JsonCodecBinder.jsonCodecBinder (com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder)6 JsonModule (com.facebook.airlift.json.JsonModule)6