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