use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AbstractTestHive method assertGetRecords.
protected void assertGetRecords(String tableName, HiveStorageFormat hiveStorageFormat) throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorSession session = newSession();
ConnectorMetadata metadata = transaction.getMetadata();
metadata.beginQuery(session);
ConnectorTableHandle tableHandle = getTableHandle(metadata, new SchemaTableName(database, tableName));
ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
HiveSplit hiveSplit = getHiveSplit(tableHandle, transaction, session);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, tableHandle).values());
ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, hiveSplit, tableHandle, columnHandles, DynamicFilter.EMPTY);
assertGetRecords(hiveStorageFormat, tableMetadata, hiveSplit, pageSource, columnHandles);
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AbstractTestHive method testTableCreationRollback.
@Test
public void testTableCreationRollback() throws Exception {
SchemaTableName temporaryCreateRollbackTable = temporaryTable("create_rollback");
try {
Path stagingPathRoot;
try (Transaction transaction = newTransaction()) {
ConnectorSession session = newSession();
ConnectorMetadata metadata = transaction.getMetadata();
// begin creating the table
ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(temporaryCreateRollbackTable, CREATE_TABLE_COLUMNS, createTableProperties(RCBINARY));
ConnectorOutputTableHandle outputHandle = metadata.beginCreateTable(session, tableMetadata, Optional.empty(), NO_RETRIES);
// write the data
ConnectorPageSink sink = pageSinkProvider.createPageSink(transaction.getTransactionHandle(), session, outputHandle);
sink.appendPage(CREATE_TABLE_DATA.toPage());
getFutureValue(sink.finish());
// verify we have data files
stagingPathRoot = getStagingPathRoot(outputHandle);
HdfsContext context = new HdfsContext(session);
assertFalse(listAllDataFiles(context, stagingPathRoot).isEmpty());
// rollback the table
transaction.rollback();
}
// verify all files have been deleted
HdfsContext context = new HdfsContext(newSession());
assertTrue(listAllDataFiles(context, stagingPathRoot).isEmpty());
// verify table is not in the metastore
try (Transaction transaction = newTransaction()) {
ConnectorSession session = newSession();
ConnectorMetadata metadata = transaction.getMetadata();
assertNull(metadata.getTableHandle(session, temporaryCreateRollbackTable));
}
} finally {
dropTable(temporaryCreateRollbackTable);
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AbstractTestHive method testUpdateBasicTableStatistics.
@Test
public void testUpdateBasicTableStatistics() throws Exception {
SchemaTableName tableName = temporaryTable("update_basic_table_statistics");
try {
doCreateEmptyTable(tableName, ORC, STATISTICS_TABLE_COLUMNS);
testUpdateTableStatistics(tableName, EMPTY_TABLE_STATISTICS, BASIC_STATISTICS_1, BASIC_STATISTICS_2);
} finally {
dropTable(tableName);
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AbstractTestHive method testPartitionStatisticsSampling.
protected void testPartitionStatisticsSampling(List<ColumnMetadata> columns, PartitionStatistics statistics) throws Exception {
SchemaTableName tableName = temporaryTable("test_partition_statistics_sampling");
try {
createDummyPartitionedTable(tableName, columns);
HiveMetastoreClosure metastoreClient = new HiveMetastoreClosure(getMetastoreClient());
metastoreClient.updatePartitionStatistics(tableName.getSchemaName(), tableName.getTableName(), "ds=2016-01-01", actualStatistics -> statistics);
metastoreClient.updatePartitionStatistics(tableName.getSchemaName(), tableName.getTableName(), "ds=2016-01-02", actualStatistics -> statistics);
try (Transaction transaction = newTransaction()) {
ConnectorSession session = newSession();
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorTableHandle tableHandle = metadata.getTableHandle(session, tableName);
TableStatistics unsampledStatistics = metadata.getTableStatistics(sampleSize(2), tableHandle, Constraint.alwaysTrue());
TableStatistics sampledStatistics = metadata.getTableStatistics(sampleSize(1), tableHandle, Constraint.alwaysTrue());
assertEquals(sampledStatistics, unsampledStatistics);
}
} finally {
dropTable(tableName);
}
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class AbstractTestHive method testUpdateBasicPartitionStatistics.
@Test
public void testUpdateBasicPartitionStatistics() throws Exception {
SchemaTableName tableName = temporaryTable("update_basic_partition_statistics");
try {
createDummyPartitionedTable(tableName, STATISTICS_PARTITIONED_TABLE_COLUMNS);
testUpdatePartitionStatistics(tableName, EMPTY_TABLE_STATISTICS, ImmutableList.of(BASIC_STATISTICS_1, BASIC_STATISTICS_2), ImmutableList.of(BASIC_STATISTICS_2, BASIC_STATISTICS_1));
} finally {
dropTable(tableName);
}
}
Aggregations