use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class AbstractTestHiveClient method doTestTransactionDeleteInsert.
protected void doTestTransactionDeleteInsert(HiveStorageFormat storageFormat, boolean allowInsertExisting, List<TransactionDeleteInsertTestCase> testCases) throws Exception {
// There are 4 types of operations on a partition: add, drop, alter (drop then add), insert existing.
// There are 12 partitions in this test, 3 for each type.
// 3 is chosen to verify that cleanups, commit aborts, rollbacks are always as complete as possible regardless of failure.
MaterializedResult beforeData = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(110L, "a", "alter1").row(120L, "a", "insert1").row(140L, "a", "drop1").row(210L, "b", "drop2").row(310L, "c", "alter2").row(320L, "c", "alter3").row(510L, "e", "drop3").row(610L, "f", "insert2").row(620L, "f", "insert3").build();
Domain domainToDrop = Domain.create(ValueSet.of(createUnboundedVarcharType(), utf8Slice("alter1"), utf8Slice("alter2"), utf8Slice("alter3"), utf8Slice("drop1"), utf8Slice("drop2"), utf8Slice("drop3")), false);
List<MaterializedRow> extraRowsForInsertExisting = ImmutableList.of();
if (allowInsertExisting) {
extraRowsForInsertExisting = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(121L, "a", "insert1").row(611L, "f", "insert2").row(621L, "f", "insert3").build().getMaterializedRows();
}
MaterializedResult insertData = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(111L, "a", "alter1").row(131L, "a", "add1").row(221L, "b", "add2").row(311L, "c", "alter2").row(321L, "c", "alter3").row(411L, "d", "add3").rows(extraRowsForInsertExisting).build();
MaterializedResult afterData = MaterializedResult.resultBuilder(SESSION, BIGINT, createUnboundedVarcharType(), createUnboundedVarcharType()).row(120L, "a", "insert1").row(610L, "f", "insert2").row(620L, "f", "insert3").rows(insertData.getMaterializedRows()).build();
for (TransactionDeleteInsertTestCase testCase : testCases) {
SchemaTableName temporaryDeleteInsert = temporaryTable("delete_insert");
try {
createEmptyTable(temporaryDeleteInsert, storageFormat, ImmutableList.of(new Column("col1", HIVE_LONG, Optional.empty(), Optional.empty())), ImmutableList.of(new Column("pk1", HIVE_STRING, Optional.empty(), Optional.empty()), new Column("pk2", HIVE_STRING, Optional.empty(), Optional.empty())));
insertData(temporaryDeleteInsert, beforeData);
try {
doTestTransactionDeleteInsert(storageFormat, temporaryDeleteInsert, domainToDrop, insertData, testCase.isExpectCommitedData() ? afterData : beforeData, testCase.getTag(), testCase.isExpectQuerySucceed(), testCase.getConflictTrigger());
} catch (AssertionError e) {
throw new AssertionError(format("Test case: %s", testCase.toString()), e);
}
} finally {
dropTable(temporaryDeleteInsert);
}
}
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testFileRenamingForUnpartitionedTable.
@Test
public void testFileRenamingForUnpartitionedTable() {
try {
// Create un-partitioned table
assertUpdate(Session.builder(getSession()).setCatalogSessionProperty(catalog, FILE_RENAMING_ENABLED, "true").setSystemProperty("scale_writers", "false").setSystemProperty("writer_min_size", "1MB").setSystemProperty("task_writer_count", "1").build(), "CREATE TABLE unpartitioned_ordering_table AS SELECT * FROM tpch.sf1.orders", (long) computeActual("SELECT count(*) FROM tpch.sf1.orders").getOnlyValue());
// Collect file names of the table
List<Integer> fileNames = new ArrayList<>();
MaterializedResult results = computeActual("SELECT DISTINCT \"$path\" FROM unpartitioned_ordering_table");
for (int i = 0; i < results.getRowCount(); i++) {
MaterializedRow row = results.getMaterializedRows().get(i);
String pathName = (String) row.getField(0);
String fileName = new Path(pathName).getName();
fileNames.add(Integer.valueOf(fileName));
}
assertTrue(fileNames.size() > 0);
// Assert that file names are continuous increasing sequence
assertTrue(isIncreasingSequence(fileNames));
} finally {
assertUpdate("DROP TABLE IF EXISTS unpartitioned_ordering_table");
}
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testFileModifiedTimeHiddenColumn.
@Test
public void testFileModifiedTimeHiddenColumn() {
long testStartTime = Instant.now().toEpochMilli();
@Language("SQL") String createTable = "CREATE TABLE test_file_modified_time " + "WITH (" + "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(createTable, 8);
assertTrue(getQueryRunner().tableExists(getSession(), "test_file_modified_time"));
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_file_modified_time");
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_MODIFIED_TIME_COLUMN_NAME)) {
assertTrue(columnMetadata.isHidden());
}
}
assertEquals(getPartitions("test_file_modified_time").size(), 3);
MaterializedResult results = computeActual(format("SELECT *, \"%s\" FROM test_file_modified_time", FILE_MODIFIED_TIME_COLUMN_NAME));
Map<Integer, Long> fileModifiedTimeMap = 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 fileModifiedTime = (Long) row.getField(2);
assertTrue(fileModifiedTime > (testStartTime - 2_000));
assertEquals(col0 % 3, col1);
if (fileModifiedTimeMap.containsKey(col1)) {
assertEquals(fileModifiedTimeMap.get(col1).longValue(), fileModifiedTime);
} else {
fileModifiedTimeMap.put(col1, fileModifiedTime);
}
}
assertEquals(fileModifiedTimeMap.size(), 3);
assertUpdate("DROP TABLE test_file_modified_time");
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testCreateUnpartitionedTableAndQuery.
@Test
public void testCreateUnpartitionedTableAndQuery() {
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_query AS " + "SELECT * from (VALUES (CAST (101 AS BIGINT), CAST (1 AS BIGINT)), (201, 2), (202, 2), (301, 3), (302, 3)) t(a, z)", 5);
MaterializedResult actualFromCurrentTransaction = computeActual(transactionSession, "SELECT * FROM tmp_create_query");
assertEqualsIgnoreOrder(actualFromCurrentTransaction, expected);
});
MaterializedResult actualAfterTransaction = computeActual(session, "SELECT * FROM tmp_create_query");
assertEqualsIgnoreOrder(actualAfterTransaction, expected);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
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, 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(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((int) (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"));
}
Aggregations