Search in sources :

Example 41 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestBlackHoleSmoke method dataGenerationUsage.

@Test
public void dataGenerationUsage() {
    Session session = testSessionBuilder().setCatalog("blackhole").setSchema("default").build();
    assertThatQueryReturnsValue(format("CREATE TABLE nation WITH ( %s = 3, %s = 2, %s = 1 ) as SELECT * FROM tpch.tiny.nation", ROWS_PER_PAGE_PROPERTY, PAGES_PER_SPLIT_PROPERTY, SPLIT_COUNT_PROPERTY), 25L, session);
    assertThatQueryReturnsValue("SELECT count(*) FROM nation", 6L, session);
    assertThatQueryReturnsValue("INSERT INTO nation SELECT * FROM tpch.tiny.nation", 25L, session);
    assertThatQueryReturnsValue("SELECT count(*) FROM nation", 6L, session);
    MaterializedResult rows = queryRunner.execute(session, "SELECT * FROM nation LIMIT 1");
    assertEquals(rows.getRowCount(), 1);
    MaterializedRow row = Iterables.getOnlyElement(rows);
    assertEquals(row.getFieldCount(), 4);
    assertEquals(row.getField(0), 0L);
    assertEquals(row.getField(1), "****************");
    assertEquals(row.getField(2), 0L);
    assertEquals(row.getField(3), "****************");
    assertThatQueryReturnsValue("DROP TABLE nation", true);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 42 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestBlackHoleSmoke method testSelectAllTypes.

@Test
public void testSelectAllTypes() {
    createBlackholeAllTypesTable();
    MaterializedResult rows = queryRunner.execute("SELECT * FROM blackhole_all_types");
    assertEquals(rows.getRowCount(), 1);
    MaterializedRow row = Iterables.getOnlyElement(rows);
    assertEquals(row.getFieldCount(), 13);
    assertEquals(row.getField(0), "**********");
    assertEquals(row.getField(1), 0L);
    assertEquals(row.getField(2), 0);
    assertEquals(row.getField(3), (short) 0);
    assertEquals(row.getField(4), (byte) 0);
    assertEquals(row.getField(5), 0.0f);
    assertEquals(row.getField(6), 0.0);
    assertEquals(row.getField(7), false);
    assertEquals(row.getField(8), LocalDate.ofEpochDay(0));
    // TODO #7122 should be 1970-01-01 00:00:00
    assertEquals(row.getField(9), LocalDateTime.of(1969, 12, 31, 13, 0, 0));
    assertEquals(row.getField(10), "****************".getBytes());
    assertEquals(row.getField(11), new BigDecimal("0.00"));
    assertEquals(row.getField(12), new BigDecimal("00000000000000000000.0000000000"));
    dropBlackholeAllTypesTable();
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 43 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method testBucketHiddenColumn.

@Test
public void testBucketHiddenColumn() {
    @Language("SQL") String createTable = "CREATE TABLE test_bucket_hidden_column " + "WITH (" + "bucketed_by = ARRAY['col0']," + "bucket_count = 2" + ") AS " + "SELECT * FROM (VALUES " + "(0, 11), (1, 12), (2, 13), " + "(3, 14), (4, 15), (5, 16), " + "(6, 17), (7, 18), (8, 19)" + " ) t (col0, col1) ";
    assertUpdate(createTable, 9);
    assertTrue(getQueryRunner().tableExists(getSession(), "test_bucket_hidden_column"));
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_bucket_hidden_column");
    assertEquals(tableMetadata.getMetadata().getProperties().get(BUCKETED_BY_PROPERTY), ImmutableList.of("col0"));
    assertEquals(tableMetadata.getMetadata().getProperties().get(BUCKET_COUNT_PROPERTY), 2);
    List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, BUCKET_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(BUCKET_COLUMN_NAME)) {
            // $bucket_number should be hidden column
            assertTrue(columnMetadata.isHidden());
        }
    }
    assertEquals(getBucketCount("test_bucket_hidden_column"), 2);
    MaterializedResult results = computeActual(format("SELECT *, \"%1$s\" FROM test_bucket_hidden_column WHERE \"%1$s\" = 1", BUCKET_COLUMN_NAME));
    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);
        int bucket = (int) row.getField(2);
        assertEquals(col1, col0 + 11);
        assertTrue(col1 % 2 == 0);
        // Because Hive's hash function for integer n is h(n) = n.
        assertEquals(bucket, col0 % 2);
    }
    assertEquals(results.getRowCount(), 4);
    assertUpdate("DROP TABLE test_bucket_hidden_column");
    assertFalse(getQueryRunner().tableExists(getSession(), "test_bucket_hidden_column"));
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Constraint(com.facebook.presto.spi.Constraint) ColumnConstraint(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 44 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method createTableWithEveryType.

@Test
public void createTableWithEveryType() {
    @Language("SQL") String query = "" + "CREATE TABLE test_types_table AS " + "SELECT" + " 'foo' _varchar" + ", cast('bar' as varbinary) _varbinary" + ", cast(1 as bigint) _bigint" + ", 2 _integer" + ", CAST('3.14' AS DOUBLE) _double" + ", true _boolean" + ", DATE '1980-05-07' _date" + ", TIMESTAMP '1980-05-07 11:22:33.456' _timestamp" + ", CAST('3.14' AS DECIMAL(3,2)) _decimal_short" + ", CAST('12345678901234567890.0123456789' AS DECIMAL(30,10)) _decimal_long" + ", CAST('bar' AS CHAR(10)) _char";
    assertUpdate(query, 1);
    MaterializedResult results = getQueryRunner().execute(getSession(), "SELECT * FROM test_types_table").toTestTypes();
    assertEquals(results.getRowCount(), 1);
    MaterializedRow row = results.getMaterializedRows().get(0);
    assertEquals(row.getField(0), "foo");
    assertEquals(row.getField(1), "bar".getBytes(UTF_8));
    assertEquals(row.getField(2), 1L);
    assertEquals(row.getField(3), 2);
    assertEquals(row.getField(4), 3.14);
    assertEquals(row.getField(5), true);
    assertEquals(row.getField(6), LocalDate.of(1980, 5, 7));
    assertEquals(row.getField(7), LocalDateTime.of(1980, 5, 7, 11, 22, 33, 456_000_000));
    assertEquals(row.getField(8), new BigDecimal("3.14"));
    assertEquals(row.getField(9), new BigDecimal("12345678901234567890.0123456789"));
    assertEquals(row.getField(10), "bar       ");
    assertUpdate("DROP TABLE test_types_table");
    assertFalse(getQueryRunner().tableExists(getSession(), "test_types_table"));
}
Also used : Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 45 with MaterializedRow

use of com.facebook.presto.testing.MaterializedRow 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");
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) HashMap(java.util.HashMap) Constraint(com.facebook.presto.spi.Constraint) ColumnConstraint(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint) Language(org.intellij.lang.annotations.Language) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Aggregations

MaterializedRow (com.facebook.presto.testing.MaterializedRow)91 MaterializedResult (com.facebook.presto.testing.MaterializedResult)80 Test (org.testng.annotations.Test)67 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)31 ImmutableList (com.google.common.collect.ImmutableList)16 Constraint (com.facebook.presto.spi.Constraint)15 ConnectorSession (com.facebook.presto.spi.ConnectorSession)14 Language (org.intellij.lang.annotations.Language)13 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)12 List (java.util.List)11 Session (com.facebook.presto.Session)10 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)10 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)9 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)9 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)9 UUID (java.util.UUID)9 Assert.assertEquals (org.testng.Assert.assertEquals)9 ImmutableMap (com.google.common.collect.ImmutableMap)8