use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testInsertPartitionedTableShuffleOnPartitionColumns.
public void testInsertPartitionedTableShuffleOnPartitionColumns(Session session, HiveStorageFormat storageFormat) {
String tableName = "test_insert_partitioned_table_shuffle_on_partition_columns";
@Language("SQL") String createTable = "" + "CREATE TABLE " + tableName + " " + "(" + " order_key BIGINT," + " comment VARCHAR," + " order_status VARCHAR" + ") " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ 'order_status' ]" + ") ";
assertUpdate(session, createTable);
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, tableName);
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("order_status"));
assertUpdate(session, "INSERT INTO " + tableName + " " + "SELECT orderkey, comment, orderstatus " + "FROM tpch.tiny.orders", "SELECT count(*) from orders");
// verify the partitions
List<?> partitions = getPartitions(tableName);
assertEquals(partitions.size(), 3);
assertQuery(session, "SELECT * from " + tableName, "SELECT orderkey, comment, orderstatus FROM orders");
assertQuery(session, "SELECT count(distinct \"$path\") from " + tableName, "SELECT 3");
assertUpdate(session, "DROP TABLE " + tableName);
assertFalse(getQueryRunner().tableExists(session, tableName));
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testFileSizeHiddenColumn.
@Test
public void testFileSizeHiddenColumn() {
@Language("SQL") String createTable = "CREATE TABLE test_file_size " + "AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
assertUpdate(createTable, 8);
assertTrue(getQueryRunner().tableExists(getSession(), "test_file_size"));
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_file_size");
List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, FILE_SIZE_COLUMN_NAME, FILE_MODIFIED_TIME_COLUMN_NAME);
List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
assertEquals(columnMetadatas.size(), columnNames.size());
for (int i = 0; i < columnMetadatas.size(); i++) {
ColumnMetadata columnMetadata = columnMetadatas.get(i);
assertEquals(columnMetadata.getName(), columnNames.get(i));
if (columnMetadata.getName().equals(FILE_SIZE_COLUMN_NAME)) {
assertTrue(columnMetadata.isHidden());
}
}
MaterializedResult results = computeActual(format("SELECT *, \"%s\" FROM test_file_size", FILE_SIZE_COLUMN_NAME));
Map<Integer, Long> fileSizeMap = new HashMap<>();
for (int i = 0; i < results.getRowCount(); i++) {
MaterializedRow row = results.getMaterializedRows().get(i);
int col0 = (int) row.getField(0);
int col1 = (int) row.getField(1);
long fileSize = (Long) row.getField(2);
assertTrue(fileSize > 0);
assertEquals(col0 % 3, col1);
if (fileSizeMap.containsKey(col1)) {
assertEquals(fileSizeMap.get(col1).longValue(), fileSize);
} else {
fileSizeMap.put(col1, fileSize);
}
}
assertEquals(fileSizeMap.size(), 3);
assertUpdate("DROP TABLE test_file_size");
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testMismatchedBucketWithBucketPredicate.
@Test
public void testMismatchedBucketWithBucketPredicate() {
try {
assertUpdate("CREATE TABLE test_mismatch_bucketing_with_predicate_8\n" + "WITH (bucket_count = 8, bucketed_by = ARRAY['key8']) AS\n" + "SELECT custkey key8, comment value8 FROM orders", 15000);
assertUpdate("CREATE TABLE test_mismatch_bucketing_with_predicate_32\n" + "WITH (bucket_count = 32, bucketed_by = ARRAY['key32']) AS\n" + "SELECT custkey key32, comment value32 FROM orders", 15000);
Session withMismatchOptimization = Session.builder(getSession()).setSystemProperty(COLOCATED_JOIN, "true").setCatalogSessionProperty(catalog, "optimize_mismatched_bucket_count", "true").build();
Session withoutMismatchOptimization = Session.builder(getSession()).setSystemProperty(COLOCATED_JOIN, "true").setCatalogSessionProperty(catalog, "optimize_mismatched_bucket_count", "false").build();
@Language("SQL") String query = "SELECT count(*) AS count\n" + "FROM (\n" + " SELECT key32\n" + " FROM test_mismatch_bucketing_with_predicate_32\n" + " WHERE \"$bucket\" between 16 AND 31\n" + ") a\n" + "JOIN test_mismatch_bucketing_with_predicate_8 b\n" + "ON a.key32 = b.key8";
assertQuery(withMismatchOptimization, query, "SELECT 130361");
assertQuery(withoutMismatchOptimization, query, "SELECT 130361");
} finally {
assertUpdate("DROP TABLE IF EXISTS test_mismatch_bucketing_with_predicate_8");
assertUpdate("DROP TABLE IF EXISTS test_mismatch_bucketing_with_predicate_32");
}
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class AbstractTestHiveFunctions method assertQuery.
public void assertQuery(@Language("SQL") String sql, Column... cols) {
checkArgument(cols != null && cols.length > 0);
int numColumns = cols.length;
int numRows = cols[0].values.length;
checkArgument(Stream.of(cols).allMatch(c -> c != null && c.values.length == numRows));
MaterializedResult result = client.execute(sql).getResult();
assertEquals(result.getRowCount(), numRows);
for (int i = 0; i < numColumns; i++) {
assertEquals(result.getTypes().get(i), cols[i].type);
}
List<MaterializedRow> rows = result.getMaterializedRows();
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numColumns; j++) {
Object actual = rows.get(i).getField(j);
Object expected = cols[j].values[i];
if (cols[j].type == DOUBLE) {
assertEquals(((Number) actual).doubleValue(), ((double) expected), 0.000001);
} else {
assertEquals(actual, expected);
}
}
}
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestEliminateSorts method testEliminateSorts.
@Test
public void testEliminateSorts() {
@Language("SQL") String sql = "SELECT quantity, row_number() OVER (ORDER BY quantity) FROM lineitem ORDER BY quantity";
PlanMatchPattern pattern = output(window(windowMatcherBuilder -> windowMatcherBuilder.specification(windowSpec).addFunction(functionCall("row_number", Optional.empty(), ImmutableList.of())), anyTree(LINEITEM_TABLESCAN_Q)));
assertUnitPlan(sql, pattern);
}
Aggregations