Search in sources :

Example 91 with QualifiedObjectName

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;
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ViewColumn(io.trino.metadata.ViewColumn) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TestingMetadata(io.trino.testing.TestingMetadata) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Metadata(io.trino.metadata.Metadata) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) LocalQueryRunner(io.trino.testing.LocalQueryRunner) StaticConnectorFactory(io.trino.connector.StaticConnectorFactory) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) TestingMetadata(io.trino.testing.TestingMetadata) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorSession(io.trino.spi.connector.ConnectorSession) Session(io.trino.Session)

Example 92 with QualifiedObjectName

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));
}
Also used : Language(org.intellij.lang.annotations.Language) QualifiedObjectName(io.trino.metadata.QualifiedObjectName)

Example 93 with QualifiedObjectName

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));
}
Also used : QualifiedObjectName(io.trino.metadata.QualifiedObjectName)

Example 94 with QualifiedObjectName

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;
    });
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TableMetadata(io.trino.metadata.TableMetadata) Metadata(io.trino.metadata.Metadata) InsertTableHandle(io.trino.metadata.InsertTableHandle) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) InsertTableHandle(io.trino.metadata.InsertTableHandle)

Example 95 with QualifiedObjectName

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());
    });
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TableMetadata(io.trino.metadata.TableMetadata) Metadata(io.trino.metadata.Metadata) InsertTableHandle(io.trino.metadata.InsertTableHandle) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) HiveQueryRunner.createBucketedSession(io.trino.plugin.hive.HiveQueryRunner.createBucketedSession) Session(io.trino.Session)

Aggregations

QualifiedObjectName (io.trino.metadata.QualifiedObjectName)142 ViewExpression (io.trino.spi.security.ViewExpression)51 Test (org.testng.annotations.Test)51 Test (org.junit.jupiter.api.Test)41 Session (io.trino.Session)40 TableHandle (io.trino.metadata.TableHandle)33 MetadataUtil.createQualifiedObjectName (io.trino.metadata.MetadataUtil.createQualifiedObjectName)24 Optional (java.util.Optional)20 Metadata (io.trino.metadata.Metadata)17 Map (java.util.Map)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 ImmutableList (com.google.common.collect.ImmutableList)15 List (java.util.List)15 ImmutableMap (com.google.common.collect.ImmutableMap)14 TrinoException (io.trino.spi.TrinoException)14 ImmutableSet (com.google.common.collect.ImmutableSet)13 ColumnHandle (io.trino.spi.connector.ColumnHandle)13 Type (io.trino.spi.type.Type)11 Set (java.util.Set)11 CatalogName (io.trino.connector.CatalogName)10