Search in sources :

Example 86 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project boostkit-bigdata by kunpengcompute.

the class TestHiveIntegrationSmokeTest method testPathHiddenColumn.

private void testPathHiddenColumn(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(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"));
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) Path(org.apache.hadoop.fs.Path) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) HashMap(java.util.HashMap) ColumnConstraint(io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint) Constraint(io.prestosql.spi.connector.Constraint) Language(org.intellij.lang.annotations.Language) MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

Example 87 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project boostkit-bigdata by kunpengcompute.

the class TestHiveIntegrationSmokeTest method testEscapeCharacter.

private void testEscapeCharacter(Session session, HiveStorageFormat storageFormat) {
    String tableName = format("test_escape_character_%s", storageFormat);
    assertUpdate(session, format("CREATE TABLE %s (id varchar) WITH (format = '%s')", tableName, storageFormat));
    assertUpdate(session, format("INSERT INTO %s VALUES ('\0')", tableName), 1);
    MaterializedResult result = getQueryRunner().execute(session, format("SELECT * FROM %s", tableName));
    assertEquals(result.getRowCount(), 1);
    MaterializedRow actualRow = result.getMaterializedRows().get(0);
    assertEquals(actualRow.getField(0), String.valueOf('\0'));
    assertUpdate(session, format("DROP TABLE %s", tableName));
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

Example 88 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project boostkit-bigdata by kunpengcompute.

the class TestHiveIntegrationSmokeTest method testDeleteAndInsert.

@Test
public void testDeleteAndInsert() {
    Session session = getSession();
    // Partition 1 is untouched
    // Partition 2 is altered (dropped and then added back)
    // Partition 3 is added
    // Partition 4 is dropped
    assertUpdate(session, "CREATE TABLE tmp_delete_insert WITH (partitioned_by=array ['z']) AS " + "SELECT * from (VALUES (CAST (101 AS BIGINT), CAST (1 AS BIGINT)), (201, 2), (202, 2), (401, 4), (402, 4), (403, 4)) t(a, z)", 6);
    List<MaterializedRow> expectedBefore = MaterializedResult.resultBuilder(session, BIGINT, BIGINT).row(101L, 1L).row(201L, 2L).row(202L, 2L).row(401L, 4L).row(402L, 4L).row(403L, 4L).build().getMaterializedRows();
    List<MaterializedRow> expectedAfter = MaterializedResult.resultBuilder(session, BIGINT, BIGINT).row(101L, 1L).row(203L, 2L).row(204L, 2L).row(205L, 2L).row(301L, 2L).row(302L, 3L).build().getMaterializedRows();
    try {
        transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(session, transactionSession -> {
            assertUpdate(transactionSession, "DELETE FROM tmp_delete_insert WHERE z >= 2");
            assertUpdate(transactionSession, "INSERT INTO tmp_delete_insert VALUES (203, 2), (204, 2), (205, 2), (301, 2), (302, 3)", 5);
            MaterializedResult actualFromAnotherTransaction = computeActual(session, "SELECT * FROM tmp_delete_insert");
            assertEqualsIgnoreOrder(actualFromAnotherTransaction, expectedBefore);
            MaterializedResult actualFromCurrentTransaction = computeActual(transactionSession, "SELECT * FROM tmp_delete_insert");
            assertEqualsIgnoreOrder(actualFromCurrentTransaction, expectedAfter);
            rollback();
        });
    } catch (RollbackException e) {
    // ignore
    }
    MaterializedResult actualAfterRollback = computeActual(session, "SELECT * FROM tmp_delete_insert");
    assertEqualsIgnoreOrder(actualAfterRollback, expectedBefore);
    transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(session, transactionSession -> {
        assertUpdate(transactionSession, "DELETE FROM tmp_delete_insert WHERE z >= 2");
        assertUpdate(transactionSession, "INSERT INTO tmp_delete_insert VALUES (203, 2), (204, 2), (205, 2), (301, 2), (302, 3)", 5);
        MaterializedResult actualOutOfTransaction = computeActual(session, "SELECT * FROM tmp_delete_insert");
        assertEqualsIgnoreOrder(actualOutOfTransaction, expectedBefore);
        MaterializedResult actualInTransaction = computeActual(transactionSession, "SELECT * FROM tmp_delete_insert");
        assertEqualsIgnoreOrder(actualInTransaction, expectedAfter);
    });
    MaterializedResult actualAfterTransaction = computeActual(session, "SELECT * FROM tmp_delete_insert");
    assertEqualsIgnoreOrder(actualAfterTransaction, expectedAfter);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Session(io.prestosql.Session) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Example 89 with MaterializedRow

use of io.prestosql.testing.MaterializedRow in project boostkit-bigdata by kunpengcompute.

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(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Aggregations

MaterializedRow (io.prestosql.testing.MaterializedRow)89 MaterializedResult (io.prestosql.testing.MaterializedResult)80 Test (org.testng.annotations.Test)57 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)18 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)16 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)14 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)14 Constraint (io.prestosql.spi.connector.Constraint)14 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)14 ImmutableList (com.google.common.collect.ImmutableList)13 HiveColumnHandle.bucketColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle.bucketColumnHandle)12 ConnectorPageSource (io.prestosql.spi.connector.ConnectorPageSource)12 ConnectorSplit (io.prestosql.spi.connector.ConnectorSplit)12 AbstractTestIntegrationSmokeTest (io.prestosql.tests.AbstractTestIntegrationSmokeTest)12 List (java.util.List)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 Session (io.prestosql.Session)9 Language (org.intellij.lang.annotations.Language)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Plan (io.prestosql.sql.planner.Plan)8