Search in sources :

Example 1 with ConnectorViewDefinition

use of io.prestosql.spi.connector.ConnectorViewDefinition in project hetu-core by openlookeng.

the class TestColumnMask method init.

@BeforeClass
public void init() {
    LocalQueryRunner runner = new LocalQueryRunner(SESSION);
    runner.createCatalog(CATALOG, new TpchConnectorFactory(1), ImmutableMap.of());
    ConnectorViewDefinition view = new ConnectorViewDefinition("SELECT nationkey, name FROM local.tiny.nation", Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorViewDefinition.ViewColumn("nationkey", BigintType.BIGINT.getTypeSignature()), new ConnectorViewDefinition.ViewColumn("name", VarcharType.createVarcharType(25).getTypeSignature())), Optional.of(VIEW_OWNER), false);
    MockConnectorFactory mock = MockConnectorFactory.builder().withGetViews((s, prefix) -> ImmutableMap.<SchemaTableName, ConnectorViewDefinition>builder().put(new SchemaTableName("default", "nation_view"), view).build()).build();
    runner.createCatalog(MOCK_CATALOG, mock, ImmutableMap.of());
    assertions = new QueryAssertions(runner);
    accessControl = assertions.getQueryRunner().getAccessControl();
}
Also used : BigintType(io.prestosql.spi.type.BigintType) AfterClass(org.testng.annotations.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) TINY_SCHEMA_NAME(io.prestosql.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) BeforeClass(org.testng.annotations.BeforeClass) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) ViewExpression(io.prestosql.spi.security.ViewExpression) Identity(io.prestosql.spi.security.Identity) Test(org.testng.annotations.Test) MockConnectorFactory(io.prestosql.connector.MockConnectorFactory) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) TestingAccessControlManager(io.prestosql.testing.TestingAccessControlManager) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) LocalQueryRunner(io.prestosql.testing.LocalQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) Session(io.prestosql.Session) Optional(java.util.Optional) VarcharType(io.prestosql.spi.type.VarcharType) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) MockConnectorFactory(io.prestosql.connector.MockConnectorFactory) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) LocalQueryRunner(io.prestosql.testing.LocalQueryRunner) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with ConnectorViewDefinition

use of io.prestosql.spi.connector.ConnectorViewDefinition in project hetu-core by openlookeng.

the class TestRowFilter method init.

@BeforeClass
public void init() {
    LocalQueryRunner runner = new LocalQueryRunner(SESSION);
    runner.createCatalog(CATALOG, new TpchConnectorFactory(1), ImmutableMap.of());
    ConnectorViewDefinition view = new ConnectorViewDefinition("SELECT nationkey, name FROM local.tiny.nation", Optional.empty(), Optional.empty(), ImmutableList.of(new ConnectorViewDefinition.ViewColumn("nationkey", BigintType.BIGINT.getTypeSignature()), new ConnectorViewDefinition.ViewColumn("name", VarcharType.createVarcharType(25).getTypeSignature())), Optional.of(VIEW_OWNER), false);
    MockConnectorFactory mock = MockConnectorFactory.builder().withGetViews((s, prefix) -> ImmutableMap.<SchemaTableName, ConnectorViewDefinition>builder().put(new SchemaTableName("default", "nation_view"), view).build()).build();
    runner.createCatalog(MOCK_CATALOG, mock, ImmutableMap.of());
    assertions = new QueryAssertions(runner);
    accessControl = assertions.getQueryRunner().getAccessControl();
}
Also used : BigintType(io.prestosql.spi.type.BigintType) AfterClass(org.testng.annotations.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) TINY_SCHEMA_NAME(io.prestosql.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) BeforeClass(org.testng.annotations.BeforeClass) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) ViewExpression(io.prestosql.spi.security.ViewExpression) Identity(io.prestosql.spi.security.Identity) Test(org.testng.annotations.Test) MockConnectorFactory(io.prestosql.connector.MockConnectorFactory) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) TestingAccessControlManager(io.prestosql.testing.TestingAccessControlManager) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) LocalQueryRunner(io.prestosql.testing.LocalQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) Session(io.prestosql.Session) Optional(java.util.Optional) VarcharType(io.prestosql.spi.type.VarcharType) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) MockConnectorFactory(io.prestosql.connector.MockConnectorFactory) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) LocalQueryRunner(io.prestosql.testing.LocalQueryRunner) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with ConnectorViewDefinition

use of io.prestosql.spi.connector.ConnectorViewDefinition in project hetu-core by openlookeng.

the class MemoryMetadata method getViewDef.

private ConnectorViewDefinition getViewDef(SchemaTableName viewName) {
    // cache view def in the map to avoid deserializing it on every visit
    ConnectorViewDefinition view = views.get(viewName);
    if (view == null) {
        try {
            TableEntity tableEntity = getTableEntity(viewName, true);
            if (isView(tableEntity)) {
                view = VIEW_CODEC.fromJson(Base64.getDecoder().decode(tableEntity.getViewOriginalText()));
                views.put(viewName, view);
            }
        } catch (Exception e) {
            views.remove(viewName);
        }
    }
    return view;
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) ViewNotFoundException(io.prestosql.spi.connector.ViewNotFoundException) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) PrestoException(io.prestosql.spi.PrestoException) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition)

Example 4 with ConnectorViewDefinition

use of io.prestosql.spi.connector.ConnectorViewDefinition in project hetu-core by openlookeng.

the class TestHiveView method tesHiveView.

@Test(enabled = false)
public void tesHiveView() {
    SchemaTableName temporaryCreateView = temporaryTable("hive_view");
    String viewData = "test hive view";
    String expectedvViewData = "{\n" + "  \"originalSql\" : \"test hive view\",\n" + "  \"catalog\" : \"hive\",\n" + "  \"columns\" : [ {\n" + "    \"name\" : \"dummy\",\n" + "    \"type\" : \"varchar\"\n" + "  } ],\n" + "  \"owner\" : \"test\",\n" + "  \"runAsInvoker\" : false\n" + "}";
    String owner = "test";
    ConnectorSession session = newSession();
    HiveIdentity identity = new HiveIdentity(session);
    metastoreClient.createTable(identity, buildHiveView(temporaryCreateView, owner, viewData), buildInitialPrivilegeSet(owner));
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        Optional<ConnectorViewDefinition> views = metadata.getView(newSession(), temporaryCreateView);
        assertEquals(views.get().getOriginalSql(), expectedvViewData);
        assertTrue(metadata.listViews(newSession(), Optional.of(temporaryCreateView.getSchemaName())).contains(temporaryCreateView));
    } finally {
        metastoreClient.dropTable(identity, temporaryCreateView.getSchemaName(), temporaryCreateView.getTableName(), true);
    }
}
Also used : ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) Test(org.testng.annotations.Test)

Example 5 with ConnectorViewDefinition

use of io.prestosql.spi.connector.ConnectorViewDefinition in project hetu-core by openlookeng.

the class MetadataManager method getViews.

@Override
public Map<QualifiedObjectName, ConnectorViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, ConnectorViewDefinition> views = new LinkedHashMap<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
        for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
            ConnectorSession connectorSession = session.toConnectorSession(catalogName);
            Map<SchemaTableName, ConnectorViewDefinition> viewMap;
            if (tablePrefix.getTable().isPresent()) {
                viewMap = metadata.getView(connectorSession, tablePrefix.toSchemaTableName()).map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view)).orElse(ImmutableMap.of());
            } else {
                viewMap = metadata.getViews(connectorSession, tablePrefix.getSchema());
            }
            for (Entry<SchemaTableName, ConnectorViewDefinition> entry : viewMap.entrySet()) {
                QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                views.put(viewName, entry.getValue());
            }
        }
    }
    return ImmutableMap.copyOf(views);
}
Also used : SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) MetadataUtil.toSchemaTableName(io.prestosql.metadata.MetadataUtil.toSchemaTableName) MetadataUtil.convertFromSchemaTableName(io.prestosql.metadata.MetadataUtil.convertFromSchemaTableName) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) LinkedHashMap(java.util.LinkedHashMap) CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Aggregations

ConnectorViewDefinition (io.prestosql.spi.connector.ConnectorViewDefinition)19 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)12 Test (org.testng.annotations.Test)10 PrestoException (io.prestosql.spi.PrestoException)9 TableEntity (io.prestosql.spi.metastore.model.TableEntity)8 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)7 ImmutableList (com.google.common.collect.ImmutableList)5 DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)5 BeforeClass (org.testng.annotations.BeforeClass)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Session (io.prestosql.Session)4 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)4 Optional (java.util.Optional)4 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)3 ViewColumn (io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn)3 ColumnEntity (io.prestosql.spi.metastore.model.ColumnEntity)3 ArrayList (java.util.ArrayList)3 AfterClass (org.testng.annotations.AfterClass)3 Throwables.throwIfUnchecked (com.google.common.base.Throwables.throwIfUnchecked)2 ImmutableSet (com.google.common.collect.ImmutableSet)2