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));
}
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);
}
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);
}
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());
}
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);
}
Aggregations