Review Board 1.7.22


HIVE-4858: Sort "show grant" result to improve usability and testability

Review Request #12562 - Created July 15, 2013 and updated

Xuefu Zhang
trunk
HIVE-4858
Reviewers
hive
hive-git
Patch includes code changes and query output re-generation for a couple of test cases.
Performed the authorization test cases.
ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
Revision 9883659 New Change
[20] 505 lines
[+20] [+] private int showGrants(ShowGrantDesc showGrantDesc) throws HiveException {
506
        List<HiveObjectPrivilege> users = db.showPrivilegeGrant(
506
        List<HiveObjectPrivilege> users = db.showPrivilegeGrant(
507
            HiveObjectType.GLOBAL, principalName, principalDesc.getType(),
507
            HiveObjectType.GLOBAL, principalName, principalDesc.getType(),
508
            null, null, null, null);
508
            null, null, null, null);
509
        if (users != null && users.size() > 0) {
509
        if (users != null && users.size() > 0) {
510
          boolean first = true;
510
          boolean first = true;

    
   
511
          sortPrivileges(users);
511
          for (HiveObjectPrivilege usr : users) {
512
          for (HiveObjectPrivilege usr : users) {
512
            if (!first) {
513
            if (!first) {
513
              outStream.write(terminator);
514
              outStream.write(terminator);
514
            } else {
515
            } else {
515
              first = false;
516
              first = false;
[+20] [20] 45 lines
[+20] private int showGrants(ShowGrantDesc showGrantDesc) throws HiveException {
561
          // show database level privileges
562
          // show database level privileges
562
          List<HiveObjectPrivilege> dbs = db.showPrivilegeGrant(HiveObjectType.DATABASE, principalName,
563
          List<HiveObjectPrivilege> dbs = db.showPrivilegeGrant(HiveObjectType.DATABASE, principalName,
563
              principalDesc.getType(), dbName, null, null, null);
564
              principalDesc.getType(), dbName, null, null, null);
564
          if (dbs != null && dbs.size() > 0) {
565
          if (dbs != null && dbs.size() > 0) {
565
            boolean first = true;
566
            boolean first = true;

    
   
567
            sortPrivileges(dbs);
566
            for (HiveObjectPrivilege db : dbs) {
568
            for (HiveObjectPrivilege db : dbs) {
567
              if (!first) {
569
              if (!first) {
568
                outStream.write(terminator);
570
                outStream.write(terminator);
569
              } else {
571
              } else {
570
                first = false;
572
                first = false;
[+20] [20] 13 lines
[+20] private int showGrants(ShowGrantDesc showGrantDesc) throws HiveException {
584
                  HiveObjectType.COLUMN, principalName,
586
                  HiveObjectType.COLUMN, principalName,
585
                  principalDesc.getType(), dbName, tableName, partValues,
587
                  principalDesc.getType(), dbName, tableName, partValues,
586
                  columnName);
588
                  columnName);
587
              if (columnss != null && columnss.size() > 0) {
589
              if (columnss != null && columnss.size() > 0) {
588
                boolean first = true;
590
                boolean first = true;

    
   
591
                sortPrivileges(columnss);
589
                for (HiveObjectPrivilege col : columnss) {
592
                for (HiveObjectPrivilege col : columnss) {
590
                  if (!first) {
593
                  if (!first) {
591
                    outStream.write(terminator);
594
                    outStream.write(terminator);
592
                  } else {
595
                  } else {
593
                    first = false;
596
                    first = false;
[+20] [20] 10 lines
[+20] private int showGrants(ShowGrantDesc showGrantDesc) throws HiveException {
604
            List<HiveObjectPrivilege> parts = db.showPrivilegeGrant(
607
            List<HiveObjectPrivilege> parts = db.showPrivilegeGrant(
605
                HiveObjectType.PARTITION, principalName, principalDesc
608
                HiveObjectType.PARTITION, principalName, principalDesc
606
                    .getType(), dbName, tableName, partValues, null);
609
                    .getType(), dbName, tableName, partValues, null);
607
            if (parts != null && parts.size() > 0) {
610
            if (parts != null && parts.size() > 0) {
608
              boolean first = true;
611
              boolean first = true;

    
   
612
              sortPrivileges(parts);
609
              for (HiveObjectPrivilege part : parts) {
613
              for (HiveObjectPrivilege part : parts) {
610
                if (!first) {
614
                if (!first) {
611
                  outStream.write(terminator);
615
                  outStream.write(terminator);
612
                } else {
616
                } else {
613
                  first = false;
617
                  first = false;
[+20] [20] 9 lines
[+20] private int showGrants(ShowGrantDesc showGrantDesc) throws HiveException {
623
            List<HiveObjectPrivilege> tbls = db.showPrivilegeGrant(
627
            List<HiveObjectPrivilege> tbls = db.showPrivilegeGrant(
624
                HiveObjectType.TABLE, principalName, principalDesc.getType(),
628
                HiveObjectType.TABLE, principalName, principalDesc.getType(),
625
                dbName, tableName, null, null);
629
                dbName, tableName, null, null);
626
            if (tbls != null && tbls.size() > 0) {
630
            if (tbls != null && tbls.size() > 0) {
627
              boolean first = true;
631
              boolean first = true;

    
   
632
              sortPrivileges(tbls);
628
              for (HiveObjectPrivilege tbl : tbls) {
633
              for (HiveObjectPrivilege tbl : tbls) {
629
                if (!first) {
634
                if (!first) {
630
                  outStream.write(terminator);
635
                  outStream.write(terminator);
631
                } else {
636
                } else {
632
                  first = false;
637
                  first = false;
[+20] [20] 22 lines
[+20] private int showGrants(ShowGrantDesc showGrantDesc) throws HiveException {
655
      IOUtils.closeStream((FSDataOutputStream) outStream);
660
      IOUtils.closeStream((FSDataOutputStream) outStream);
656
    }
661
    }
657
    return 0;
662
    return 0;
658
  }
663
  }
659

    
   
664

   

    
   
665
  private static void sortPrivileges(List<HiveObjectPrivilege> privileges) {

    
   
666
    Collections.sort(privileges, new Comparator<HiveObjectPrivilege>() {

    
   
667

   

    
   
668
      @Override

    
   
669
      public int compare(HiveObjectPrivilege one, HiveObjectPrivilege other) {

    
   
670
        return one.getGrantInfo().getPrivilege().compareTo(other.getGrantInfo().getPrivilege());

    
   
671
      }

    
   
672

   

    
   
673
    });

    
   
674

   

    
   
675
  }

    
   
676

   
660
  private int grantOrRevokePrivileges(List<PrincipalDesc> principals,
677
  private int grantOrRevokePrivileges(List<PrincipalDesc> principals,
661
      List<PrivilegeDesc> privileges, PrivilegeObjectDesc privSubjectDesc,
678
      List<PrivilegeDesc> privileges, PrivilegeObjectDesc privSubjectDesc,
662
      String grantor, PrincipalType grantorType, boolean grantOption, boolean isGrant) {
679
      String grantor, PrincipalType grantorType, boolean grantOption, boolean isGrant) {
663
    if (privileges == null || privileges.size() == 0) {
680
    if (privileges == null || privileges.size() == 0) {
664
      console.printError("No privilege found.");
681
      console.printError("No privilege found.");
[+20] [20] 3249 lines
ql/src/test/results/clientpositive/alter_rename_partition_authorization.q.out
Revision 4262b7c New Change
 
ql/src/test/results/clientpositive/authorization_2.q.out
Revision c934a2a New Change
 
ql/src/test/results/clientpositive/authorization_6.q.out
Revision b8483ca New Change
 
  1. ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java: Loading...
  2. ql/src/test/results/clientpositive/alter_rename_partition_authorization.q.out: Loading...
  3. ql/src/test/results/clientpositive/authorization_2.q.out: Loading...
  4. ql/src/test/results/clientpositive/authorization_6.q.out: Loading...