use of com.facebook.presto.metadata.TableMetadata 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 com.facebook.presto.metadata.TableMetadata in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method createTableLike.
protected void createTableLike(String likeSuffix, boolean hasPartition) throws Exception {
// Create a non-partitioned table
@Language("SQL") String createTable = "" + "CREATE TABLE test_table_original (" + " tinyint_col tinyint " + ", smallint_col smallint" + ")";
assertUpdate(createTable);
// Verify the table is correctly created
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_table_original");
assertColumnType(tableMetadata, "tinyint_col", TINYINT);
assertColumnType(tableMetadata, "smallint_col", SMALLINT);
// Create a partitioned table
@Language("SQL") String createPartitionedTable = "" + "CREATE TABLE test_partitioned_table_original (" + " string_col VARCHAR" + ", decimal_long_col DECIMAL(30,10)" + ", partition_bigint BIGINT" + ", partition_decimal_long DECIMAL(30,10)" + ") " + "WITH (" + "partitioned_by = ARRAY['partition_bigint', 'partition_decimal_long']" + ")";
assertUpdate(createPartitionedTable);
// Verify the table is correctly created
tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_partitioned_table_original");
// Verify the partition keys are correctly created
List<String> partitionedBy = ImmutableList.of("partition_bigint", "partition_decimal_long");
assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), partitionedBy);
// Verify the column types
assertColumnType(tableMetadata, "string_col", createUnboundedVarcharType());
assertColumnType(tableMetadata, "partition_bigint", BIGINT);
assertColumnType(tableMetadata, "partition_decimal_long", createDecimalType(30, 10));
// Create a table using only one LIKE
@Language("SQL") String createTableSingleLike = "" + "CREATE TABLE test_partitioned_table_single_like (" + "LIKE test_partitioned_table_original " + likeSuffix + ")";
assertUpdate(createTableSingleLike);
tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_partitioned_table_single_like");
// Verify the partitioned keys are correctly created if copying partition columns
verifyPartition(hasPartition, tableMetadata, partitionedBy);
// Verify the column types
assertColumnType(tableMetadata, "string_col", createUnboundedVarcharType());
assertColumnType(tableMetadata, "partition_bigint", BIGINT);
assertColumnType(tableMetadata, "partition_decimal_long", createDecimalType(30, 10));
@Language("SQL") String createTableLikeExtra = "" + "CREATE TABLE test_partitioned_table_like_extra (" + " bigint_col BIGINT" + ", double_col DOUBLE" + ", LIKE test_partitioned_table_single_like " + likeSuffix + ")";
assertUpdate(createTableLikeExtra);
tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_partitioned_table_like_extra");
// Verify the partitioned keys are correctly created if copying partition columns
verifyPartition(hasPartition, tableMetadata, partitionedBy);
// Verify the column types
assertColumnType(tableMetadata, "bigint_col", BIGINT);
assertColumnType(tableMetadata, "double_col", DOUBLE);
assertColumnType(tableMetadata, "string_col", createUnboundedVarcharType());
assertColumnType(tableMetadata, "partition_bigint", BIGINT);
assertColumnType(tableMetadata, "partition_decimal_long", createDecimalType(30, 10));
@Language("SQL") String createTableDoubleLike = "" + "CREATE TABLE test_partitioned_table_double_like (" + " LIKE test_table_original " + ", LIKE test_partitioned_table_like_extra " + likeSuffix + ")";
assertUpdate(createTableDoubleLike);
tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_partitioned_table_double_like");
// Verify the partitioned keys are correctly created if copying partition columns
verifyPartition(hasPartition, tableMetadata, partitionedBy);
// Verify the column types
assertColumnType(tableMetadata, "tinyint_col", TINYINT);
assertColumnType(tableMetadata, "smallint_col", SMALLINT);
assertColumnType(tableMetadata, "string_col", createUnboundedVarcharType());
assertColumnType(tableMetadata, "partition_bigint", BIGINT);
assertColumnType(tableMetadata, "partition_decimal_long", createDecimalType(30, 10));
assertUpdate("DROP TABLE test_table_original");
assertUpdate("DROP TABLE test_partitioned_table_original");
assertUpdate("DROP TABLE test_partitioned_table_single_like");
assertUpdate("DROP TABLE test_partitioned_table_like_extra");
assertUpdate("DROP TABLE test_partitioned_table_double_like");
}
use of com.facebook.presto.metadata.TableMetadata 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"));
}
Aggregations