use of com.facebook.presto.testing.MaterializedResult 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.MaterializedResult in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testDeleteFromUnpartitionedTable.
@Test
public void testDeleteFromUnpartitionedTable() throws Exception {
assertUpdate("CREATE TABLE test_delete_unpartitioned AS SELECT orderstatus FROM tpch.tiny.orders", "SELECT count(*) from orders");
assertUpdate("DELETE FROM test_delete_unpartitioned");
MaterializedResult result = computeActual("SELECT * from test_delete_unpartitioned");
assertEquals(result.getRowCount(), 0);
assertUpdate("DROP TABLE test_delete_unpartitioned");
assertFalse(getQueryRunner().tableExists(getSession(), "test_delete_unpartitioned"));
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testCreateExternalTable.
@Test
public void testCreateExternalTable() throws Exception {
File tempDir = createTempDir();
File dataFile = new File(tempDir, "test.txt");
Files.write("hello\nworld\n", dataFile, UTF_8);
@Language("SQL") String createTableSql = format("" + "CREATE TABLE %s.%s.test_create_external (\n" + " name varchar\n" + ")\n" + "WITH (\n" + " external_location = '%s',\n" + " format = 'TEXTFILE'\n" + ")", getSession().getCatalog().get(), getSession().getSchema().get(), new Path(tempDir.toURI().toASCIIString()).toString());
assertUpdate(createTableSql);
MaterializedResult actual = computeActual("SHOW CREATE TABLE test_create_external");
assertEquals(actual.getOnlyValue(), createTableSql);
actual = computeActual("SELECT name FROM test_create_external");
assertEquals(actual.getOnlyColumnAsSet(), ImmutableSet.of("hello", "world"));
assertUpdate("DROP TABLE test_create_external");
// file should still exist after drop
assertFile(dataFile);
deleteRecursively(tempDir);
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class TestHivePageSink method writeTestFile.
private static long writeTestFile(HiveClientConfig config, ExtendedHiveMetastore metastore, String outputPath) {
HiveTransactionHandle transaction = new HiveTransactionHandle();
ConnectorPageSink pageSink = createPageSink(transaction, config, metastore, new Path("file:///" + outputPath));
List<LineItemColumn> columns = getTestColumns();
List<Type> columnTypes = columns.stream().map(LineItemColumn::getType).map(TestHivePageSink::getHiveType).map(hiveType -> hiveType.getType(TYPE_MANAGER)).collect(toList());
PageBuilder pageBuilder = new PageBuilder(columnTypes);
int rows = 0;
for (LineItem lineItem : new LineItemGenerator(0.01, 1, 1)) {
rows++;
if (rows >= NUM_ROWS) {
break;
}
pageBuilder.declarePosition();
for (int i = 0; i < columns.size(); i++) {
LineItemColumn column = columns.get(i);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
switch(column.getType().getBase()) {
case IDENTIFIER:
BIGINT.writeLong(blockBuilder, column.getIdentifier(lineItem));
break;
case INTEGER:
INTEGER.writeLong(blockBuilder, column.getInteger(lineItem));
break;
case DATE:
DATE.writeLong(blockBuilder, column.getDate(lineItem));
break;
case DOUBLE:
DOUBLE.writeDouble(blockBuilder, column.getDouble(lineItem));
break;
case VARCHAR:
createUnboundedVarcharType().writeSlice(blockBuilder, Slices.utf8Slice(column.getString(lineItem)));
break;
default:
throw new IllegalArgumentException("Unsupported type " + column.getType());
}
}
}
Page page = pageBuilder.build();
pageSink.appendPage(page);
getFutureValue(pageSink.finish());
File outputDir = new File(outputPath);
List<File> files = ImmutableList.copyOf(outputDir.listFiles((dir, name) -> !name.endsWith(".crc")));
File outputFile = getOnlyElement(files);
long length = outputFile.length();
ConnectorPageSource pageSource = createPageSource(transaction, config, outputFile);
List<Page> pages = new ArrayList<>();
while (!pageSource.isFinished()) {
Page nextPage = pageSource.getNextPage();
if (nextPage != null) {
nextPage.assureLoaded();
pages.add(nextPage);
}
}
MaterializedResult expectedResults = toMaterializedResult(getSession(config), columnTypes, ImmutableList.of(page));
MaterializedResult results = toMaterializedResult(getSession(config), columnTypes, pages);
assertEquals(results, expectedResults);
return length;
}
use of com.facebook.presto.testing.MaterializedResult in project presto by prestodb.
the class WindowAssertions method assertWindowQuery.
public static void assertWindowQuery(@Language("SQL") String sql, MaterializedResult expected, LocalQueryRunner localQueryRunner) {
@Language("SQL") String query = format("" + "SELECT orderkey, orderstatus,\n%s\n" + "FROM (%s) x", sql, VALUES);
MaterializedResult actual = localQueryRunner.execute(query);
assertEqualsIgnoreOrder(actual.getMaterializedRows(), expected.getMaterializedRows());
}
Aggregations