Search in sources :

Example 91 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestMixedDistinctAggregationOptimizer method testMixedDistinctAggregationOptimizer.

@Test
public void testMixedDistinctAggregationOptimizer() {
    @Language("SQL") String sql = "SELECT custkey, max(totalprice) AS s, count(DISTINCT orderdate) AS d FROM orders GROUP BY custkey";
    String group = "GROUP";
    // Original keys
    String groupBy = "CUSTKEY";
    String aggregate = "TOTALPRICE";
    String distinctAggregation = "ORDERDATE";
    // Second Aggregation data
    List<String> groupByKeysSecond = ImmutableList.of(groupBy);
    Map<Optional<String>, ExpectedValueProvider<FunctionCall>> aggregationsSecond = ImmutableMap.of(Optional.of("arbitrary"), PlanMatchPattern.functionCall("arbitrary", false, ImmutableList.of(anySymbol())), Optional.of("count"), PlanMatchPattern.functionCall("count", false, ImmutableList.of(anySymbol())));
    // First Aggregation data
    List<String> groupByKeysFirst = ImmutableList.of(groupBy, distinctAggregation, group);
    Map<Optional<String>, ExpectedValueProvider<FunctionCall>> aggregationsFirst = ImmutableMap.of(Optional.of("MAX"), functionCall("max", ImmutableList.of("TOTALPRICE")));
    PlanMatchPattern tableScan = tableScan("orders", ImmutableMap.of("TOTALPRICE", "totalprice", "CUSTKEY", "custkey", "ORDERDATE", "orderdate"));
    // GroupingSet symbols
    ImmutableList.Builder<List<String>> groups = ImmutableList.builder();
    groups.add(ImmutableList.of(groupBy, aggregate));
    groups.add(ImmutableList.of(groupBy, distinctAggregation));
    PlanMatchPattern expectedPlanPattern = anyTree(aggregation(ImmutableList.of(groupByKeysSecond), aggregationsSecond, ImmutableMap.of(), Optional.empty(), project(aggregation(ImmutableList.of(groupByKeysFirst), aggregationsFirst, ImmutableMap.of(), Optional.empty(), groupingSet(groups.build(), group, anyTree(tableScan))))));
    assertUnitPlan(sql, expectedPlanPattern);
}
Also used : ExpectedValueProvider(com.facebook.presto.sql.planner.assertions.ExpectedValueProvider) Language(org.intellij.lang.annotations.Language) Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 92 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class AbstractTestHiveFunctions method setup.

@BeforeClass
public void setup() throws Exception {
    // TODO: Use DistributedQueryRunner to perform query
    server = createTestingPrestoServer();
    client = new TestingPrestoClient(server, testSessionBuilder().setTimeZoneKey(TimeZoneKey.getTimeZoneKey("America/Bahia_Banderas")).build());
    typeManager = server.getInstance(Key.get(TypeManager.class));
    if (getInitScript().isPresent()) {
        String sql = Files.asCharSource(getInitScript().get(), UTF_8).read();
        Iterable<String> initQueries = Splitter.on("----\n").omitEmptyStrings().trimResults().split(sql);
        for (@Language("SQL") String query : initQueries) {
            log.debug("Executing %s", query);
            client.execute(query);
        }
    }
}
Also used : TestingPrestoClient(com.facebook.presto.tests.TestingPrestoClient) Language(org.intellij.lang.annotations.Language) BeforeClass(org.testng.annotations.BeforeClass)

Example 93 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestAbstractIcebergSmoke method testPartitionedTableWithNullValues.

private void testPartitionedTableWithNullValues(Session session, FileFormat fileFormat) {
    @Language("SQL") String createTable = "" + "CREATE TABLE test_partitioned_table_with_null_values (" + "  _string VARCHAR" + ", _bigint BIGINT" + ", _integer INTEGER" + ", _real REAL" + ", _double DOUBLE" + ", _boolean BOOLEAN" + ", _decimal_short DECIMAL(3,2)" + ", _decimal_long DECIMAL(30,10)" + ", _date DATE" + ") " + "WITH (" + "format = '" + fileFormat + "', " + "partitioning = ARRAY[" + "  '_string'," + "  '_integer'," + "  '_bigint'," + "  '_boolean'," + "  '_real'," + "  '_double'," + "  '_decimal_short', " + "  '_decimal_long'," + "  '_date']" + ")";
    assertUpdate(session, createTable);
    MaterializedResult result = computeActual("SELECT * from test_partitioned_table_with_null_values");
    assertEquals(result.getRowCount(), 0);
    @Language("SQL") String select = "" + "SELECT" + " null _string" + ", null _bigint" + ", null _integer" + ", null _real" + ", null _double" + ", null _boolean" + ", null _decimal_short" + ", null _decimal_long" + ", null _date";
    assertUpdate(session, "INSERT INTO test_partitioned_table_with_null_values " + select, 1);
    assertQuery(session, "SELECT * from test_partitioned_table_with_null_values", select);
    dropTable(session, "test_partitioned_table_with_null_values");
}
Also used : Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult)

Example 94 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestAbstractIcebergSmoke method testCreateNestedPartitionedTable.

public void testCreateNestedPartitionedTable(Session session, FileFormat fileFormat) {
    @Language("SQL") String createTable = "" + "CREATE TABLE test_nested_table (" + " bool BOOLEAN" + ", int INTEGER" + ", arr ARRAY(VARCHAR)" + ", big BIGINT" + ", rl REAL" + ", dbl DOUBLE" + ", mp MAP(INTEGER, VARCHAR)" + ", dec DECIMAL(5,2)" + ", vc VARCHAR" + ", vb VARBINARY" + ", str ROW(id INTEGER , vc VARCHAR)" + ", dt DATE)" + " WITH (partitioning = ARRAY['int']," + " format = '" + fileFormat + "'" + ")";
    assertUpdate(session, createTable);
    assertUpdate(session, "INSERT INTO test_nested_table " + " select true, 1, array['uno', 'dos', 'tres'], BIGINT '1', REAL '1.0', DOUBLE '1.0', map(array[1,2,3,4], array['ek','don','teen','char'])," + " CAST(1.0 as DECIMAL(5,2))," + " 'one', VARBINARY 'binary0/1values',\n" + " (CAST(ROW(null, 'this is a random value') AS ROW(int, varchar))), current_date", 1);
    MaterializedResult result = computeActual("SELECT * from test_nested_table");
    assertEquals(result.getRowCount(), 1);
    dropTable(session, "test_nested_table");
    @Language("SQL") String createTable2 = "" + "CREATE TABLE test_nested_table (" + " int INTEGER" + ", arr ARRAY(ROW(id INTEGER, vc VARCHAR))" + ", big BIGINT" + ", rl REAL" + ", dbl DOUBLE" + ", mp MAP(INTEGER, ARRAY(VARCHAR))" + ", dec DECIMAL(5,2)" + ", str ROW(id INTEGER, vc VARCHAR, arr ARRAY(INTEGER))" + ", vc VARCHAR)" + " WITH (partitioning = ARRAY['int']," + " format = '" + fileFormat + "'" + ")";
    assertUpdate(session, createTable2);
    assertUpdate(session, "INSERT INTO test_nested_table " + " select 1, array[cast(row(1, null) as row(int, varchar)), cast(row(2, 'dos') as row(int, varchar))], BIGINT '1', REAL '1.0', DOUBLE '1.0', " + "map(array[1,2], array[array['ek', 'one'], array['don', 'do', 'two']]), CAST(1.0 as DECIMAL(5,2)), " + "CAST(ROW(1, 'this is a random value', null) AS ROW(int, varchar, array(int))), 'one'", 1);
    result = computeActual("SELECT * from test_nested_table");
    assertEquals(result.getRowCount(), 1);
    @Language("SQL") String createTable3 = "" + "CREATE TABLE test_nested_table2 WITH (partitioning = ARRAY['int']) as select * from test_nested_table";
    assertUpdate(session, createTable3, 1);
    result = computeActual("SELECT * from test_nested_table2");
    assertEquals(result.getRowCount(), 1);
    dropTable(session, "test_nested_table");
    dropTable(session, "test_nested_table2");
}
Also used : Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult)

Example 95 with Language

use of org.intellij.lang.annotations.Language in project presto by prestodb.

the class TestHiveRecoverableExecution method testRecoverableGroupedExecution.

private void testRecoverableGroupedExecution(DistributedQueryRunner queryRunner, int writerConcurrency, boolean optimizedPartitionUpdateSerializationEnabled, List<String> preQueries, @Language("SQL") String queryWithoutFailure, @Language("SQL") String queryWithFailure, int expectedUpdateCount, List<String> postQueries) throws Exception {
    waitUntilAllNodesAreHealthy(queryRunner, new Duration(10, SECONDS));
    Session recoverableSession = createRecoverableSession(writerConcurrency, optimizedPartitionUpdateSerializationEnabled);
    for (@Language("SQL") String postQuery : postQueries) {
        queryRunner.execute(recoverableSession, postQuery);
    }
    try {
        for (@Language("SQL") String preQuery : preQueries) {
            queryRunner.execute(recoverableSession, preQuery);
        }
        // test no failure case
        Stopwatch noRecoveryStopwatch = Stopwatch.createStarted();
        assertEquals(queryRunner.execute(recoverableSession, queryWithoutFailure).getUpdateCount(), OptionalLong.of(expectedUpdateCount));
        log.info("Query with no recovery took %sms", noRecoveryStopwatch.elapsed(MILLISECONDS));
        // cancel all queries and tasks to make sure we are dealing only with a single running query
        cancelAllQueries(queryRunner);
        cancelAllTasks(queryRunner);
        // test failure case
        Stopwatch recoveryStopwatch = Stopwatch.createStarted();
        ListenableFuture<MaterializedResult> result = executor.submit(() -> queryRunner.execute(recoverableSession, queryWithFailure));
        List<TestingPrestoServer> workers = queryRunner.getServers().stream().filter(server -> !server.isCoordinator()).collect(toList());
        shuffle(workers);
        TestingPrestoServer worker1 = workers.get(0);
        // kill worker1 right away, to make sure recoverable execution works in cases when the task hasn't been yet submitted
        worker1.stopResponding();
        // kill worker2 only after the task has been scheduled
        TestingPrestoServer worker2 = workers.get(1);
        sleep(1000);
        worker2.stopResponding();
        assertEquals(result.get(1000, SECONDS).getUpdateCount(), OptionalLong.of(expectedUpdateCount));
        log.info("Query with recovery took %sms", recoveryStopwatch.elapsed(MILLISECONDS));
    } finally {
        queryRunner.getServers().forEach(TestingPrestoServer::startResponding);
        cancelAllQueries(queryRunner);
        cancelAllTasks(queryRunner);
        for (@Language("SQL") String postQuery : postQueries) {
            queryRunner.execute(recoverableSession, postQuery);
        }
    }
}
Also used : Collections.shuffle(java.util.Collections.shuffle) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Duration(io.airlift.units.Duration) RECOVERABLE_GROUPED_EXECUTION(com.facebook.presto.SystemSessionProperties.RECOVERABLE_GROUPED_EXECUTION) Thread.sleep(java.lang.Thread.sleep) TASK_WRITER_COUNT(com.facebook.presto.SystemSessionProperties.TASK_WRITER_COUNT) EXCHANGE_MATERIALIZATION_STRATEGY(com.facebook.presto.SystemSessionProperties.EXCHANGE_MATERIALIZATION_STRATEGY) TASK_PARTITIONED_WRITER_COUNT(com.facebook.presto.SystemSessionProperties.TASK_PARTITIONED_WRITER_COUNT) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) String.format(java.lang.String.format) List(java.util.List) HASH_PARTITION_COUNT(com.facebook.presto.SystemSessionProperties.HASH_PARTITION_COUNT) CONCURRENT_LIFESPANS_PER_NODE(com.facebook.presto.SystemSessionProperties.CONCURRENT_LIFESPANS_PER_NODE) Optional(java.util.Optional) VIRTUAL_BUCKET_COUNT(com.facebook.presto.hive.HiveSessionProperties.VIRTUAL_BUCKET_COUNT) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) Logger(com.facebook.airlift.log.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DataProvider(org.testng.annotations.DataProvider) TPCH_BUCKETED_SCHEMA(com.facebook.presto.hive.HiveQueryRunner.TPCH_BUCKETED_SCHEMA) Stopwatch(com.google.common.base.Stopwatch) PARTITIONING_PROVIDER_CATALOG(com.facebook.presto.SystemSessionProperties.PARTITIONING_PROVIDER_CATALOG) ALL(com.facebook.presto.spi.security.SelectedRole.Type.ALL) ORDERS(io.airlift.tpch.TpchTable.ORDERS) Assert.assertEquals(org.testng.Assert.assertEquals) ROLE(com.facebook.presto.spi.security.SelectedRole.Type.ROLE) OptionalLong(java.util.OptionalLong) OPTIMIZED_PARTITION_UPDATE_SERIALIZATION_ENABLED(com.facebook.presto.hive.HiveSessionProperties.OPTIMIZED_PARTITION_UPDATE_SERIALIZATION_ENABLED) ImmutableList(com.google.common.collect.ImmutableList) Identity(com.facebook.presto.spi.security.Identity) GROUPED_EXECUTION(com.facebook.presto.SystemSessionProperties.GROUPED_EXECUTION) AfterClass(org.testng.annotations.AfterClass) SelectedRole(com.facebook.presto.spi.security.SelectedRole) HIVE_CATALOG(com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) MAX_STAGE_RETRIES(com.facebook.presto.SystemSessionProperties.MAX_STAGE_RETRIES) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) AllNodes(com.facebook.presto.metadata.AllNodes) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Collectors.toList(java.util.stream.Collectors.toList) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) COLOCATED_JOIN(com.facebook.presto.SystemSessionProperties.COLOCATED_JOIN) REDISTRIBUTE_WRITES(com.facebook.presto.SystemSessionProperties.REDISTRIBUTE_WRITES) SECONDS(java.util.concurrent.TimeUnit.SECONDS) SCALE_WRITERS(com.facebook.presto.SystemSessionProperties.SCALE_WRITERS) Language(org.intellij.lang.annotations.Language) Stopwatch(com.google.common.base.Stopwatch) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) Duration(io.airlift.units.Duration) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session)

Aggregations

Language (org.intellij.lang.annotations.Language)111 TableMetadata (com.facebook.presto.metadata.TableMetadata)25 Test (org.testng.annotations.Test)24 MaterializedResult (com.facebook.presto.testing.MaterializedResult)19 PsiFile (com.intellij.psi.PsiFile)18 MaterializedRow (com.facebook.presto.testing.MaterializedRow)11 List (java.util.List)11 Optional (java.util.Optional)11 Test (org.junit.Test)11 ImmutableList (com.google.common.collect.ImmutableList)10 Session (com.facebook.presto.Session)9 Constraint (com.facebook.presto.spi.Constraint)9 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)9 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)8 ColumnConstraint (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)7 ExpectedValueProvider (com.facebook.presto.sql.planner.assertions.ExpectedValueProvider)7 PlanMatchPattern (com.facebook.presto.sql.planner.assertions.PlanMatchPattern)7 SortOrder (com.facebook.presto.common.block.SortOrder)6