|
169 | 169 | import org.slf4j.LoggerFactory;
|
170 | 170 |
|
171 | 171 | import com.google.common.annotations.VisibleForTesting;
|
| 172 | +import com.google.common.base.Joiner; |
172 | 173 | import com.google.common.collect.Lists;
|
173 | 174 | import com.google.common.collect.Maps;
|
174 | 175 |
|
@@ -2565,34 +2566,67 @@ private Collection getPartitionPsQueryResults(String dbName, String tableName,
|
2565 | 2566 | return (Collection) query.execute(dbName, tableName, partNameMatcher);
|
2566 | 2567 | }
|
2567 | 2568 |
|
| 2569 | + /** |
| 2570 | + * If partVals all the values are empty strings, it means we are returning |
| 2571 | + * all the partitions and hence we can attempt to use a directSQL equivalent API which |
| 2572 | + * is considerably faster. |
| 2573 | + * @param partVals The partitions values used to filter out the partitions. |
| 2574 | + * @return true only when partVals is non-empty and contains only empty strings, |
| 2575 | + * otherwise false. If user or groups is valid then returns false since the directSQL |
| 2576 | + * doesn't support partition privileges. |
| 2577 | + */ |
| 2578 | + private boolean canTryDirectSQL(List<String> partVals) { |
| 2579 | + if (partVals.isEmpty()) { |
| 2580 | + return false; |
| 2581 | + } |
| 2582 | + for (String val : partVals) { |
| 2583 | + if (val != null && !val.isEmpty()) { |
| 2584 | + return false; |
| 2585 | + } |
| 2586 | + } |
| 2587 | + return true; |
| 2588 | + } |
| 2589 | + |
2568 | 2590 | @Override
|
2569 | 2591 | public List<Partition> listPartitionsPsWithAuth(String db_name, String tbl_name,
|
2570 | 2592 | List<String> part_vals, short max_parts, String userName, List<String> groupNames)
|
2571 | 2593 | throws MetaException, InvalidObjectException, NoSuchObjectException {
|
2572 |
| - List<Partition> partitions = new ArrayList<Partition>(); |
| 2594 | + List<Partition> partitions = new ArrayList<>(); |
2573 | 2595 | boolean success = false;
|
2574 | 2596 | QueryWrapper queryWrapper = new QueryWrapper();
|
2575 |
| - |
2576 | 2597 | try {
|
2577 | 2598 | openTransaction();
|
2578 |
| - LOG.debug("executing listPartitionNamesPsWithAuth"); |
2579 |
| - Collection parts = getPartitionPsQueryResults(db_name, tbl_name, |
2580 |
| - part_vals, max_parts, null, queryWrapper); |
| 2599 | + |
2581 | 2600 | MTable mtbl = getMTable(db_name, tbl_name);
|
| 2601 | + if (mtbl == null) { |
| 2602 | + throw new NoSuchObjectException(db_name + "." + tbl_name + " table not found"); |
| 2603 | + } |
| 2604 | + boolean getauth = null != userName && null != groupNames && |
| 2605 | + "TRUE".equalsIgnoreCase(mtbl.getParameters().get("PARTITION_LEVEL_PRIVILEGE")); |
| 2606 | + if(!getauth && canTryDirectSQL(part_vals)) { |
| 2607 | + LOG.debug( |
| 2608 | + "Redirecting to directSQL enabled API: db: {} tbl: {} partVals: {}", |
| 2609 | + db_name, tbl_name, Joiner.on(',').join(part_vals)); |
| 2610 | + return getPartitions(db_name, tbl_name, -1); |
| 2611 | + } |
| 2612 | + LOG.debug("executing listPartitionNamesPsWithAuth"); |
| 2613 | + Collection parts = getPartitionPsQueryResults(db_name, tbl_name, part_vals, |
| 2614 | + max_parts, null, queryWrapper); |
2582 | 2615 | for (Object o : parts) {
|
2583 | 2616 | Partition part = convertToPart((MPartition) o);
|
2584 |
| - //set auth privileges |
2585 |
| - if (null != userName && null != groupNames && |
2586 |
| - "TRUE".equalsIgnoreCase(mtbl.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) { |
2587 |
| - String partName = Warehouse.makePartName(this.convertToFieldSchemas(mtbl |
2588 |
| - .getPartitionKeys()), part.getValues()); |
2589 |
| - PrincipalPrivilegeSet partAuth = getPartitionPrivilegeSet(db_name, |
2590 |
| - tbl_name, partName, userName, groupNames); |
2591 |
| - part.setPrivileges(partAuth); |
2592 |
| - } |
| 2617 | + // set auth privileges |
| 2618 | + String partName = Warehouse.makePartName(this.convertToFieldSchemas(mtbl |
| 2619 | + .getPartitionKeys()), part.getValues()); |
| 2620 | + PrincipalPrivilegeSet partAuth = getPartitionPrivilegeSet(db_name, |
| 2621 | + tbl_name, partName, userName, groupNames); |
| 2622 | + part.setPrivileges(partAuth); |
2593 | 2623 | partitions.add(part);
|
2594 | 2624 | }
|
2595 | 2625 | success = commitTransaction();
|
| 2626 | + } catch (InvalidObjectException | NoSuchObjectException | MetaException e) { |
| 2627 | + throw e; |
| 2628 | + } catch (Exception e) { |
| 2629 | + throw new MetaException(e.getMessage()); |
2596 | 2630 | } finally {
|
2597 | 2631 | rollbackAndCleanup(success, queryWrapper);
|
2598 | 2632 | }
|
|
0 commit comments