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);
}
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);
}
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);
}
}
}
}
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));
}
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());
}
Aggregations