use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestMaterializedViews method createLocalQueryRunner.
@Override
protected LocalQueryRunner createLocalQueryRunner() {
Session.SessionBuilder sessionBuilder = testSessionBuilder().setCatalog(CATALOG).setSchema(SCHEMA).setSystemProperty("task_concurrency", // these tests don't handle exchanges from local parallel
"1");
TestingMetadata testingConnectorMetadata = new TestingMetadata();
LocalQueryRunner queryRunner = LocalQueryRunner.create(sessionBuilder.build());
queryRunner.createCatalog(CATALOG, new StaticConnectorFactory("test", new TestMaterializedViewConnector(testingConnectorMetadata)), ImmutableMap.of());
Metadata metadata = queryRunner.getMetadata();
SchemaTableName testTable = new SchemaTableName(SCHEMA, "test_table");
queryRunner.inTransaction(session -> {
metadata.createTable(session, CATALOG, new ConnectorTableMetadata(testTable, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT))), false);
return null;
});
SchemaTableName storageTable = new SchemaTableName(SCHEMA, "storage_table");
queryRunner.inTransaction(session -> {
metadata.createTable(session, CATALOG, new ConnectorTableMetadata(storageTable, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT))), false);
return null;
});
SchemaTableName storageTableWithCasts = new SchemaTableName(SCHEMA, "storage_table_with_casts");
queryRunner.inTransaction(session -> {
metadata.createTable(session, CATALOG, new ConnectorTableMetadata(storageTableWithCasts, ImmutableList.of(new ColumnMetadata("a", TINYINT), new ColumnMetadata("b", VARCHAR))), false);
return null;
});
QualifiedObjectName freshMaterializedView = new QualifiedObjectName(CATALOG, SCHEMA, "fresh_materialized_view");
MaterializedViewDefinition materializedViewDefinition = new MaterializedViewDefinition("SELECT a, b FROM test_table", Optional.of(CATALOG), Optional.of(SCHEMA), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId()), new ViewColumn("b", BIGINT.getTypeId())), Optional.empty(), Identity.ofUser("some user"), Optional.of(new CatalogSchemaTableName(CATALOG, SCHEMA, "storage_table")), ImmutableMap.of());
queryRunner.inTransaction(session -> {
metadata.createMaterializedView(session, freshMaterializedView, materializedViewDefinition, false, false);
return null;
});
testingConnectorMetadata.markMaterializedViewIsFresh(freshMaterializedView.asSchemaTableName());
QualifiedObjectName notFreshMaterializedView = new QualifiedObjectName(CATALOG, SCHEMA, "not_fresh_materialized_view");
queryRunner.inTransaction(session -> {
metadata.createMaterializedView(session, notFreshMaterializedView, materializedViewDefinition, false, false);
return null;
});
MaterializedViewDefinition materializedViewDefinitionWithCasts = new MaterializedViewDefinition("SELECT a, b FROM test_table", Optional.of(CATALOG), Optional.of(SCHEMA), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId()), new ViewColumn("b", BIGINT.getTypeId())), Optional.empty(), Identity.ofUser("some user"), Optional.of(new CatalogSchemaTableName(CATALOG, SCHEMA, "storage_table_with_casts")), ImmutableMap.of());
QualifiedObjectName materializedViewWithCasts = new QualifiedObjectName(CATALOG, SCHEMA, "materialized_view_with_casts");
queryRunner.inTransaction(session -> {
metadata.createMaterializedView(session, materializedViewWithCasts, materializedViewDefinitionWithCasts, false, false);
return null;
});
testingConnectorMetadata.markMaterializedViewIsFresh(materializedViewWithCasts.asSchemaTableName());
return queryRunner;
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class AccumuloQueryRunner method copyTable.
private static void copyTable(QueryRunner queryRunner, String catalog, Session session, String schema, TpchTable<?> table) {
QualifiedObjectName source = new QualifiedObjectName(catalog, schema, table.getTableName());
String target = table.getTableName();
@Language("SQL") String sql;
switch(target) {
case "customer":
sql = format("CREATE TABLE %s WITH (index_columns = 'mktsegment') AS SELECT * FROM %s", target, source);
break;
case "lineitem":
sql = format("CREATE TABLE %s WITH (index_columns = 'quantity,discount,returnflag,shipdate,receiptdate,shipinstruct,shipmode') AS SELECT cast(uuid() AS varchar) AS uuid, * FROM %s", target, source);
break;
case "orders":
sql = format("CREATE TABLE %s WITH (index_columns = 'orderdate') AS SELECT * FROM %s", target, source);
break;
case "part":
sql = format("CREATE TABLE %s WITH (index_columns = 'brand,type,size,container') AS SELECT * FROM %s", target, source);
break;
case "partsupp":
sql = format("CREATE TABLE %s WITH (index_columns = 'partkey') AS SELECT cast(uuid() AS varchar) AS uuid, * FROM %s", target, source);
break;
case "supplier":
sql = format("CREATE TABLE %s WITH (index_columns = 'name') AS SELECT * FROM %s", target, source);
break;
default:
sql = format("CREATE TABLE %s AS SELECT * FROM %s", target, source);
break;
}
LOG.info("Running import for %s%n%s", target, sql);
long start = System.nanoTime();
long rows = queryRunner.execute(session, sql).getUpdateCount().getAsLong();
LOG.info("Imported %s rows for %s in %s", rows, target, nanosSince(start));
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class HiveQueryRunner method copyTpchTablesBucketed.
private static void copyTpchTablesBucketed(QueryRunner queryRunner, String sourceCatalog, String sourceSchema, Session session, Iterable<TpchTable<?>> tables, ColumnNaming columnNaming) {
log.info("Loading data from %s.%s...", sourceCatalog, sourceSchema);
long startTime = System.nanoTime();
for (TpchTable<?> table : tables) {
copyTableBucketed(queryRunner, new QualifiedObjectName(sourceCatalog, sourceSchema, table.getTableName().toLowerCase(ENGLISH)), table, session, columnNaming);
}
log.info("Loading from %s.%s complete in %s", sourceCatalog, sourceSchema, nanosSince(startTime).toString(SECONDS));
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class BaseHiveConnectorTest method getHiveInsertTableHandle.
private HiveInsertTableHandle getHiveInsertTableHandle(Session session, String tableName) {
Metadata metadata = getDistributedQueryRunner().getCoordinator().getMetadata();
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).execute(session, transactionSession -> {
QualifiedObjectName objectName = new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName);
Optional<TableHandle> handle = metadata.getTableHandle(transactionSession, objectName);
List<ColumnHandle> columns = ImmutableList.copyOf(metadata.getColumnHandles(transactionSession, handle.get()).values());
InsertTableHandle insertTableHandle = metadata.beginInsert(transactionSession, handle.get(), columns);
HiveInsertTableHandle hiveInsertTableHandle = (HiveInsertTableHandle) insertTableHandle.getConnectorHandle();
metadata.finishInsert(transactionSession, insertTableHandle, ImmutableList.of(), ImmutableList.of());
return hiveInsertTableHandle;
});
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class BaseHiveConnectorTest method getHiveTableProperty.
private Object getHiveTableProperty(String tableName, Function<HiveTableHandle, Object> propertyGetter) {
Session session = getSession();
Metadata metadata = getDistributedQueryRunner().getCoordinator().getMetadata();
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
QualifiedObjectName name = new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName);
TableHandle table = metadata.getTableHandle(transactionSession, name).orElseThrow(() -> new AssertionError("table not found: " + name));
table = metadata.applyFilter(transactionSession, table, Constraint.alwaysTrue()).orElseThrow(() -> new AssertionError("applyFilter did not return a result")).getHandle();
return propertyGetter.apply((HiveTableHandle) table.getConnectorHandle());
});
}
Aggregations