org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet Java Examples
The following examples show how to use
org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CatalogThriftHiveMetastore.java From metacat with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public PrincipalPrivilegeSet get_privilege_set(final HiveObjectRef hiveObject, final String userName, final List<String> groupNames) throws TException { MetacatContextManager.getContext().setUserName(userName); return requestWrapper("get_privilege_set", new Object[]{hiveObject, userName, groupNames}, () -> { Map<String, List<PrivilegeGrantInfo>> groupPrivilegeSet = null; Map<String, List<PrivilegeGrantInfo>> userPrivilegeSet = null; if (groupNames != null) { groupPrivilegeSet = groupNames.stream() .collect(Collectors.toMap(p -> p, p -> Lists.newArrayList())); } if (userName != null) { userPrivilegeSet = ImmutableMap.of(userName, Lists.newArrayList()); } return new PrincipalPrivilegeSet(userPrivilegeSet, groupPrivilegeSet, defaultRolesPrivilegeSet); }); }
Example #2
Source File: PartitionAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 6 votes |
@Test public void allShortCircuit() { left.getPartition().getParameters().put("com.company.key", "value"); left.getPartition().setValues(ImmutableList.of("p1", "p2")); List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getPartition().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); left.getPartition().getSd().setLocation("left"); left.getPartition().getSd().setInputFormat("LeftInputFormat"); left.getPartition().getSd().setOutputFormat("LeftOutputFormat"); left.getPartition().getSd().getParameters().put("com.company.key", "value"); left.getPartition().getSd().getSerdeInfo().setName("left serde info"); left.getPartition().getSd().getSkewedInfo().setSkewedColNames(ImmutableList.of("left skewed col")); left.getPartition().getSd().setCols(ImmutableList.of(new FieldSchema("left", "type", "comment"))); left.getPartition().getSd().setSortCols(ImmutableList.of(new Order())); left.getPartition().getSd().setBucketCols(ImmutableList.of("bucket")); left.getPartition().getSd().setNumBuckets(9000); List<Diff<Object, Object>> diffs = newPartitionAndMetadataComparator(SHORT_CIRCUIT).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(1)); assertThat(diffs.get(0), is(newPropertyDiff(PartitionAndMetadata.class, "partition.parameters", left.getPartition().getParameters(), right.getPartition().getParameters()))); }
Example #3
Source File: PartitionAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 5 votes |
@Test public void privilegesShortCircuit() { List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getPartition().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); List<Diff<Object, Object>> diffs = newPartitionAndMetadataComparator(SHORT_CIRCUIT).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(0)); }
Example #4
Source File: FederatedHMSHandlerTest.java From waggle-dance with Apache License 2.0 | 5 votes |
@Test public void getPrivilegeSetDbNameIsNullShouldUsePrimary() throws TException { String userName = "user"; List<String> groupNames = Lists.newArrayList("group"); HiveObjectRef hiveObjectRef = new HiveObjectRef(); hiveObjectRef.setDbName(null); when(primaryMapping.transformInboundHiveObjectRef(hiveObjectRef)).thenReturn(hiveObjectRef); PrincipalPrivilegeSet principalPrivilegeSet = new PrincipalPrivilegeSet(); when(primaryClient.get_privilege_set(hiveObjectRef, userName, groupNames)).thenReturn(principalPrivilegeSet); PrincipalPrivilegeSet result = handler.get_privilege_set(hiveObjectRef, userName, groupNames); assertThat(result, is(principalPrivilegeSet)); verify(databaseMappingService, never()).databaseMapping(DB_P); }
Example #5
Source File: FederatedHMSHandlerTest.java From waggle-dance with Apache License 2.0 | 5 votes |
@Test public void getPrivilegeSet() throws TException { String userName = "user"; List<String> groupNames = Lists.newArrayList("group"); HiveObjectRef hiveObjectRef = new HiveObjectRef(); hiveObjectRef.setDbName(DB_P); when(databaseMappingService.databaseMapping(DB_P)).thenReturn(primaryMapping); when(primaryMapping.transformInboundHiveObjectRef(hiveObjectRef)).thenReturn(hiveObjectRef); PrincipalPrivilegeSet principalPrivilegeSet = new PrincipalPrivilegeSet(); when(primaryClient.get_privilege_set(hiveObjectRef, userName, groupNames)).thenReturn(principalPrivilegeSet); PrincipalPrivilegeSet result = handler.get_privilege_set(hiveObjectRef, userName, groupNames); assertThat(result, is(principalPrivilegeSet)); }
Example #6
Source File: FederatedHMSHandler.java From waggle-dance with Apache License 2.0 | 5 votes |
@Override @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME) public PrincipalPrivilegeSet get_privilege_set(HiveObjectRef hiveObject, String user_name, List<String> group_names) throws MetaException, TException { DatabaseMapping mapping; if (hiveObject.getDbName() == null) { mapping = databaseMappingService.primaryDatabaseMapping(); } else { mapping = databaseMappingService.databaseMapping(hiveObject.getDbName()); } return mapping.getClient().get_privilege_set(mapping.transformInboundHiveObjectRef(hiveObject), user_name, group_names); }
Example #7
Source File: PartitionTransformationTest.java From circus-train with Apache License 2.0 | 5 votes |
@Before public void init() { partition = new Partition(); partition.setDbName("database"); partition.setTableName("table"); partition.setValues(ImmutableList.of("part")); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); partition.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(Arrays.asList(new FieldSchema("a", "int", null))); storageDescriptor.setInputFormat("input_format"); storageDescriptor.setOutputFormat("output_format"); storageDescriptor.setSerdeInfo(new SerDeInfo("serde", "lib", new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation("database/table/part/"); partition.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); partition.setParameters(parameters); }
Example #8
Source File: TableTransformationTest.java From circus-train with Apache License 2.0 | 5 votes |
@Before public void init() { table = new Table(); table.setDbName("database"); table.setTableName("table"); table.setTableType("type"); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); table.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(Arrays.asList(new FieldSchema("a", "int", null))); storageDescriptor.setInputFormat("input_format"); storageDescriptor.setOutputFormat("output_format"); storageDescriptor.setSerdeInfo(new SerDeInfo("serde", "lib", new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation("database/table/"); table.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); table.setParameters(parameters); }
Example #9
Source File: TestUtils.java From circus-train with Apache License 2.0 | 5 votes |
public static Partition newPartition(String database, String tableName, String partitionValue) { Partition partition = new Partition(); partition.setDbName(database); partition.setTableName(tableName); partition.setCreateTime(CREATE_TIME); partition.setValues(ImmutableList.of(partitionValue)); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); partition.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(COLS); storageDescriptor.setInputFormat(INPUT_FORMAT); storageDescriptor.setOutputFormat(OUTPUT_FORMAT); storageDescriptor.setSerdeInfo(new SerDeInfo(SERDE_INFO_NAME, SERIALIZATION_LIB, new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation(DATABASE + "/" + tableName + "/" + partitionValue + "/"); partition.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); partition.setParameters(parameters); return partition; }
Example #10
Source File: TestUtils.java From circus-train with Apache License 2.0 | 5 votes |
public static Table newTable(String database, String tableName) { Table table = new Table(); table.setDbName(database); table.setTableName(tableName); table.setTableType(TABLE_TYPE); table.setOwner(OWNER); table.setCreateTime(CREATE_TIME); table.setRetention(RETENTION); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); table.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(COLS); storageDescriptor.setInputFormat(INPUT_FORMAT); storageDescriptor.setOutputFormat(OUTPUT_FORMAT); storageDescriptor.setSerdeInfo(new SerDeInfo(SERDE_INFO_NAME, SERIALIZATION_LIB, new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation(DATABASE + "/" + tableName + "/"); table.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); table.setParameters(parameters); return table; }
Example #11
Source File: TableAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 5 votes |
@Test public void allShortCircuit() { left.getTable().getParameters().put("com.company.key", "value"); left.getTable().setPartitionKeys(ImmutableList.of(new FieldSchema("p", "string", "p comment"))); left.getTable().setOwner("left owner"); List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getTable().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); left.getTable().setRetention(2); left.getTable().setTableType("internal"); left.getTable().getSd().setLocation("left"); left.getTable().getSd().setInputFormat("LeftInputFormat"); left.getTable().getSd().setOutputFormat("LeftOutputFormat"); left.getTable().getSd().getParameters().put("com.company.key", "value"); left.getTable().getSd().getSerdeInfo().setName("left serde info"); left.getTable().getSd().getSkewedInfo().setSkewedColNames(ImmutableList.of("left skewed col")); left.getTable().getSd().setCols(ImmutableList.of(new FieldSchema("left", "type", "comment"))); left.getTable().getSd().setSortCols(ImmutableList.of(new Order())); left.getTable().getSd().setBucketCols(ImmutableList.of("bucket")); left.getTable().getSd().setNumBuckets(9000); List<Diff<Object, Object>> diffs = newTableAndMetadataComparator(SHORT_CIRCUIT).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(1)); assertThat(diffs.get(0), is(newPropertyDiff(TableAndMetadata.class, "table.parameters", left.getTable().getParameters(), right.getTable().getParameters()))); }
Example #12
Source File: TableAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 5 votes |
@Test public void privilegesFullComparison() { List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getTable().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); List<Diff<Object, Object>> diffs = newTableAndMetadataComparator(FULL_COMPARISON).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(0)); }
Example #13
Source File: TableAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 5 votes |
@Test public void privilegesShortCircuit() { List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getTable().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); List<Diff<Object, Object>> diffs = newTableAndMetadataComparator(SHORT_CIRCUIT).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(0)); }
Example #14
Source File: PartitionAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 5 votes |
@Test public void privilegesFullComparison() { List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getPartition().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); List<Diff<Object, Object>> diffs = newPartitionAndMetadataComparator(FULL_COMPARISON).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(0)); }
Example #15
Source File: InMemoryThriftMetastore.java From presto with Apache License 2.0 | 5 votes |
@Override public synchronized void createTable(HiveIdentity identity, Table table) { TableType tableType = TableType.valueOf(table.getTableType()); checkArgument(EnumSet.of(MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW).contains(tableType), "Invalid table type: %s", tableType); if (tableType == VIRTUAL_VIEW) { checkArgument(table.getSd().getLocation() == null, "Storage location for view must be null"); } else { File directory = new File(new Path(table.getSd().getLocation()).toUri()); checkArgument(directory.exists(), "Table directory does not exist"); if (tableType == MANAGED_TABLE) { checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory"); } } SchemaTableName schemaTableName = new SchemaTableName(table.getDbName(), table.getTableName()); Table tableCopy = table.deepCopy(); if (relations.putIfAbsent(schemaTableName, tableCopy) != null) { throw new TableAlreadyExistsException(schemaTableName); } if (tableType == VIRTUAL_VIEW) { views.put(schemaTableName, tableCopy); } PrincipalPrivilegeSet privileges = table.getPrivileges(); if (privileges != null) { throw new UnsupportedOperationException(); } }
Example #16
Source File: TableAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 4 votes |
@Test public void allFullComparison() { left.getTable().getParameters().put("com.company.key", "value"); left.getTable().setPartitionKeys(ImmutableList.of(new FieldSchema("p", "string", "p comment"))); left.getTable().setOwner("left owner"); List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getTable().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); left.getTable().setRetention(2); left.getTable().setTableType("internal"); left.getTable().getSd().setLocation("left"); left.getTable().getSd().setInputFormat("LeftInputFormat"); left.getTable().getSd().setOutputFormat("LeftOutputFormat"); left.getTable().getSd().getParameters().put("com.company.key", "value"); left.getTable().getSd().getSerdeInfo().setName("left serde info"); left.getTable().getSd().getSkewedInfo().setSkewedColNames(ImmutableList.of("left skewed col")); left.getTable().getSd().setCols(ImmutableList.of(new FieldSchema("left", "type", "comment"))); left.getTable().getSd().setSortCols(ImmutableList.of(new Order())); left.getTable().getSd().setBucketCols(ImmutableList.of("bucket")); left.getTable().getSd().setNumBuckets(9000); List<Diff<Object, Object>> diffs = newTableAndMetadataComparator(FULL_COMPARISON).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(12)); assertThat(diffs.get(0), is(newPropertyDiff(TableAndMetadata.class, "table.parameters", left.getTable().getParameters(), right.getTable().getParameters()))); assertThat(diffs.get(1), is(newPropertyDiff(TableAndMetadata.class, "table.partitionKeys", left.getTable().getPartitionKeys(), right.getTable().getPartitionKeys()))); assertThat(diffs.get(2), is(newPropertyDiff(TableAndMetadata.class, "table.retention", left.getTable().getRetention(), right.getTable().getRetention()))); assertThat(diffs.get(3), is(newPropertyDiff(TableAndMetadata.class, "table.sd.inputFormat", left.getTable().getSd().getInputFormat(), right.getTable().getSd().getInputFormat()))); assertThat(diffs.get(4), is(newPropertyDiff(TableAndMetadata.class, "table.sd.outputFormat", left.getTable().getSd().getOutputFormat(), right.getTable().getSd().getOutputFormat()))); assertThat(diffs.get(5), is(newPropertyDiff(TableAndMetadata.class, "table.sd.parameters", left.getTable().getSd().getParameters(), right.getTable().getSd().getParameters()))); assertThat(diffs.get(6), is(newPropertyDiff(TableAndMetadata.class, "table.sd.serdeInfo", left.getTable().getSd().getSerdeInfo(), right.getTable().getSd().getSerdeInfo()))); assertThat(diffs.get(7), is(newPropertyDiff(TableAndMetadata.class, "table.sd.skewedInfo", left.getTable().getSd().getSkewedInfo(), right.getTable().getSd().getSkewedInfo()))); assertThat(diffs.get(8), is(newDiff( "Collection table.sd.cols of class com.google.common.collect.SingletonImmutableList has different size: left.size()=1 and right.size()=2", left.getTable().getSd().getCols(), right.getTable().getSd().getCols()))); assertThat(diffs.get(9), is(newPropertyDiff(TableAndMetadata.class, "table.sd.sortCols", left.getTable().getSd().getSortCols(), right.getTable().getSd().getSortCols()))); assertThat(diffs.get(10), is(newPropertyDiff(TableAndMetadata.class, "table.sd.bucketCols", left.getTable().getSd().getBucketCols(), right.getTable().getSd().getBucketCols()))); assertThat(diffs.get(11), is(newPropertyDiff(TableAndMetadata.class, "table.sd.numBuckets", left.getTable().getSd().getNumBuckets(), right.getTable().getSd().getNumBuckets()))); }
Example #17
Source File: PartitionAndMetadataComparatorTest.java From circus-train with Apache License 2.0 | 4 votes |
@Test public void allFullComparison() { left.getPartition().getParameters().put("com.company.key", "value"); left.getPartition().setValues(ImmutableList.of("p1", "p2")); List<PrivilegeGrantInfo> privilege = ImmutableList.of(new PrivilegeGrantInfo()); left.getPartition().setPrivileges(new PrincipalPrivilegeSet(ImmutableMap.of("write", privilege), null, null)); left.getPartition().getSd().setLocation("left"); left.getPartition().getSd().setInputFormat("LeftInputFormat"); left.getPartition().getSd().setOutputFormat("LeftOutputFormat"); left.getPartition().getSd().getParameters().put("com.company.key", "value"); left.getPartition().getSd().getSerdeInfo().setName("left serde info"); left.getPartition().getSd().getSkewedInfo().setSkewedColNames(ImmutableList.of("left skewed col")); left.getPartition().getSd().setCols(ImmutableList.of(new FieldSchema("left", "type", "comment"))); left.getPartition().getSd().setSortCols(ImmutableList.of(new Order())); left.getPartition().getSd().setBucketCols(ImmutableList.of("bucket")); left.getPartition().getSd().setNumBuckets(9000); List<Diff<Object, Object>> diffs = newPartitionAndMetadataComparator(FULL_COMPARISON).compare(left, right); assertThat(diffs, is(notNullValue())); assertThat(diffs.size(), is(10)); assertThat(diffs.get(0), is(newPropertyDiff(PartitionAndMetadata.class, "partition.parameters", left.getPartition().getParameters(), right.getPartition().getParameters()))); assertThat(diffs.get(1), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.inputFormat", left.getPartition().getSd().getInputFormat(), right.getPartition().getSd().getInputFormat()))); assertThat(diffs.get(2), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.outputFormat", left.getPartition().getSd().getOutputFormat(), right.getPartition().getSd().getOutputFormat()))); assertThat(diffs.get(3), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.parameters", left.getPartition().getSd().getParameters(), right.getPartition().getSd().getParameters()))); assertThat(diffs.get(4), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.serdeInfo", left.getPartition().getSd().getSerdeInfo(), right.getPartition().getSd().getSerdeInfo()))); assertThat(diffs.get(5), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.skewedInfo", left.getPartition().getSd().getSkewedInfo(), right.getPartition().getSd().getSkewedInfo()))); assertThat(diffs.get(6), is(newDiff( "Collection partition.sd.cols of class com.google.common.collect.SingletonImmutableList has different size: left.size()=1 and right.size()=2", left.getPartition().getSd().getCols(), right.getPartition().getSd().getCols()))); assertThat(diffs.get(7), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.sortCols", left.getPartition().getSd().getSortCols(), right.getPartition().getSd().getSortCols()))); assertThat(diffs.get(8), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.bucketCols", left.getPartition().getSd().getBucketCols(), right.getPartition().getSd().getBucketCols()))); assertThat(diffs.get(9), is(newPropertyDiff(PartitionAndMetadata.class, "partition.sd.numBuckets", left.getPartition().getSd().getNumBuckets(), right.getPartition().getSd().getNumBuckets()))); }