Search in sources :

Example 1 with CatalogSchemaName

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()));
    }
}
Also used : CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) PrestoException(io.prestosql.spi.PrestoException) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName)

Example 2 with CatalogSchemaName

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);
    }
}
Also used : FunctionMetadata(io.prestosql.spi.function.FunctionMetadata) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) Parameter(io.prestosql.spi.function.Parameter) PrestoException(io.prestosql.spi.PrestoException) InMemoryFunctionNamespaceManager(io.hetu.core.plugin.functionnamespace.memory.InMemoryFunctionNamespaceManager) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName)

Example 3 with CatalogSchemaName

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);
}
Also used : FunctionMetadata(io.prestosql.spi.function.FunctionMetadata) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) Parameter(io.prestosql.spi.function.Parameter) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 4 with CatalogSchemaName

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);
}
Also used : CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) Test(org.testng.annotations.Test)

Example 5 with 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) {
    }
}
Also used : AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) ConnectorIdentity(io.prestosql.spi.security.ConnectorIdentity) Identity(io.prestosql.spi.security.Identity) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) CatalogSchemaTableName(io.prestosql.spi.connector.CatalogSchemaTableName) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Test(org.testng.annotations.Test)

Aggregations

CatalogSchemaName (io.prestosql.spi.connector.CatalogSchemaName)10 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)5 SqlInvokedFunction (io.prestosql.spi.function.SqlInvokedFunction)5 PrestoException (io.prestosql.spi.PrestoException)4 Session (io.prestosql.Session)3 MetadataUtil.createCatalogSchemaName (io.prestosql.metadata.MetadataUtil.createCatalogSchemaName)3 Parameter (io.prestosql.spi.function.Parameter)3 SemanticException (io.prestosql.sql.analyzer.SemanticException)3 Test (org.testng.annotations.Test)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ExternalFunctionInfo (io.prestosql.spi.function.ExternalFunctionInfo)2 FunctionMetadata (io.prestosql.spi.function.FunctionMetadata)2 RoutineCharacteristics (io.prestosql.spi.function.RoutineCharacteristics)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InMemoryFunctionNamespaceManager (io.hetu.core.plugin.functionnamespace.memory.InMemoryFunctionNamespaceManager)1 CatalogName (io.prestosql.spi.connector.CatalogName)1 CatalogSchemaTableName (io.prestosql.spi.connector.CatalogSchemaTableName)1 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)1