Search in sources :

Example 1 with VARCHAR

use of com.facebook.presto.spi.type.VarcharType.VARCHAR in project presto by prestodb.

the class TestRaptorIntegrationSmokeTest method testTablesSystemTable.

@Test
public void testTablesSystemTable() {
    assertUpdate("" + "CREATE TABLE system_tables_test0 (c00 timestamp, c01 varchar, c02 double, c03 bigint, c04 bigint)");
    assertUpdate("" + "CREATE TABLE system_tables_test1 (c10 timestamp, c11 varchar, c12 double, c13 bigint, c14 bigint) " + "WITH (temporal_column = 'c10')");
    assertUpdate("" + "CREATE TABLE system_tables_test2 (c20 timestamp, c21 varchar, c22 double, c23 bigint, c24 bigint) " + "WITH (temporal_column = 'c20', ordering = ARRAY['c22', 'c21'])");
    assertUpdate("" + "CREATE TABLE system_tables_test3 (c30 timestamp, c31 varchar, c32 double, c33 bigint, c34 bigint) " + "WITH (temporal_column = 'c30', bucket_count = 40, bucketed_on = ARRAY ['c34', 'c33'])");
    assertUpdate("" + "CREATE TABLE system_tables_test4 (c40 timestamp, c41 varchar, c42 double, c43 bigint, c44 bigint) " + "WITH (temporal_column = 'c40', ordering = ARRAY['c41', 'c42'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c43', 'c44'])");
    assertUpdate("" + "CREATE TABLE system_tables_test5 (c50 timestamp, c51 varchar, c52 double, c53 bigint, c54 bigint) " + "WITH (ordering = ARRAY['c51', 'c52'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c53', 'c54'], organized = true)");
    MaterializedResult actualResults = computeActual("SELECT * FROM system.tables");
    assertEquals(actualResults.getTypes(), ImmutableList.builder().add(// table_schema
    VARCHAR).add(// table_name
    VARCHAR).add(// temporal_column
    VARCHAR).add(// ordering_columns
    new ArrayType(VARCHAR)).add(// distribution_name
    VARCHAR).add(// bucket_count
    BIGINT).add(// bucket_columns
    new ArrayType(VARCHAR)).add(// organized
    BOOLEAN).build());
    Map<String, MaterializedRow> map = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).collect(ImmutableCollectors.toImmutableMap(row -> ((String) row.getField(1))));
    assertEquals(map.size(), 6);
    assertEquals(map.get("system_tables_test0").getFields(), asList("tpch", "system_tables_test0", null, null, null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test1").getFields(), asList("tpch", "system_tables_test1", "c10", null, null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test2").getFields(), asList("tpch", "system_tables_test2", "c20", ImmutableList.of("c22", "c21"), null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test3").getFields(), asList("tpch", "system_tables_test3", "c30", null, null, 40L, ImmutableList.of("c34", "c33"), Boolean.FALSE));
    assertEquals(map.get("system_tables_test4").getFields(), asList("tpch", "system_tables_test4", "c40", ImmutableList.of("c41", "c42"), "test_distribution", 50L, ImmutableList.of("c43", "c44"), Boolean.FALSE));
    assertEquals(map.get("system_tables_test5").getFields(), asList("tpch", "system_tables_test5", null, ImmutableList.of("c51", "c52"), "test_distribution", 50L, ImmutableList.of("c53", "c54"), Boolean.TRUE));
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch'");
    long actualRowCount = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).count();
    assertEquals(actualRowCount, 6);
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_name = 'system_tables_test3'");
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    actualResults = computeActual("" + "SELECT distribution_name, bucket_count, bucketing_columns, ordering_columns, temporal_column, organized " + "FROM system.tables " + "WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
    assertEquals(actualResults.getTypes(), ImmutableList.of(VARCHAR, BIGINT, new ArrayType(VARCHAR), new ArrayType(VARCHAR), VARCHAR, BOOLEAN));
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    assertUpdate("DROP TABLE system_tables_test0");
    assertUpdate("DROP TABLE system_tables_test1");
    assertUpdate("DROP TABLE system_tables_test2");
    assertUpdate("DROP TABLE system_tables_test3");
    assertUpdate("DROP TABLE system_tables_test4");
    assertUpdate("DROP TABLE system_tables_test5");
    assertEquals(computeActual("SELECT * FROM system.tables WHERE table_schema IN ('foo', 'bar')").getRowCount(), 0);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) IntStream(java.util.stream.IntStream) RaptorQueryRunner.createRaptorQueryRunner(com.facebook.presto.raptor.RaptorQueryRunner.createRaptorQueryRunner) SHARD_UUID_COLUMN_TYPE(com.facebook.presto.raptor.RaptorColumnHandle.SHARD_UUID_COLUMN_TYPE) Assertions.assertInstanceOf(io.airlift.testing.Assertions.assertInstanceOf) ArrayType(com.facebook.presto.type.ArrayType) Assertions.assertGreaterThan(io.airlift.testing.Assertions.assertGreaterThan) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Assertions.assertLessThan(io.airlift.testing.Assertions.assertLessThan) Assertions.assertGreaterThanOrEqual(io.airlift.testing.Assertions.assertGreaterThanOrEqual) Collectors.toSet(java.util.stream.Collectors.toSet) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Set(java.util.Set) VARCHAR(com.facebook.presto.spi.type.VarcharType.VARCHAR) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) UUID(java.util.UUID) Assert.assertNotNull(org.testng.Assert.assertNotNull) SetMultimap(com.google.common.collect.SetMultimap) String.format(java.lang.String.format) Date(java.sql.Date) MaterializedResult(com.facebook.presto.testing.MaterializedResult) DATE(com.facebook.presto.spi.type.DateType.DATE) MaterializedRow(com.facebook.presto.testing.MaterializedRow) StringJoiner(java.util.StringJoiner) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest) ImmutableCollectors(com.facebook.presto.util.ImmutableCollectors) INTEGER(com.facebook.presto.spi.type.IntegerType.INTEGER) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Aggregations

SHARD_UUID_COLUMN_TYPE (com.facebook.presto.raptor.RaptorColumnHandle.SHARD_UUID_COLUMN_TYPE)1 RaptorQueryRunner.createRaptorQueryRunner (com.facebook.presto.raptor.RaptorQueryRunner.createRaptorQueryRunner)1 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.spi.type.BooleanType.BOOLEAN)1 DATE (com.facebook.presto.spi.type.DateType.DATE)1 INTEGER (com.facebook.presto.spi.type.IntegerType.INTEGER)1 VARCHAR (com.facebook.presto.spi.type.VarcharType.VARCHAR)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1 MaterializedRow (com.facebook.presto.testing.MaterializedRow)1 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)1 ArrayType (com.facebook.presto.type.ArrayType)1 ImmutableCollectors (com.facebook.presto.util.ImmutableCollectors)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 SetMultimap (com.google.common.collect.SetMultimap)1 Assertions.assertGreaterThan (io.airlift.testing.Assertions.assertGreaterThan)1 Assertions.assertGreaterThanOrEqual (io.airlift.testing.Assertions.assertGreaterThanOrEqual)1 Assertions.assertInstanceOf (io.airlift.testing.Assertions.assertInstanceOf)1