Search in sources :

Example 1 with USER

use of io.prestosql.spi.security.PrincipalType.USER in project hetu-core by openlookeng.

the class ThriftMetastoreUtil method listApplicableTablePrivileges.

public static Stream<HivePrivilegeInfo> listApplicableTablePrivileges(SemiTransactionalHiveMetastore metastore, String databaseName, String tableName, String user) {
    HivePrincipal userPrincipal = new HivePrincipal(USER, user);
    Stream<HivePrincipal> principals = Stream.concat(Stream.of(userPrincipal), listApplicableRoles(metastore, userPrincipal).map(role -> new HivePrincipal(ROLE, role)));
    return listTablePrivileges(metastore, databaseName, tableName, principals);
}
Also used : NUMBER_OF_TRUE_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_TRUE_VALUES) Arrays(java.util.Arrays) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) RoleGrant(io.prestosql.spi.security.RoleGrant) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) BigDecimal(java.math.BigDecimal) BooleanColumnStatsData(org.apache.hadoop.hive.metastore.api.BooleanColumnStatsData) Math.round(java.lang.Math.round) Map(java.util.Map) RowType(io.prestosql.spi.type.RowType) DoubleColumnStatsData(org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData) BigInteger(java.math.BigInteger) ENGLISH(java.util.Locale.ENGLISH) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) HiveErrorCode(io.prestosql.plugin.hive.HiveErrorCode) Longs(com.google.common.primitives.Longs) DecimalColumnStatsData(org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData) ColumnStatisticsData.decimalStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.decimalStats) MAX_VALUE(io.prestosql.spi.statistics.ColumnStatisticType.MAX_VALUE) Set(java.util.Set) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) Stream(java.util.stream.Stream) Table(io.prestosql.plugin.hive.metastore.Table) Date(org.apache.hadoop.hive.metastore.api.Date) Database(io.prestosql.plugin.hive.metastore.Database) Partition(io.prestosql.plugin.hive.metastore.Partition) MIN_VALUE(io.prestosql.spi.statistics.ColumnStatisticType.MIN_VALUE) MapType(io.prestosql.spi.type.MapType) OptionalLong(java.util.OptionalLong) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) AVRO(io.prestosql.plugin.hive.HiveStorageFormat.AVRO) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) LongColumnStatsData(org.apache.hadoop.hive.metastore.api.LongColumnStatsData) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) Nullable(javax.annotation.Nullable) ColumnStatisticsData.binaryStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.binaryStats) AbstractIterator(com.google.common.collect.AbstractIterator) USER(io.prestosql.spi.security.PrincipalType.USER) MAX_VALUE_SIZE_IN_BYTES(io.prestosql.spi.statistics.ColumnStatisticType.MAX_VALUE_SIZE_IN_BYTES) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) StringColumnStatsData(org.apache.hadoop.hive.metastore.api.StringColumnStatsData) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) ColumnStatisticsData.longStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.longStats) DateColumnStatsData(org.apache.hadoop.hive.metastore.api.DateColumnStatsData) ArrayDeque(java.util.ArrayDeque) ColumnStatisticsData.stringStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.stringStats) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) PrincipalType(io.prestosql.spi.security.PrincipalType) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) ColumnStatisticsData.booleanStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.booleanStats) DecimalType(io.prestosql.spi.type.DecimalType) RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) ByteBuffer(java.nio.ByteBuffer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Locale(java.util.Locale) ColumnStatisticsData.doubleStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.doubleStats) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Type(io.prestosql.spi.type.Type) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ArrayType(io.prestosql.spi.type.ArrayType) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) Collection(java.util.Collection) Decimal(org.apache.hadoop.hive.metastore.api.Decimal) Order(org.apache.hadoop.hive.metastore.api.Order) SelectedRole(io.prestosql.spi.security.SelectedRole) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) Streams(com.google.common.collect.Streams) HiveType(io.prestosql.plugin.hive.HiveType) String.format(java.lang.String.format) NUMBER_OF_DISTINCT_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_DISTINCT_VALUES) List(java.util.List) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Queue(java.util.Queue) HiveBucketProperty(io.prestosql.plugin.hive.HiveBucketProperty) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) OptionalDouble(java.util.OptionalDouble) AVRO_SCHEMA_URL_KEY(io.prestosql.plugin.hive.HiveMetadata.AVRO_SCHEMA_URL_KEY) Shorts(com.google.common.primitives.Shorts) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal) Function(java.util.function.Function) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) HashSet(java.util.HashSet) ROLE(io.prestosql.spi.security.PrincipalType.ROLE) ColumnStatisticsData.dateStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.dateStats) BinaryColumnStatsData(org.apache.hadoop.hive.metastore.api.BinaryColumnStatsData) HivePrivilegeInfo(io.prestosql.plugin.hive.metastore.HivePrivilegeInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) DATE(io.prestosql.spi.type.DateType.DATE) REAL(io.prestosql.spi.type.RealType.REAL) TOTAL_SIZE_IN_BYTES(io.prestosql.spi.statistics.ColumnStatisticType.TOTAL_SIZE_IN_BYTES) NUMBER_OF_NON_NULL_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_NON_NULL_VALUES) CSV(io.prestosql.plugin.hive.HiveStorageFormat.CSV) PartitionWithStatistics(io.prestosql.plugin.hive.metastore.PartitionWithStatistics) ConnectorIdentity(io.prestosql.spi.security.ConnectorIdentity) PRIMITIVE(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category.PRIMITIVE) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Storage(io.prestosql.plugin.hive.metastore.Storage) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Column(io.prestosql.plugin.hive.metastore.Column) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal)

Example 2 with USER

use of io.prestosql.spi.security.PrincipalType.USER in project hetu-core by openlookeng.

the class TestFileBasedSystemAccessControl method testViewOperations.

@Test
public void testViewOperations() {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog.json");
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, alice, aliceView);
        accessControlManager.checkCanDropView(transactionId, alice, aliceView);
        accessControlManager.checkCanSelectFromColumns(transactionId, alice, aliceView, ImmutableSet.of());
        accessControlManager.checkCanCreateViewWithSelectFromColumns(transactionId, alice, aliceTable, ImmutableSet.of());
        accessControlManager.checkCanCreateViewWithSelectFromColumns(transactionId, alice, aliceView, ImmutableSet.of());
        accessControlManager.checkCanSetCatalogSessionProperty(transactionId, alice, "alice-catalog", "property");
        accessControlManager.checkCanGrantTablePrivilege(transactionId, alice, SELECT, aliceTable, new PrestoPrincipal(USER, "grantee"), true);
        accessControlManager.checkCanRevokeTablePrivilege(transactionId, alice, SELECT, aliceTable, new PrestoPrincipal(USER, "revokee"), true);
    });
    assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, bob, aliceView);
    }));
}
Also used : SECURITY_CONFIG_FILE(io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_CONFIG_FILE) TransactionManager(io.prestosql.transaction.TransactionManager) InterfaceTestUtils.assertAllMethodsOverridden(io.prestosql.spi.testing.InterfaceTestUtils.assertAllMethodsOverridden) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assert.assertThrows(org.testng.Assert.assertThrows) Thread.sleep(java.lang.Thread.sleep) TransactionBuilder.transaction(io.prestosql.transaction.TransactionBuilder.transaction) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) Files.newTemporaryFile(org.assertj.core.util.Files.newTemporaryFile) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Set(java.util.Set) Identity(io.prestosql.spi.security.Identity) USER(io.prestosql.spi.security.PrincipalType.USER) File(java.io.File) SystemAccessControl(io.prestosql.spi.security.SystemAccessControl) SECURITY_REFRESH_PERIOD(io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_REFRESH_PERIOD) Files.copy(com.google.common.io.Files.copy) Optional(java.util.Optional) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) SELECT(io.prestosql.spi.security.Privilege.SELECT) TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) Test(org.testng.annotations.Test)

Example 3 with USER

use of io.prestosql.spi.security.PrincipalType.USER in project boostkit-bigdata by kunpengcompute.

the class ThriftMetastoreUtil method listApplicableTablePrivileges.

public static Stream<HivePrivilegeInfo> listApplicableTablePrivileges(SemiTransactionalHiveMetastore metastore, String databaseName, String tableName, String user) {
    HivePrincipal userPrincipal = new HivePrincipal(USER, user);
    Stream<HivePrincipal> principals = Stream.concat(Stream.of(userPrincipal), listApplicableRoles(metastore, userPrincipal).map(role -> new HivePrincipal(ROLE, role)));
    return listTablePrivileges(metastore, databaseName, tableName, principals);
}
Also used : NUMBER_OF_TRUE_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_TRUE_VALUES) Arrays(java.util.Arrays) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) RoleGrant(io.prestosql.spi.security.RoleGrant) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) BigDecimal(java.math.BigDecimal) BooleanColumnStatsData(org.apache.hadoop.hive.metastore.api.BooleanColumnStatsData) Math.round(java.lang.Math.round) Map(java.util.Map) RowType(io.prestosql.spi.type.RowType) DoubleColumnStatsData(org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData) BigInteger(java.math.BigInteger) ENGLISH(java.util.Locale.ENGLISH) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) HiveErrorCode(io.prestosql.plugin.hive.HiveErrorCode) Longs(com.google.common.primitives.Longs) DecimalColumnStatsData(org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData) ColumnStatisticsData.decimalStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.decimalStats) MAX_VALUE(io.prestosql.spi.statistics.ColumnStatisticType.MAX_VALUE) Set(java.util.Set) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) Stream(java.util.stream.Stream) Table(io.prestosql.plugin.hive.metastore.Table) Date(org.apache.hadoop.hive.metastore.api.Date) Database(io.prestosql.plugin.hive.metastore.Database) Partition(io.prestosql.plugin.hive.metastore.Partition) MIN_VALUE(io.prestosql.spi.statistics.ColumnStatisticType.MIN_VALUE) MapType(io.prestosql.spi.type.MapType) OptionalLong(java.util.OptionalLong) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) AVRO(io.prestosql.plugin.hive.HiveStorageFormat.AVRO) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) LongColumnStatsData(org.apache.hadoop.hive.metastore.api.LongColumnStatsData) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) Nullable(javax.annotation.Nullable) ColumnStatisticsData.binaryStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.binaryStats) AbstractIterator(com.google.common.collect.AbstractIterator) USER(io.prestosql.spi.security.PrincipalType.USER) MAX_VALUE_SIZE_IN_BYTES(io.prestosql.spi.statistics.ColumnStatisticType.MAX_VALUE_SIZE_IN_BYTES) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) StringColumnStatsData(org.apache.hadoop.hive.metastore.api.StringColumnStatsData) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) ColumnStatisticsData.longStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.longStats) DateColumnStatsData(org.apache.hadoop.hive.metastore.api.DateColumnStatsData) ArrayDeque(java.util.ArrayDeque) ColumnStatisticsData.stringStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.stringStats) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) PrincipalType(io.prestosql.spi.security.PrincipalType) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) ColumnStatisticsData.booleanStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.booleanStats) DecimalType(io.prestosql.spi.type.DecimalType) RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) ByteBuffer(java.nio.ByteBuffer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Locale(java.util.Locale) ColumnStatisticsData.doubleStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.doubleStats) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Type(io.prestosql.spi.type.Type) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ArrayType(io.prestosql.spi.type.ArrayType) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) Collection(java.util.Collection) Decimal(org.apache.hadoop.hive.metastore.api.Decimal) Order(org.apache.hadoop.hive.metastore.api.Order) SelectedRole(io.prestosql.spi.security.SelectedRole) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) Streams(com.google.common.collect.Streams) HiveType(io.prestosql.plugin.hive.HiveType) String.format(java.lang.String.format) NUMBER_OF_DISTINCT_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_DISTINCT_VALUES) List(java.util.List) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Queue(java.util.Queue) HiveBucketProperty(io.prestosql.plugin.hive.HiveBucketProperty) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) OptionalDouble(java.util.OptionalDouble) AVRO_SCHEMA_URL_KEY(io.prestosql.plugin.hive.HiveMetadata.AVRO_SCHEMA_URL_KEY) Shorts(com.google.common.primitives.Shorts) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal) Function(java.util.function.Function) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) HashSet(java.util.HashSet) ROLE(io.prestosql.spi.security.PrincipalType.ROLE) ColumnStatisticsData.dateStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.dateStats) BinaryColumnStatsData(org.apache.hadoop.hive.metastore.api.BinaryColumnStatsData) HivePrivilegeInfo(io.prestosql.plugin.hive.metastore.HivePrivilegeInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) DATE(io.prestosql.spi.type.DateType.DATE) REAL(io.prestosql.spi.type.RealType.REAL) TOTAL_SIZE_IN_BYTES(io.prestosql.spi.statistics.ColumnStatisticType.TOTAL_SIZE_IN_BYTES) NUMBER_OF_NON_NULL_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_NON_NULL_VALUES) CSV(io.prestosql.plugin.hive.HiveStorageFormat.CSV) PartitionWithStatistics(io.prestosql.plugin.hive.metastore.PartitionWithStatistics) ConnectorIdentity(io.prestosql.spi.security.ConnectorIdentity) PRIMITIVE(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category.PRIMITIVE) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Storage(io.prestosql.plugin.hive.metastore.Storage) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Column(io.prestosql.plugin.hive.metastore.Column) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal)

Example 4 with USER

use of io.prestosql.spi.security.PrincipalType.USER in project hetu-core by openlookeng.

the class HiveMetadata method createTable.

@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
    SchemaTableName schemaTableName = tableMetadata.getTable();
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    List<String> partitionedBy = getPartitionedBy(tableMetadata.getProperties());
    Optional<HiveBucketProperty> bucketProperty = HiveTableProperties.getBucketProperty(tableMetadata.getProperties());
    if ((bucketProperty.isPresent() || !partitionedBy.isEmpty()) && HiveTableProperties.getAvroSchemaUrl(tableMetadata.getProperties()) != null) {
        throw new PrestoException(NOT_SUPPORTED, "Bucketing/Partitioning columns not supported when Avro schema url is set");
    }
    List<HiveColumnHandle> columnHandles = getColumnHandles(tableMetadata, ImmutableSet.copyOf(partitionedBy), typeTranslator);
    HiveStorageFormat hiveStorageFormat = HiveTableProperties.getHiveStorageFormat(tableMetadata.getProperties());
    Map<String, String> tableProperties = getEmptyTableProperties(tableMetadata, bucketProperty, new HdfsContext(session, schemaName, tableName));
    hiveStorageFormat.validateColumns(columnHandles);
    Map<String, HiveColumnHandle> columnHandlesByName = Maps.uniqueIndex(columnHandles, HiveColumnHandle::getName);
    List<Column> partitionColumns = partitionedBy.stream().map(columnHandlesByName::get).map(column -> new Column(column.getName(), column.getHiveType(), column.getComment())).collect(toList());
    checkPartitionTypesSupported(partitionColumns);
    boolean external = isExternalTable(tableMetadata.getProperties());
    String externalLocation = getExternalLocation(tableMetadata.getProperties());
    if ((external || (externalLocation != null)) && !createsOfNonManagedTablesEnabled) {
        throw new PrestoException(NOT_SUPPORTED, "Cannot create non-managed Hive table");
    }
    Path targetPath;
    Optional<String> location = getLocation(tableMetadata.getProperties());
    // User specifies the location property
    if (location.isPresent()) {
        if (!tableCreatesWithLocationAllowed) {
            throw new PrestoException(NOT_SUPPORTED, format("Setting %s property is not allowed", LOCATION_PROPERTY));
        }
        targetPath = getPath(new HdfsContext(session, schemaName, tableName), location.get(), external);
    } else {
        // User specifies external property, but location property is absent
        if (external) {
            throw new PrestoException(NOT_SUPPORTED, format("Cannot create external Hive table without location. Set it through '%s' property", LOCATION_PROPERTY));
        }
        // User specifies the external location property
        if (externalLocation != null) {
            external = true;
            targetPath = getPath(new HdfsContext(session, schemaName, tableName), externalLocation, true);
        } else // Default option
        {
            external = false;
            LocationHandle locationHandle = locationService.forNewTable(metastore, session, schemaName, tableName, Optional.empty(), Optional.empty(), HiveWriteUtils.OpertionType.CREATE_TABLE);
            targetPath = locationService.getQueryWriteInfo(locationHandle).getTargetPath();
        }
    }
    Table table = buildTableObject(session.getQueryId(), schemaName, tableName, session.getUser(), columnHandles, hiveStorageFormat, partitionedBy, bucketProperty, tableProperties, targetPath, external, prestoVersion);
    PrincipalPrivileges principalPrivileges = MetastoreUtil.buildInitialPrivilegeSet(table.getOwner());
    HiveBasicStatistics basicStatistics = table.getPartitionColumns().isEmpty() ? HiveBasicStatistics.createZeroStatistics() : HiveBasicStatistics.createEmptyStatistics();
    metastore.createTable(session, table, principalPrivileges, Optional.empty(), ignoreExisting, new PartitionStatistics(basicStatistics, ImmutableMap.of()));
}
Also used : TableStatistics(io.prestosql.spi.statistics.TableStatistics) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) PartialAndFinalAggregationType(io.prestosql.spi.PartialAndFinalAggregationType) FIELD_DELIM(org.apache.hadoop.hive.serde.serdeConstants.FIELD_DELIM) HiveUtil.verifyPartitionTypeSupported(io.prestosql.plugin.hive.HiveUtil.verifyPartitionTypeSupported) FileSystem(org.apache.hadoop.fs.FileSystem) HIVE_FILESYSTEM_ERROR(io.prestosql.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR) HiveUtil.hiveColumnHandles(io.prestosql.plugin.hive.HiveUtil.hiveColumnHandles) MetastoreUtil(io.prestosql.plugin.hive.metastore.MetastoreUtil) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) NullableValue(io.prestosql.spi.predicate.NullableValue) RoleGrant(io.prestosql.spi.security.RoleGrant) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) FileStatus(org.apache.hadoop.fs.FileStatus) SCHEMA_NOT_EMPTY(io.prestosql.spi.StandardErrorCode.SCHEMA_NOT_EMPTY) HiveUtil.getPartitionKeyColumnHandles(io.prestosql.plugin.hive.HiveUtil.getPartitionKeyColumnHandles) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) Future(java.util.concurrent.Future) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) BucketingVersion(io.prestosql.plugin.hive.HiveBucketing.BucketingVersion) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) Map(java.util.Map) HiveTableProperties.getPartitionedBy(io.prestosql.plugin.hive.HiveTableProperties.getPartitionedBy) ENGLISH(java.util.Locale.ENGLISH) ConstraintApplicationResult(io.prestosql.spi.connector.ConstraintApplicationResult) SystemTable(io.prestosql.spi.connector.SystemTable) GrantInfo(io.prestosql.spi.security.GrantInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) org.apache.hadoop.hive.serde.serdeConstants(org.apache.hadoop.hive.serde.serdeConstants) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) Set(java.util.Set) LOCATION_PROPERTY(io.prestosql.plugin.hive.HiveTableProperties.LOCATION_PROPERTY) HiveTableProperties.getTransactionalValue(io.prestosql.plugin.hive.HiveTableProperties.getTransactionalValue) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) Collectors.joining(java.util.stream.Collectors.joining) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) Table(io.prestosql.plugin.hive.metastore.Table) Privilege(io.prestosql.spi.security.Privilege) INVALID_TABLE_PROPERTY(io.prestosql.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) HiveTableProperties.isExternalTable(io.prestosql.plugin.hive.HiveTableProperties.isExternalTable) Domain(io.prestosql.spi.predicate.Domain) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) AccessControlMetadata(io.prestosql.plugin.hive.security.AccessControlMetadata) ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) ORC(io.prestosql.plugin.hive.HiveStorageFormat.ORC) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) Joiner(com.google.common.base.Joiner) Iterables(com.google.common.collect.Iterables) Database(io.prestosql.plugin.hive.metastore.Database) Slice(io.airlift.slice.Slice) Partition(io.prestosql.plugin.hive.metastore.Partition) TRANSACTIONAL(io.prestosql.plugin.hive.HiveTableProperties.TRANSACTIONAL) HiveWriterFactory.getSnapshotSubFileIndex(io.prestosql.plugin.hive.HiveWriterFactory.getSnapshotSubFileIndex) Supplier(java.util.function.Supplier) ComputedStatistics(io.prestosql.spi.statistics.ComputedStatistics) ArrayList(java.util.ArrayList) HiveUtil.decodeViewData(io.prestosql.plugin.hive.HiveUtil.decodeViewData) OptionalLong(java.util.OptionalLong) TupleDomain.withColumnDomains(io.prestosql.spi.predicate.TupleDomain.withColumnDomains) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConnectorPartitioningHandle(io.prestosql.spi.connector.ConnectorPartitioningHandle) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) RecordCursor(io.prestosql.spi.connector.RecordCursor) DiscretePredicates(io.prestosql.spi.connector.DiscretePredicates) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) HiveWriterFactory.removeSnapshotFileName(io.prestosql.plugin.hive.HiveWriterFactory.removeSnapshotFileName) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) Properties(java.util.Properties) HiveUtil.isPrestoView(io.prestosql.plugin.hive.HiveUtil.isPrestoView) TypeManager(io.prestosql.spi.type.TypeManager) IOException(java.io.IOException) USER(io.prestosql.spi.security.PrincipalType.USER) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Streams.stream(com.google.common.collect.Streams.stream) IS_EXTERNAL_TABLE(io.prestosql.plugin.hive.HiveTableProperties.IS_EXTERNAL_TABLE) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ConnectorTablePartitioning(io.prestosql.spi.connector.ConnectorTablePartitioning) TableType(org.apache.hadoop.hive.metastore.TableType) ConfigurationUtils(io.prestosql.plugin.hive.util.ConfigurationUtils) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) HiveWriterFactory.isSnapshotFile(io.prestosql.plugin.hive.HiveWriterFactory.isSnapshotFile) VarcharType(io.prestosql.spi.type.VarcharType) HiveTableProperties.getLocation(io.prestosql.plugin.hive.HiveTableProperties.getLocation) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) Statistics(io.prestosql.plugin.hive.util.Statistics) URL(java.net.URL) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext) EXTERNAL_TABLE(org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE) ViewNotFoundException(io.prestosql.spi.connector.ViewNotFoundException) HiveTableProperties.getHiveStorageFormat(io.prestosql.plugin.hive.HiveTableProperties.getHiveStorageFormat) Duration(io.airlift.units.Duration) TableStatisticType(io.prestosql.spi.statistics.TableStatisticType) FileSinkOperator(org.apache.hadoop.hive.ql.exec.FileSinkOperator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) INVALID_ANALYZE_PROPERTY(io.prestosql.spi.StandardErrorCode.INVALID_ANALYZE_PROPERTY) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Collectors.toMap(java.util.stream.Collectors.toMap) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) Iterables.concat(com.google.common.collect.Iterables.concat) Path(org.apache.hadoop.fs.Path) Type(io.prestosql.spi.type.Type) Splitter(com.google.common.base.Splitter) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Collectors.toSet(java.util.stream.Collectors.toSet) Constraint(io.prestosql.spi.connector.Constraint) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) HiveWriteUtils.isS3FileSystem(io.prestosql.plugin.hive.HiveWriteUtils.isS3FileSystem) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) HiveUtil.columnExtraInfo(io.prestosql.plugin.hive.HiveUtil.columnExtraInfo) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) HiveUtil.encodeViewData(io.prestosql.plugin.hive.HiveUtil.encodeViewData) HiveWriterFactory.isSnapshotSubFile(io.prestosql.plugin.hive.HiveWriterFactory.isSnapshotSubFile) ROW_COUNT(io.prestosql.spi.statistics.TableStatisticType.ROW_COUNT) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) List(java.util.List) PRESTO_VIEW_FLAG(io.prestosql.plugin.hive.HiveUtil.PRESTO_VIEW_FLAG) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) Function.identity(java.util.function.Function.identity) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils) HiveStatisticsProvider(io.prestosql.plugin.hive.statistics.HiveStatisticsProvider) JsonCodec(io.airlift.json.JsonCodec) IntStream(java.util.stream.IntStream) ConnectorOutputMetadata(io.prestosql.spi.connector.ConnectorOutputMetadata) Logger(io.airlift.log.Logger) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) ConnectorNewTableLayout(io.prestosql.spi.connector.ConnectorNewTableLayout) HashMap(java.util.HashMap) HiveUtil.toPartitionValues(io.prestosql.plugin.hive.HiveUtil.toPartitionValues) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) HashSet(java.util.HashSet) HiveTableProperties.getExternalLocation(io.prestosql.plugin.hive.HiveTableProperties.getExternalLocation) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) OpenCSVSerde(org.apache.hadoop.hive.serde2.OpenCSVSerde) INVALID_SCHEMA_PROPERTY(io.prestosql.spi.StandardErrorCode.INVALID_SCHEMA_PROPERTY) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) Suppliers(com.google.common.base.Suppliers) NoSuchElementException(java.util.NoSuchElementException) Block(io.prestosql.spi.block.Block) VerifyException(com.google.common.base.VerifyException) Collections.emptyMap(java.util.Collections.emptyMap) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) MalformedURLException(java.net.MalformedURLException) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) NON_INHERITABLE_PROPERTIES(io.prestosql.plugin.hive.HiveTableProperties.NON_INHERITABLE_PROPERTIES) Maps(com.google.common.collect.Maps) PRIMITIVE(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category.PRIMITIVE) JobConf(org.apache.hadoop.mapred.JobConf) Collectors.toList(java.util.stream.Collectors.toList) Column(io.prestosql.plugin.hive.metastore.Column) GENERIC_USER_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_USER_ERROR) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) HiveBucketing.bucketedOnTimestamp(io.prestosql.plugin.hive.HiveBucketing.bucketedOnTimestamp) Path(org.apache.hadoop.fs.Path) SystemTable(io.prestosql.spi.connector.SystemTable) Table(io.prestosql.plugin.hive.metastore.Table) HiveTableProperties.isExternalTable(io.prestosql.plugin.hive.HiveTableProperties.isExternalTable) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) HiveTableProperties.getHiveStorageFormat(io.prestosql.plugin.hive.HiveTableProperties.getHiveStorageFormat) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) Column(io.prestosql.plugin.hive.metastore.Column) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)

Example 5 with USER

use of io.prestosql.spi.security.PrincipalType.USER in project hetu-core by openlookeng.

the class SqlStandardAccessControlMetadata method revokeTablePrivileges.

@Override
public void revokeTablePrivileges(ConnectorSession session, SchemaTableName schemaTableName, Set<Privilege> privileges, HivePrincipal grantee, boolean grantOption) {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    Set<HivePrivilegeInfo> hivePrivilegeInfos = privileges.stream().map(privilege -> new HivePrivilegeInfo(toHivePrivilege(privilege), grantOption, new HivePrincipal(USER, session.getUser()), new HivePrincipal(USER, session.getUser()))).collect(toSet());
    metastore.revokeTablePrivileges(schemaName, tableName, grantee, hivePrivilegeInfos);
}
Also used : ALREADY_EXISTS(io.prestosql.spi.StandardErrorCode.ALREADY_EXISTS) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) HivePrivilegeInfo.toHivePrivilege(io.prestosql.plugin.hive.metastore.HivePrivilegeInfo.toHivePrivilege) ThriftMetastoreUtil.listEnabledPrincipals(io.prestosql.plugin.hive.metastore.thrift.ThriftMetastoreUtil.listEnabledPrincipals) GrantInfo(io.prestosql.spi.security.GrantInfo) Set(java.util.Set) RoleGrant(io.prestosql.spi.security.RoleGrant) PrivilegeInfo(io.prestosql.spi.security.PrivilegeInfo) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal) USER(io.prestosql.spi.security.PrincipalType.USER) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Privilege(io.prestosql.spi.security.Privilege) HivePrivilegeInfo(io.prestosql.plugin.hive.metastore.HivePrivilegeInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) ThriftMetastoreUtil(io.prestosql.plugin.hive.metastore.thrift.ThriftMetastoreUtil) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) ENGLISH(java.util.Locale.ENGLISH) Collectors.toSet(java.util.stream.Collectors.toSet) HivePrivilegeInfo(io.prestosql.plugin.hive.metastore.HivePrivilegeInfo) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)9 USER (io.prestosql.spi.security.PrincipalType.USER)9 Optional (java.util.Optional)9 Set (java.util.Set)9 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)8 HivePrincipal (io.prestosql.plugin.hive.metastore.HivePrincipal)8 SemiTransactionalHiveMetastore (io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore)8 PrestoException (io.prestosql.spi.PrestoException)8 RoleGrant (io.prestosql.spi.security.RoleGrant)8 ImmutableList (com.google.common.collect.ImmutableList)6 HivePrivilegeInfo (io.prestosql.plugin.hive.metastore.HivePrivilegeInfo)6 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)6 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)6 GrantInfo (io.prestosql.spi.security.GrantInfo)6 Privilege (io.prestosql.spi.security.Privilege)6 List (java.util.List)6 ENGLISH (java.util.Locale.ENGLISH)6 Objects.requireNonNull (java.util.Objects.requireNonNull)6 Collectors.toSet (java.util.stream.Collectors.toSet)6 ImmutableMap (com.google.common.collect.ImmutableMap)5