Search in sources :

Example 46 with MaterializedRow

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

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(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) ConnectorSession(com.facebook.presto.spi.ConnectorSession) HiveQueryRunner.createBucketedSession(com.facebook.presto.hive.HiveQueryRunner.createBucketedSession) Session(com.facebook.presto.Session) HiveQueryRunner.createMaterializeExchangesSession(com.facebook.presto.hive.HiveQueryRunner.createMaterializeExchangesSession) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 47 with MaterializedRow

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

the class TestHiveIntegrationSmokeTest method testCreateAndInsert.

@Test
public void testCreateAndInsert() {
    Session session = getSession();
    List<MaterializedRow> expected = MaterializedResult.resultBuilder(session, BIGINT, BIGINT).row(101L, 1L).row(201L, 2L).row(202L, 2L).row(301L, 3L).row(302L, 3L).build().getMaterializedRows();
    transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(session, transactionSession -> {
        assertUpdate(transactionSession, "CREATE TABLE tmp_create_insert WITH (partitioned_by=array ['z']) AS " + "SELECT * from (VALUES (CAST (101 AS BIGINT), CAST (1 AS BIGINT)), (201, 2), (202, 2)) t(a, z)", 3);
        assertUpdate(transactionSession, "INSERT INTO tmp_create_insert VALUES (301, 3), (302, 3)", 2);
        MaterializedResult actualFromCurrentTransaction = computeActual(transactionSession, "SELECT * FROM tmp_create_insert");
        assertEqualsIgnoreOrder(actualFromCurrentTransaction, expected);
    });
    MaterializedResult actualAfterTransaction = computeActual(session, "SELECT * FROM tmp_create_insert");
    assertEqualsIgnoreOrder(actualAfterTransaction, expected);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) ConnectorSession(com.facebook.presto.spi.ConnectorSession) HiveQueryRunner.createBucketedSession(com.facebook.presto.hive.HiveQueryRunner.createBucketedSession) Session(com.facebook.presto.Session) HiveQueryRunner.createMaterializeExchangesSession(com.facebook.presto.hive.HiveQueryRunner.createMaterializeExchangesSession) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 48 with MaterializedRow

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

the class AbstractTestHiveFunctions method assertQuery.

public void assertQuery(@Language("SQL") String sql, Column... cols) {
    checkArgument(cols != null && cols.length > 0);
    int numColumns = cols.length;
    int numRows = cols[0].values.length;
    checkArgument(Stream.of(cols).allMatch(c -> c != null && c.values.length == numRows));
    MaterializedResult result = client.execute(sql).getResult();
    assertEquals(result.getRowCount(), numRows);
    for (int i = 0; i < numColumns; i++) {
        assertEquals(result.getTypes().get(i), cols[i].type);
    }
    List<MaterializedRow> rows = result.getMaterializedRows();
    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < numColumns; j++) {
            Object actual = rows.get(i).getField(j);
            Object expected = cols[j].values[i];
            if (cols[j].type == DOUBLE) {
                assertEquals(((Number) actual).doubleValue(), ((double) expected), 0.000001);
            } else {
                assertEquals(actual, expected);
            }
        }
    }
}
Also used : Logger(com.facebook.airlift.log.Logger) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) Key(com.google.inject.Key) Assert.assertEquals(org.testng.Assert.assertEquals) HiveFunctionsTestUtils.createTestingPrestoServer(com.facebook.presto.hive.functions.HiveFunctionsTestUtils.createTestingPrestoServer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Files(com.google.common.io.Files) TypeManager(com.facebook.presto.common.type.TypeManager) Splitter(com.google.common.base.Splitter) Type(com.facebook.presto.common.type.Type) Language(org.intellij.lang.annotations.Language) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BeforeClass(org.testng.annotations.BeforeClass) Assert.fail(org.testng.Assert.fail) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) File(java.io.File) String.format(java.lang.String.format) TimeZoneKey(com.facebook.presto.common.type.TimeZoneKey) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Stream(java.util.stream.Stream) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Optional(java.util.Optional) TestingPrestoClient(com.facebook.presto.tests.TestingPrestoClient) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 49 with MaterializedRow

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

the class TestKuduIntegrationSmoke method testDescribeTable.

/**
 * Overrides original implementation because of usage of 'extra' column.
 */
@Test
@Override
public void testDescribeTable() {
    MaterializedResult actualColumns = this.computeActual("DESC orders").toTestTypes();
    MaterializedResult.Builder builder = MaterializedResult.resultBuilder(this.getQueryRunner().getDefaultSession(), VarcharType.VARCHAR, VarcharType.VARCHAR, VarcharType.VARCHAR, VarcharType.VARCHAR);
    for (MaterializedRow row : actualColumns.getMaterializedRows()) {
        builder.row(row.getField(0), row.getField(1), "", "");
    }
    MaterializedResult filteredActual = builder.build();
    builder = MaterializedResult.resultBuilder(this.getQueryRunner().getDefaultSession(), VarcharType.VARCHAR, VarcharType.VARCHAR, VarcharType.VARCHAR, VarcharType.VARCHAR);
    MaterializedResult expectedColumns = builder.row("orderkey", "bigint", "", "").row("custkey", "bigint", "", "").row("orderstatus", "varchar", "", "").row("totalprice", "double", "", "").row("orderdate", "varchar", "", "").row("orderpriority", "varchar", "", "").row("clerk", "varchar", "", "").row("shippriority", "integer", "", "").row("comment", "varchar", "", "").build();
    assertEquals(filteredActual, expectedColumns, String.format("%s != %s", filteredActual, expectedColumns));
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 50 with MaterializedRow

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

the class TestIcebergSystemTables method testPartitionTable.

@Test
public void testPartitionTable() {
    assertQuery("SELECT count(*) FROM test_schema.test_table", "VALUES 6");
    assertQuery("SHOW COLUMNS FROM test_schema.\"test_table$partitions\"", "VALUES ('_date', 'date', '', '')," + "('row_count', 'bigint', '', '')," + "('file_count', 'bigint', '', '')," + "('total_size', 'bigint', '', '')," + "('_bigint', 'row(\"min\" bigint, \"max\" bigint, \"null_count\" bigint)', '', '')");
    MaterializedResult result = computeActual("SELECT * from test_schema.\"test_table$partitions\"");
    assertEquals(result.getRowCount(), 3);
    Map<LocalDate, MaterializedRow> rowsByPartition = result.getMaterializedRows().stream().collect(toImmutableMap(row -> (LocalDate) row.getField(0), Function.identity()));
    // Test if row counts are computed correctly
    assertEquals(rowsByPartition.get(LocalDate.parse("2019-09-08")).getField(1), 1L);
    assertEquals(rowsByPartition.get(LocalDate.parse("2019-09-09")).getField(1), 3L);
    assertEquals(rowsByPartition.get(LocalDate.parse("2019-09-10")).getField(1), 2L);
    // Test if min/max values and null value count are computed correctly.
    assertEquals(rowsByPartition.get(LocalDate.parse("2019-09-08")).getField(4), new MaterializedRow(DEFAULT_PRECISION, 0L, 0L, 0L).getFields());
    assertEquals(rowsByPartition.get(LocalDate.parse("2019-09-09")).getField(4), new MaterializedRow(DEFAULT_PRECISION, 1L, 3L, 0L).getFields());
    assertEquals(rowsByPartition.get(LocalDate.parse("2019-09-10")).getField(4), new MaterializedRow(DEFAULT_PRECISION, 4L, 5L, 0L).getFields());
}
Also used : AfterClass(org.testng.annotations.AfterClass) AbstractTestQueryFramework(com.facebook.presto.tests.AbstractTestQueryFramework) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session) BeforeClass(org.testng.annotations.BeforeClass) Assert.assertEquals(org.testng.Assert.assertEquals) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) Function(java.util.function.Function) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) MaterializedRow(com.facebook.presto.testing.MaterializedRow) LocalDate(java.time.LocalDate) Map(java.util.Map) ICEBERG_CATALOG(com.facebook.presto.iceberg.IcebergQueryRunner.ICEBERG_CATALOG) Path(java.nio.file.Path) MaterializedResult(com.facebook.presto.testing.MaterializedResult) LocalDate(java.time.LocalDate) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

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