Search in sources :

Example 1 with BOOLEAN

use of com.facebook.presto.spi.type.BooleanType.BOOLEAN in project presto by prestodb.

the class TestHashPartitionMaskOperator method testHashPartitionMaskWithMask.

@Test(dataProvider = "hashEnabledValues")
public void testHashPartitionMaskWithMask(boolean hashEnabled) throws Exception {
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT, BOOLEAN, BOOLEAN);
    List<Page> input = rowPagesBuilder.addSequencePage(ROW_COUNT, 0, 0, 1).build();
    OperatorFactory operatorFactory = new HashPartitionMaskOperatorFactory(0, new PlanNodeId("test"), PARTITION_COUNT, rowPagesBuilder.getTypes(), ImmutableList.of(1, 2), ImmutableList.of(0), rowPagesBuilder.getHashChannel());
    int[] rowPartition = new int[ROW_COUNT];
    Arrays.fill(rowPartition, -1);
    for (int partition = 0; partition < PARTITION_COUNT; partition++) {
        MaterializedResult.Builder expected = resultBuilder(TEST_SESSION, BIGINT, BOOLEAN, BOOLEAN, BOOLEAN);
        for (int i = 0; i < ROW_COUNT; i++) {
            long rawHash = BigintOperators.hashCode(i);
            // mix the bits so we don't use the same hash used to distribute between stages
            rawHash = XxHash64.hash(Long.reverse(rawHash));
            rawHash &= Long.MAX_VALUE;
            boolean active = (rawHash % PARTITION_COUNT == partition);
            boolean maskValue = i % 2 == 0;
            expected.row((long) i, active && maskValue, active && !maskValue, active);
            if (active) {
                assertEquals(rowPartition[i], -1);
                rowPartition[i] = partition;
            }
        }
        OperatorAssertion.assertOperatorEqualsIgnoreOrder(operatorFactory, createDriverContext(), input, expected.build(), hashEnabled, Optional.of(3));
    }
    assertTrue(IntStream.of(rowPartition).noneMatch(partition -> partition == -1));
}
Also used : Page(com.facebook.presto.spi.Page) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) BigintOperators(com.facebook.presto.type.BigintOperators) DataProvider(org.testng.annotations.DataProvider) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) BeforeClass(org.testng.annotations.BeforeClass) XxHash64(io.airlift.slice.XxHash64) Ints(com.google.common.primitives.Ints) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) Page(com.facebook.presto.spi.Page) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 2 with BOOLEAN

use of com.facebook.presto.spi.type.BooleanType.BOOLEAN in project presto by prestodb.

the class TestHashPartitionMaskOperator method testHashPartitionMask.

@Test(dataProvider = "hashEnabledValues")
public void testHashPartitionMask(boolean hashEnabled) throws Exception {
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT);
    List<Page> input = rowPagesBuilder.addSequencePage(ROW_COUNT, 0).build();
    OperatorFactory operatorFactory = new HashPartitionMaskOperatorFactory(0, new PlanNodeId("test"), PARTITION_COUNT, rowPagesBuilder.getTypes(), ImmutableList.of(), ImmutableList.of(0), rowPagesBuilder.getHashChannel());
    int[] rowPartition = new int[ROW_COUNT];
    Arrays.fill(rowPartition, -1);
    for (int partition = 0; partition < PARTITION_COUNT; partition++) {
        MaterializedResult.Builder expected = resultBuilder(TEST_SESSION, BIGINT, BOOLEAN);
        for (int i = 0; i < ROW_COUNT; i++) {
            long rawHash = BigintOperators.hashCode(i);
            // mix the bits so we don't use the same hash used to distribute between stages
            rawHash = XxHash64.hash(Long.reverse(rawHash));
            rawHash &= Long.MAX_VALUE;
            boolean active = (rawHash % PARTITION_COUNT == partition);
            expected.row((long) i, active);
            if (active) {
                assertEquals(rowPartition[i], -1);
                rowPartition[i] = partition;
            }
        }
        OperatorAssertion.assertOperatorEqualsIgnoreOrder(operatorFactory, createDriverContext(), input, expected.build(), hashEnabled, Optional.of(1));
    }
    assertTrue(IntStream.of(rowPartition).noneMatch(partition -> partition == -1));
}
Also used : Page(com.facebook.presto.spi.Page) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) BigintOperators(com.facebook.presto.type.BigintOperators) DataProvider(org.testng.annotations.DataProvider) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) BeforeClass(org.testng.annotations.BeforeClass) XxHash64(io.airlift.slice.XxHash64) Ints(com.google.common.primitives.Ints) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) Page(com.facebook.presto.spi.Page) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 3 with BOOLEAN

use of com.facebook.presto.spi.type.BooleanType.BOOLEAN in project presto by prestodb.

the class TestRaptorIntegrationSmokeTest method testTablesSystemTable.

@Test
public void testTablesSystemTable() {
    assertUpdate("" + "CREATE TABLE system_tables_test0 (c00 timestamp, c01 varchar, c02 double, c03 bigint, c04 bigint)");
    assertUpdate("" + "CREATE TABLE system_tables_test1 (c10 timestamp, c11 varchar, c12 double, c13 bigint, c14 bigint) " + "WITH (temporal_column = 'c10')");
    assertUpdate("" + "CREATE TABLE system_tables_test2 (c20 timestamp, c21 varchar, c22 double, c23 bigint, c24 bigint) " + "WITH (temporal_column = 'c20', ordering = ARRAY['c22', 'c21'])");
    assertUpdate("" + "CREATE TABLE system_tables_test3 (c30 timestamp, c31 varchar, c32 double, c33 bigint, c34 bigint) " + "WITH (temporal_column = 'c30', bucket_count = 40, bucketed_on = ARRAY ['c34', 'c33'])");
    assertUpdate("" + "CREATE TABLE system_tables_test4 (c40 timestamp, c41 varchar, c42 double, c43 bigint, c44 bigint) " + "WITH (temporal_column = 'c40', ordering = ARRAY['c41', 'c42'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c43', 'c44'])");
    assertUpdate("" + "CREATE TABLE system_tables_test5 (c50 timestamp, c51 varchar, c52 double, c53 bigint, c54 bigint) " + "WITH (ordering = ARRAY['c51', 'c52'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c53', 'c54'], organized = true)");
    MaterializedResult actualResults = computeActual("SELECT * FROM system.tables");
    assertEquals(actualResults.getTypes(), ImmutableList.builder().add(// table_schema
    VARCHAR).add(// table_name
    VARCHAR).add(// temporal_column
    VARCHAR).add(// ordering_columns
    new ArrayType(VARCHAR)).add(// distribution_name
    VARCHAR).add(// bucket_count
    BIGINT).add(// bucket_columns
    new ArrayType(VARCHAR)).add(// organized
    BOOLEAN).build());
    Map<String, MaterializedRow> map = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).collect(ImmutableCollectors.toImmutableMap(row -> ((String) row.getField(1))));
    assertEquals(map.size(), 6);
    assertEquals(map.get("system_tables_test0").getFields(), asList("tpch", "system_tables_test0", null, null, null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test1").getFields(), asList("tpch", "system_tables_test1", "c10", null, null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test2").getFields(), asList("tpch", "system_tables_test2", "c20", ImmutableList.of("c22", "c21"), null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test3").getFields(), asList("tpch", "system_tables_test3", "c30", null, null, 40L, ImmutableList.of("c34", "c33"), Boolean.FALSE));
    assertEquals(map.get("system_tables_test4").getFields(), asList("tpch", "system_tables_test4", "c40", ImmutableList.of("c41", "c42"), "test_distribution", 50L, ImmutableList.of("c43", "c44"), Boolean.FALSE));
    assertEquals(map.get("system_tables_test5").getFields(), asList("tpch", "system_tables_test5", null, ImmutableList.of("c51", "c52"), "test_distribution", 50L, ImmutableList.of("c53", "c54"), Boolean.TRUE));
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch'");
    long actualRowCount = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).count();
    assertEquals(actualRowCount, 6);
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_name = 'system_tables_test3'");
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    actualResults = computeActual("" + "SELECT distribution_name, bucket_count, bucketing_columns, ordering_columns, temporal_column, organized " + "FROM system.tables " + "WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
    assertEquals(actualResults.getTypes(), ImmutableList.of(VARCHAR, BIGINT, new ArrayType(VARCHAR), new ArrayType(VARCHAR), VARCHAR, BOOLEAN));
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    assertUpdate("DROP TABLE system_tables_test0");
    assertUpdate("DROP TABLE system_tables_test1");
    assertUpdate("DROP TABLE system_tables_test2");
    assertUpdate("DROP TABLE system_tables_test3");
    assertUpdate("DROP TABLE system_tables_test4");
    assertUpdate("DROP TABLE system_tables_test5");
    assertEquals(computeActual("SELECT * FROM system.tables WHERE table_schema IN ('foo', 'bar')").getRowCount(), 0);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) IntStream(java.util.stream.IntStream) RaptorQueryRunner.createRaptorQueryRunner(com.facebook.presto.raptor.RaptorQueryRunner.createRaptorQueryRunner) SHARD_UUID_COLUMN_TYPE(com.facebook.presto.raptor.RaptorColumnHandle.SHARD_UUID_COLUMN_TYPE) Assertions.assertInstanceOf(io.airlift.testing.Assertions.assertInstanceOf) ArrayType(com.facebook.presto.type.ArrayType) Assertions.assertGreaterThan(io.airlift.testing.Assertions.assertGreaterThan) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Assertions.assertLessThan(io.airlift.testing.Assertions.assertLessThan) Assertions.assertGreaterThanOrEqual(io.airlift.testing.Assertions.assertGreaterThanOrEqual) Collectors.toSet(java.util.stream.Collectors.toSet) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Set(java.util.Set) VARCHAR(com.facebook.presto.spi.type.VarcharType.VARCHAR) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) UUID(java.util.UUID) Assert.assertNotNull(org.testng.Assert.assertNotNull) SetMultimap(com.google.common.collect.SetMultimap) String.format(java.lang.String.format) Date(java.sql.Date) MaterializedResult(com.facebook.presto.testing.MaterializedResult) DATE(com.facebook.presto.spi.type.DateType.DATE) MaterializedRow(com.facebook.presto.testing.MaterializedRow) StringJoiner(java.util.StringJoiner) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest) ImmutableCollectors(com.facebook.presto.util.ImmutableCollectors) INTEGER(com.facebook.presto.spi.type.IntegerType.INTEGER) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 4 with BOOLEAN

use of com.facebook.presto.spi.type.BooleanType.BOOLEAN in project presto by prestodb.

the class AbstractGreatestLeast method specialize.

@Override
public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) {
    Type type = boundVariables.getTypeVariable("E");
    checkArgument(type.isOrderable(), "Type must be orderable");
    MethodHandle compareMethod = functionRegistry.getScalarFunctionImplementation(internalOperator(operatorType, BOOLEAN, ImmutableList.of(type, type))).getMethodHandle();
    List<Class<?>> javaTypes = IntStream.range(0, arity).mapToObj(i -> type.getJavaType()).collect(toImmutableList());
    Class<?> clazz = generate(javaTypes, type, compareMethod);
    MethodHandle methodHandle = methodHandle(clazz, getSignature().getName(), javaTypes.toArray(new Class<?>[javaTypes.size()]));
    List<Boolean> nullableParameters = ImmutableList.copyOf(Collections.nCopies(javaTypes.size(), false));
    return new ScalarFunctionImplementation(false, nullableParameters, methodHandle, isDeterministic());
}
Also used : IntStream(java.util.stream.IntStream) MethodHandle(java.lang.invoke.MethodHandle) TypeManager(com.facebook.presto.spi.type.TypeManager) PRIVATE(com.facebook.presto.bytecode.Access.PRIVATE) PrestoException(com.facebook.presto.spi.PrestoException) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeUtils.invoke(com.facebook.presto.sql.gen.BytecodeUtils.invoke) FunctionKind(com.facebook.presto.metadata.FunctionKind) Access.a(com.facebook.presto.bytecode.Access.a) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) ParameterizedType.type(com.facebook.presto.bytecode.ParameterizedType.type) Reflection.methodHandle(com.facebook.presto.util.Reflection.methodHandle) Type(com.facebook.presto.spi.type.Type) Objects.requireNonNull(java.util.Objects.requireNonNull) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) INVALID_FUNCTION_ARGUMENT(com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT) StandardTypes(com.facebook.presto.spi.type.StandardTypes) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode) IfStatement(com.facebook.presto.bytecode.control.IfStatement) PUBLIC(com.facebook.presto.bytecode.Access.PUBLIC) Variable(com.facebook.presto.bytecode.Variable) BoundVariables(com.facebook.presto.metadata.BoundVariables) Signature.orderableTypeParameter(com.facebook.presto.metadata.Signature.orderableTypeParameter) Parameter(com.facebook.presto.bytecode.Parameter) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) Signature(com.facebook.presto.metadata.Signature) Signature.internalOperator(com.facebook.presto.metadata.Signature.internalOperator) DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition) List(java.util.List) CompilerUtils(com.facebook.presto.bytecode.CompilerUtils) FINAL(com.facebook.presto.bytecode.Access.FINAL) STATIC(com.facebook.presto.bytecode.Access.STATIC) Scope(com.facebook.presto.bytecode.Scope) OperatorType(com.facebook.presto.spi.function.OperatorType) CompilerUtils.defineClass(com.facebook.presto.bytecode.CompilerUtils.defineClass) CallSiteBinder(com.facebook.presto.sql.gen.CallSiteBinder) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Collections(java.util.Collections) Parameter.arg(com.facebook.presto.bytecode.Parameter.arg) Type(com.facebook.presto.spi.type.Type) OperatorType(com.facebook.presto.spi.function.OperatorType) CompilerUtils.defineClass(com.facebook.presto.bytecode.CompilerUtils.defineClass) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

BOOLEAN (com.facebook.presto.spi.type.BooleanType.BOOLEAN)4 ImmutableList (com.google.common.collect.ImmutableList)4 IntStream (java.util.stream.IntStream)4 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)3 MaterializedResult (com.facebook.presto.testing.MaterializedResult)3 List (java.util.List)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Test (org.testng.annotations.Test)3 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)2 RowPagesBuilder.rowPagesBuilder (com.facebook.presto.RowPagesBuilder.rowPagesBuilder)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2 HashPartitionMaskOperatorFactory (com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory)2 Page (com.facebook.presto.spi.Page)2 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)2 MaterializedResult.resultBuilder (com.facebook.presto.testing.MaterializedResult.resultBuilder)2 TestingTaskContext.createTaskContext (com.facebook.presto.testing.TestingTaskContext.createTaskContext)2 BigintOperators (com.facebook.presto.type.BigintOperators)2 Ints (com.google.common.primitives.Ints)2 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)2 XxHash64 (io.airlift.slice.XxHash64)2