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();
}
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();
}
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;
}
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);
}
}
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);
}
Aggregations