Search in sources :

Example 26 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class TestAccessControlManager method testDenySystemAccessControl.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Access Denied: Cannot select from table secured_catalog.schema.table")
public void testDenySystemAccessControl() {
    CatalogManager catalogManager = new CatalogManager();
    TransactionManager transactionManager = createTestTransactionManager(catalogManager);
    AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
    TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("test");
    accessControlManager.addSystemAccessControlFactory(accessControlFactory);
    accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
    registerBogusConnector(catalogManager, transactionManager, accessControlManager, "connector");
    accessControlManager.addCatalogAccessControl(new ConnectorId("connector"), new DenyConnectorAccessControl());
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanSelectFromColumns(transactionId, new Identity(USER_NAME, Optional.of(PRINCIPAL)), new AccessControlContext(new QueryId(QUERY_ID), Optional.empty(), Optional.empty()), new QualifiedObjectName("secured_catalog", "schema", "table"), ImmutableSet.of("column"));
    });
}
Also used : AccessControlContext(com.facebook.presto.spi.security.AccessControlContext) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) QueryId(com.facebook.presto.spi.QueryId) Identity(com.facebook.presto.spi.security.Identity) ConnectorIdentity(com.facebook.presto.spi.security.ConnectorIdentity) CatalogManager(com.facebook.presto.metadata.CatalogManager) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 27 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class MySqlFunctionNamespaceManager method createFunction.

@Override
public void createFunction(SqlInvokedFunction function, boolean replace) {
    checkCatalog(function);
    checkFunctionLanguageSupported(function);
    checkArgument(!function.hasVersion(), "function '%s' is already versioned", function);
    QualifiedObjectName functionName = function.getFunctionId().getFunctionName();
    checkFieldLength("Catalog name", functionName.getCatalogName(), MAX_CATALOG_NAME_LENGTH);
    checkFieldLength("Schema name", functionName.getSchemaName(), MAX_SCHEMA_NAME_LENGTH);
    if (!functionNamespaceDao.functionNamespaceExists(functionName.getCatalogName(), functionName.getSchemaName())) {
        throw new PrestoException(NOT_FOUND, format("Function namespace not found: %s", functionName.getCatalogSchemaName()));
    }
    checkFieldLength("Function name", functionName.getObjectName(), MAX_FUNCTION_NAME_LENGTH);
    if (function.getParameters().size() > MAX_PARAMETER_COUNT) {
        throw new PrestoException(GENERIC_USER_ERROR, format("Function has more than %s parameters: %s", MAX_PARAMETER_COUNT, function.getParameters().size()));
    }
    for (Parameter parameter : function.getParameters()) {
        checkFieldLength("Parameter name", parameter.getName(), MAX_PARAMETER_NAME_LENGTH);
    }
    checkFieldLength("Parameter type list", function.getFunctionId().getArgumentTypes().stream().map(TypeSignature::toString).collect(joining(",")), MAX_PARAMETER_TYPES_LENGTH);
    checkFieldLength("Return type", function.getSignature().getReturnType().toString(), MAX_RETURN_TYPE_LENGTH);
    jdbi.useTransaction(handle -> {
        FunctionNamespaceDao transactionDao = handle.attach(functionNamespaceDaoClass);
        Optional<SqlInvokedFunctionRecord> latestVersion = transactionDao.getLatestRecordForUpdate(hash(function.getFunctionId()), function.getFunctionId());
        if (!replace && latestVersion.isPresent() && !latestVersion.get().isDeleted()) {
            throw new PrestoException(ALREADY_EXISTS, "Function already exists: " + function.getFunctionId());
        }
        if (!latestVersion.isPresent() || !latestVersion.get().getFunction().hasSameDefinitionAs(function)) {
            long newVersion = latestVersion.map(SqlInvokedFunctionRecord::getFunction).map(MySqlFunctionNamespaceManager::getLongVersion).orElse(0L) + 1;
            insertSqlInvokedFunction(transactionDao, function, newVersion);
        } else if (latestVersion.get().isDeleted()) {
            SqlInvokedFunction latest = latestVersion.get().getFunction();
            checkState(latest.hasVersion(), "Function version missing: %s", latest.getFunctionId());
            transactionDao.setDeletionStatus(hash(latest.getFunctionId()), latest.getFunctionId(), getLongVersion(latest), false);
        }
    });
    refreshFunctionsCache(functionName);
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) Parameter(com.facebook.presto.spi.function.Parameter) PrestoException(com.facebook.presto.spi.PrestoException) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 28 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class MySqlFunctionNamespaceManager method insertSqlInvokedFunction.

private void insertSqlInvokedFunction(FunctionNamespaceDao functionNamespaceDao, SqlInvokedFunction function, long version) {
    QualifiedObjectName functionName = function.getFunctionId().getFunctionName();
    functionNamespaceDao.insertFunction(hash(function.getFunctionId()), function.getFunctionId(), version, functionName.getCatalogName(), functionName.getSchemaName(), functionName.getObjectName(), function.getParameters(), function.getSignature().getReturnType(), function.getDescription(), function.getRoutineCharacteristics(), function.getBody());
}
Also used : QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 29 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class MySqlFunctionNamespaceManager method addUserDefinedType.

@Override
public void addUserDefinedType(UserDefinedType type) {
    jdbi.useTransaction(handle -> {
        FunctionNamespaceDao transactionDao = handle.attach(functionNamespaceDaoClass);
        QualifiedObjectName typeName = type.getUserDefinedTypeName();
        if (functionNamespaceDao.typeExists(typeName.getCatalogName(), typeName.getSchemaName(), typeName.getObjectName())) {
            throw new PrestoException(ALREADY_EXISTS, format("Type %s already exists", typeName));
        }
        transactionDao.insertUserDefinedType(typeName.getCatalogName(), typeName.getSchemaName(), typeName.getObjectName(), type.getPhysicalTypeSignature().toString());
    });
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 30 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class TestMySqlFunctionNamespaceManager method testSchemaNameTooLong.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Schema name exceeds max length of 128.*")
public void testSchemaNameTooLong() {
    QualifiedObjectName functionName = QualifiedObjectName.valueOf(TEST_CATALOG, dummyString(129), "tangent");
    createFunction(createFunctionTangent(functionName), false);
}
Also used : QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Test(org.testng.annotations.Test)

Aggregations

QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)59 TableHandle (com.facebook.presto.spi.TableHandle)20 Metadata (com.facebook.presto.metadata.Metadata)15 Session (com.facebook.presto.Session)14 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)14 List (java.util.List)13 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)12 ConnectorId (com.facebook.presto.spi.ConnectorId)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 Map (java.util.Map)11 Objects.requireNonNull (java.util.Objects.requireNonNull)11 Optional (java.util.Optional)11 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)10 TransactionManager (com.facebook.presto.transaction.TransactionManager)10 Type (com.facebook.presto.common.type.Type)9 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 PrestoException (com.facebook.presto.spi.PrestoException)9 WarningCollector (com.facebook.presto.spi.WarningCollector)9 Expression (com.facebook.presto.sql.tree.Expression)9 ImmutableList (com.google.common.collect.ImmutableList)9