use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.
the class FunctionNamespaceTestCommon method createFunction.
/**
* create function
*/
public void createFunction(AbstractSqlInvokedFunctionNamespaceManager functionNamespaceManager, String functionName, List<Parameter> parameters) {
QualifiedObjectName powerTower = QualifiedObjectName.valueOf(new CatalogSchemaName(this.catalogName, funcNsSchemaName), functionName);
SqlInvokedFunction function = new SqlInvokedFunction(powerTower, parameters, parseTypeSignature(DOUBLE), "power tower test", RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).setLanguage(JDBC).build(), "RETURN pow(x, x)", ImmutableMap.of("executor", "mysql"), Optional.empty());
try {
functionNamespaceManager.createFunction(function, false);
} catch (PrestoException e) {
fail(format("Create function(id=%s) failed.", function.getFunctionId().toString()));
}
}
use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.
the class FunctionNamespaceTestCommon method testGetFunction.
/**
* test get function
*/
public void testGetFunction(AbstractSqlInvokedFunctionNamespaceManager functionNamespaceManager) {
QualifiedObjectName powerTower = QualifiedObjectName.valueOf(new CatalogSchemaName(this.catalogName, funcNsSchemaName), functionName);
List<Parameter> parameters = ImmutableList.of(new Parameter("x", parseTypeSignature(DOUBLE)));
List<Parameter> parameters1 = ImmutableList.of(new Parameter("y", parseTypeSignature(INTEGER)), new Parameter("x", parseTypeSignature(DOUBLE)));
String funcDesc = "power tower test";
String funcBody = "RETURN pow(x, x)";
Map<String, String> funcProperties = ImmutableMap.of("executor", "mysql");
SqlInvokedFunction function = new SqlInvokedFunction(powerTower, parameters, parseTypeSignature(DOUBLE), funcDesc, RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).setLanguage(JDBC).build(), funcBody, funcProperties, Optional.empty());
SqlInvokedFunction function1 = new SqlInvokedFunction(powerTower, parameters1, parseTypeSignature(DOUBLE), funcDesc, RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).setLanguage(JDBC).build(), funcBody, funcProperties, Optional.empty());
try {
functionNamespaceManager.createFunction(function, false);
functionNamespaceManager.createFunction(function1, false);
} catch (PrestoException e) {
fail(format("Create function(id=%s) failed.", function.getFunctionId().toString()));
}
if ((functionNamespaceManager instanceof InMemoryFunctionNamespaceManager)) {
// trans to InMemoryFunctionNamespaceManager obj for sub classes method test
InMemoryFunctionNamespaceManager manager = (InMemoryFunctionNamespaceManager) functionNamespaceManager;
List<SqlInvokedFunction> storedFunc = manager.listFunctions();
assertTrue(storedFunc.size() == 2);
storedFunc = manager.fetchFunctionsDirect(powerTower);
assertTrue(storedFunc.size() == 2);
Optional<SqlInvokedFunction> singleFunc = manager.fetchFunctionsDirect(powerTower, parameters.stream().map(x -> x.getType()).collect(Collectors.toList()));
assertTrue(singleFunc.isPresent());
FunctionMetadata funcMeta = manager.fetchFunctionMetadataDirect(singleFunc.get().getFunctionHandle().get());
assertEquals(funcMeta.getName(), powerTower);
}
}
use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.
the class TestInMemoryManager method testCreateAndGetFunction.
/**
* test get function
*/
@Test
public void testCreateAndGetFunction() {
QualifiedObjectName powerTower = QualifiedObjectName.valueOf(new CatalogSchemaName(this.catalogName, funcNsSchemaName), functionName);
List<Parameter> parameters = ImmutableList.of(new Parameter("x", parseTypeSignature(DOUBLE)));
List<Parameter> parameters1 = ImmutableList.of(new Parameter("y", parseTypeSignature(INTEGER)), new Parameter("x", parseTypeSignature(DOUBLE)));
testProc.createFunction(functionNamespaceManager, functionName, parameters);
testProc.createFunction(functionNamespaceManager, functionName, parameters1);
List<SqlInvokedFunction> storedFunc = functionNamespaceManager.listFunctions();
assertTrue(storedFunc.size() == 2);
storedFunc = functionNamespaceManager.fetchFunctionsDirect(powerTower);
assertTrue(storedFunc.size() == 2);
Optional<SqlInvokedFunction> singleFunc = functionNamespaceManager.fetchFunctionsDirect(powerTower, parameters.stream().map(x -> x.getType()).collect(Collectors.toList()));
assertTrue(singleFunc.isPresent());
FunctionMetadata funcMeta = functionNamespaceManager.fetchFunctionMetadataDirect(singleFunc.get().getFunctionHandle().get());
assertEquals(funcMeta.getName(), powerTower);
}
use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.
the class TestJdbcExternalFunctionHub method testGetExternalFunctionCatalogSchemaName.
@Test
public void testGetExternalFunctionCatalogSchemaName() {
CatalogSchemaName catalogSchemaName = new CatalogSchemaName("jdbc", "foo");
assertEquals(jdbcExternalFunctionHub.getExternalFunctionCatalogSchemaName().get(), catalogSchemaName);
}
use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.
the class TestAccessControlManager method testReadOnlySystemAccessControl.
@Test
public void testReadOnlySystemAccessControl() {
Identity identity = new Identity(USER_NAME, Optional.of(PRINCIPAL));
QualifiedObjectName tableName = new QualifiedObjectName("catalog", "schema", "table");
TransactionManager transactionManager = createTestTransactionManager();
AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
accessControlManager.setSystemAccessControl(ReadOnlySystemAccessControl.NAME, ImmutableMap.of());
accessControlManager.checkCanSetUser(Optional.of(PRINCIPAL), USER_NAME);
accessControlManager.checkCanSetSystemSessionProperty(identity, "property");
transaction(transactionManager, accessControlManager).execute(transactionId -> {
accessControlManager.checkCanSetCatalogSessionProperty(transactionId, identity, "catalog", "property");
accessControlManager.checkCanShowSchemas(transactionId, identity, "catalog");
accessControlManager.checkCanShowTablesMetadata(transactionId, identity, new CatalogSchemaName("catalog", "schema"));
accessControlManager.checkCanSelectFromColumns(transactionId, identity, tableName, ImmutableSet.of("column"));
accessControlManager.checkCanCreateViewWithSelectFromColumns(transactionId, identity, tableName, ImmutableSet.of("column"));
Set<String> catalogs = ImmutableSet.of("catalog");
assertEquals(accessControlManager.filterCatalogs(identity, catalogs), catalogs);
Set<String> schemas = ImmutableSet.of("schema");
assertEquals(accessControlManager.filterSchemas(transactionId, identity, "catalog", schemas), schemas);
Set<SchemaTableName> tableNames = ImmutableSet.of(new SchemaTableName("schema", "table"));
assertEquals(accessControlManager.filterTables(transactionId, identity, "catalog", tableNames), tableNames);
});
try {
transaction(transactionManager, accessControlManager).execute(transactionId -> {
accessControlManager.checkCanInsertIntoTable(transactionId, identity, tableName);
});
fail();
} catch (AccessDeniedException expected) {
}
}
Aggregations