use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method doTestPathHiddenColumn.
private void doTestPathHiddenColumn(Session session, HiveStorageFormat storageFormat) {
@Language("SQL") String createTable = "CREATE TABLE test_path " + "WITH (" + "format = '" + storageFormat + "'," + "partitioned_by = ARRAY['col1']" + ") AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
assertUpdate(session, createTable, 8);
assertTrue(getQueryRunner().tableExists(getSession(), "test_path"));
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_path");
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
List<String> columnNames = ImmutableList.of("col0", "col1", PATH_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(PATH_COLUMN_NAME)) {
// $path should be hidden column
assertTrue(columnMetadata.isHidden());
}
}
assertEquals(getPartitions("test_path").size(), 3);
MaterializedResult results = computeActual(session, format("SELECT *, \"%s\" FROM test_path", PATH_COLUMN_NAME));
Map<Integer, String> partitionPathMap = 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);
String pathName = (String) row.getField(2);
String parentDirectory = new Path(pathName).getParent().toString();
assertTrue(pathName.length() > 0);
assertEquals((int) (col0 % 3), col1);
if (partitionPathMap.containsKey(col1)) {
// the rows in the same partition should be in the same partition directory
assertEquals(partitionPathMap.get(col1), parentDirectory);
} else {
partitionPathMap.put(col1, parentDirectory);
}
}
assertEquals(partitionPathMap.size(), 3);
assertUpdate(session, "DROP TABLE test_path");
assertFalse(getQueryRunner().tableExists(session, "test_path"));
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method createPartitionedTable.
public void createPartitionedTable(Session session, HiveStorageFormat storageFormat) throws Exception {
@Language("SQL") String createTable = "" + "CREATE TABLE test_partitioned_table (" + " _string VARCHAR" + ", _varchar VARCHAR(65535)" + ", _char CHAR(10)" + ", _bigint BIGINT" + ", _integer INTEGER" + ", _smallint SMALLINT" + ", _tinyint TINYINT" + ", _real REAL" + ", _double DOUBLE" + ", _boolean BOOLEAN" + ", _decimal_short DECIMAL(3,2)" + ", _decimal_long DECIMAL(30,10)" + ", _partition_string VARCHAR" + ", _partition_varchar VARCHAR(65535)" + ", _partition_char CHAR(10)" + ", _partition_tinyint TINYINT" + ", _partition_smallint SMALLINT" + ", _partition_integer INTEGER" + ", _partition_bigint BIGINT" + ", _partition_decimal_short DECIMAL(3,2)" + ", _partition_decimal_long DECIMAL(30,10)" + ") " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ '_partition_string', '_partition_varchar', '_partition_char', '_partition_tinyint', '_partition_smallint', '_partition_integer', '_partition_bigint', '_partition_decimal_short', '_partition_decimal_long' ]" + ") ";
if (storageFormat == HiveStorageFormat.AVRO) {
createTable = createTable.replace(" _smallint SMALLINT,", " _smallint INTEGER,");
createTable = createTable.replace(" _tinyint TINYINT,", " _tinyint INTEGER,");
}
assertUpdate(session, createTable);
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_partitioned_table");
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
List<String> partitionedBy = ImmutableList.of("_partition_string", "_partition_varchar", "_partition_char", "_partition_tinyint", "_partition_smallint", "_partition_integer", "_partition_bigint", "_partition_decimal_short", "_partition_decimal_long");
assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), partitionedBy);
for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
boolean partitionKey = partitionedBy.contains(columnMetadata.getName());
assertEquals(columnMetadata.getExtraInfo(), columnExtraInfo(partitionKey));
}
assertColumnType(tableMetadata, "_string", createUnboundedVarcharType());
assertColumnType(tableMetadata, "_varchar", createVarcharType(65535));
assertColumnType(tableMetadata, "_char", createCharType(10));
assertColumnType(tableMetadata, "_partition_string", createUnboundedVarcharType());
assertColumnType(tableMetadata, "_partition_varchar", createVarcharType(65535));
MaterializedResult result = computeActual("SELECT * from test_partitioned_table");
assertEquals(result.getRowCount(), 0);
@Language("SQL") String select = "" + "SELECT" + " 'foo' _string" + ", 'bar' _varchar" + ", CAST('boo' AS CHAR(10)) _char" + ", CAST(1 AS BIGINT) _bigint" + ", 2 _integer" + ", CAST (3 AS SMALLINT) _smallint" + ", CAST (4 AS TINYINT) _tinyint" + ", CAST('123.45' AS REAL) _real" + ", CAST('3.14' AS DOUBLE) _double" + ", true _boolean" + ", CAST('3.14' AS DECIMAL(3,2)) _decimal_short" + ", CAST('12345678901234567890.0123456789' AS DECIMAL(30,10)) _decimal_long" + ", 'foo' _partition_string" + ", 'bar' _partition_varchar" + ", CAST('boo' AS CHAR(10)) _partition_char" + ", CAST(1 AS TINYINT) _partition_tinyint" + ", CAST(1 AS SMALLINT) _partition_smallint" + ", 1 _partition_integer" + ", CAST (1 AS BIGINT) _partition_bigint" + ", CAST('3.14' AS DECIMAL(3,2)) _partition_decimal_short" + ", CAST('12345678901234567890.0123456789' AS DECIMAL(30,10)) _partition_decimal_long";
if (storageFormat == HiveStorageFormat.AVRO) {
select = select.replace(" CAST (3 AS SMALLINT) _smallint,", " 3 _smallint,");
select = select.replace(" CAST (4 AS TINYINT) _tinyint,", " 4 _tinyint,");
}
assertUpdate(session, "INSERT INTO test_partitioned_table " + select, 1);
assertQuery(session, "SELECT * from test_partitioned_table", select);
assertUpdate(session, "DROP TABLE test_partitioned_table");
assertFalse(getQueryRunner().tableExists(session, "test_partitioned_table"));
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method createTableAs.
public void createTableAs(Session session, HiveStorageFormat storageFormat) throws Exception {
@Language("SQL") String select = "SELECT" + " 'foo' _varchar" + ", CAST('bar' AS CHAR(10)) _char" + ", CAST (1 AS BIGINT) _bigint" + ", 2 _integer" + ", CAST (3 AS SMALLINT) _smallint" + ", CAST (4 AS TINYINT) _tinyint" + ", CAST ('123.45' as REAL) _real" + ", CAST('3.14' AS DOUBLE) _double" + ", true _boolean" + ", CAST('3.14' AS DECIMAL(3,2)) _decimal_short" + ", CAST('12345678901234567890.0123456789' AS DECIMAL(30,10)) _decimal_long";
if (storageFormat == HiveStorageFormat.AVRO) {
select = select.replace(" CAST (3 AS SMALLINT) _smallint,", " 3 _smallint,");
select = select.replace(" CAST (4 AS TINYINT) _tinyint,", " 4 _tinyint,");
}
String createTableAs = format("CREATE TABLE test_format_table WITH (format = '%s') AS %s", storageFormat, select);
assertUpdate(session, createTableAs, 1);
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_format_table");
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
assertColumnType(tableMetadata, "_varchar", createVarcharType(3));
assertColumnType(tableMetadata, "_char", createCharType(10));
// assure reader supports basic column reordering and pruning
assertQuery(session, "SELECT _integer, _varchar, _integer from test_format_table", "SELECT 2, 'foo', 2");
assertQuery(session, "SELECT * from test_format_table", select);
assertUpdate(session, "DROP TABLE test_format_table");
assertFalse(getQueryRunner().tableExists(session, "test_format_table"));
}
use of org.intellij.lang.annotations.Language in project presto by prestodb.
the class TestRaptorIntegrationSmokeTest method testTableStatsSystemTable.
@SuppressWarnings("OverlyStrongTypeCast")
@Test
public void testTableStatsSystemTable() throws Exception {
// basic sanity tests
assertQuery("" + "SELECT table_schema, table_name, sum(row_count)\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + " AND table_name IN ('orders', 'lineitem')\n" + "GROUP BY 1, 2", "" + "SELECT 'tpch', 'orders', (SELECT count(*) FROM orders)\n" + "UNION ALL\n" + "SELECT 'tpch', 'lineitem', (SELECT count(*) FROM lineitem)");
assertQuery("" + "SELECT\n" + " bool_and(row_count >= shard_count)\n" + ", bool_and(update_time >= create_time)\n" + ", bool_and(table_version >= 1)\n" + "FROM system.table_stats\n" + "WHERE row_count > 0", "SELECT true, true, true");
// create empty table
assertUpdate("CREATE TABLE test_table_stats (x bigint)");
@Language("SQL") String sql = "" + "SELECT create_time, update_time, table_version," + " shard_count, row_count, uncompressed_size\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + " AND table_name = 'test_table_stats'";
MaterializedRow row = getOnlyElement(computeActual(sql).getMaterializedRows());
Timestamp createTime = (Timestamp) row.getField(0);
Timestamp updateTime1 = (Timestamp) row.getField(1);
assertEquals(createTime, updateTime1);
// table_version
assertEquals(row.getField(2), 1L);
// shard_count
assertEquals(row.getField(3), 0L);
// row_count
assertEquals(row.getField(4), 0L);
// uncompressed_size
long size1 = (long) row.getField(5);
// insert
assertUpdate("INSERT INTO test_table_stats VALUES (1), (2), (3), (4)", 4);
row = getOnlyElement(computeActual(sql).getMaterializedRows());
assertEquals(row.getField(0), createTime);
Timestamp updateTime2 = (Timestamp) row.getField(1);
assertLessThan(updateTime1, updateTime2);
// table_version
assertEquals(row.getField(2), 2L);
// shard_count
assertGreaterThanOrEqual((Long) row.getField(3), 1L);
// row_count
assertEquals(row.getField(4), 4L);
// uncompressed_size
long size2 = (long) row.getField(5);
assertGreaterThan(size2, size1);
// delete
assertUpdate("DELETE FROM test_table_stats WHERE x IN (2, 4)", 2);
row = getOnlyElement(computeActual(sql).getMaterializedRows());
assertEquals(row.getField(0), createTime);
Timestamp updateTime3 = (Timestamp) row.getField(1);
assertLessThan(updateTime2, updateTime3);
// table_version
assertEquals(row.getField(2), 3L);
// shard_count
assertGreaterThanOrEqual((Long) row.getField(3), 1L);
// row_count
assertEquals(row.getField(4), 2L);
// uncompressed_Size
long size3 = (long) row.getField(5);
assertLessThan(size3, size2);
// add column
assertUpdate("ALTER TABLE test_table_stats ADD COLUMN y bigint");
row = getOnlyElement(computeActual(sql).getMaterializedRows());
assertEquals(row.getField(0), createTime);
assertLessThan(updateTime3, (Timestamp) row.getField(1));
// table_version
assertEquals(row.getField(2), 4L);
// row_count
assertEquals(row.getField(4), 2L);
// uncompressed_size
assertEquals(row.getField(5), size3);
// cleanup
assertUpdate("DROP TABLE test_table_stats");
}
use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class XmlBuilderTest method toStringNoClosePreviousTagWithoutAttributes.
@Test
public void toStringNoClosePreviousTagWithoutAttributes() {
@Language("XML") String expected = "<Foo>\n\n" + " <Bar />\n" + "</Foo>\n";
// @formatter:off
String actual = new XmlBuilder().startTag("Foo").startTag("Bar").endTag("Bar").endTag("Foo").toString();
// @formatter:on
assertEquals(expected, actual);
}
Aggregations