keith-turner commented on a change in pull request #370: ACCUMULO-4772 Update 
shell to use NewTableConfiguration methods
URL: https://github.com/apache/accumulo/pull/370#discussion_r165379209
 
 

 ##########
 File path: 
shell/src/main/java/org/apache/accumulo/shell/commands/CreateTableCommand.java
 ##########
 @@ -150,9 +168,115 @@ public int execute(final String fullCommand, final 
CommandLine cl, final Shell s
     return 0;
   }
 
+  /**
+   * Add supplied locality groups information to a NewTableConfiguration 
object.
+   *
+   * Used in conjunction with createtable shell command to allow locality 
groups to be configured upon table creation.
+   */
+  private NewTableConfiguration setLocalityForNewTable(CommandLine cl, 
NewTableConfiguration ntc) {
+    HashMap<String,Set<Text>> localityGroupMap = new HashMap<>();
+    String[] options = 
cl.getOptionValues(createTableOptLocalityProps.getOpt());
+    for (String localityInfo : options) {
+      final String parts[] = localityInfo.split("=", 2);
+      if (parts.length < 2)
+        throw new IllegalArgumentException("Missing '=' or there are spaces 
between entries");
+      final String groupName = parts[0];
+      final HashSet<Text> colFams = new HashSet<>();
+      for (String family : parts[1].split(","))
+        colFams.add(new Text(family.getBytes(Shell.CHARSET)));
+      // check that group names are not duplicated on usage line
+      if (localityGroupMap.put(groupName, colFams) != null)
+        throw new IllegalArgumentException("Duplicate locality group name 
found. Group names must be unique");
+    }
+    ntc.setLocalityGroups(localityGroupMap);
+    return ntc;
+  }
+
+  /**
+   * Add supplied iterator information to NewTableConfiguration object.
+   *
+   * Used in conjunction with createtable shell command to allow an iterator 
to be configured upon table creation.
+   */
+  private NewTableConfiguration attachIteratorToNewTable(final CommandLine cl, 
final Shell shellState, NewTableConfiguration ntc) {
+    EnumSet<IteratorUtil.IteratorScope> scopeEnumSet = null;
+    IteratorSetting iteratorSetting = null;
+    if (shellState.iteratorProfiles.size() == 0)
+      throw new IllegalArgumentException("No shell iterator profiles have been 
created.");
+    String[] options = 
cl.getOptionValues(createTableOptIteratorProps.getOpt());
+    for (String profileInfo : options) {
+      String[] parts = profileInfo.split(":", 2);
+      String profileName = parts[0];
+      // The iteratorProfiles.get calls below will throw an NPE if the profile 
does not exist
+      // This can occur when the profile actually does not exist or if there is
+      // extraneous spacing in the iterator profile argument list causing the 
parser to read a scope as a profile.
+      try {
+        iteratorSetting = shellState.iteratorProfiles.get(profileName).get(0);
+      } catch (NullPointerException ex) {
+        throw new IllegalArgumentException("invalid iterator argument. Either 
profile does not exist or unexpected spaces in argument list.", ex);
+      }
+      // handle case where only the profile is supplied. Use all scopes by 
default if no scope args are provided.
+      if (parts.length == 1) {
+        // add all scopes to enum set
+        scopeEnumSet = EnumSet.allOf(IteratorUtil.IteratorScope.class);
+      } else {
+        // user provided scope arguments exist, parse them
+        List<String> scopeArgs = Arrays.asList(parts[1].split(","));
+        // there are only three allowable scope values
+        if (scopeArgs.size() > 3)
+          throw new IllegalArgumentException("Too many scope arguments 
supplied");
+        // handle the 'all' argument separately since it is not an allowable 
enum value for IteratorScope
+        // if 'all' is used, it should be the only scope provided
+        if (scopeArgs.contains("all")) {
+          if (scopeArgs.size() > 1)
+            throw new IllegalArgumentException("Cannot use 'all' in 
conjunction with other scopes");
+          scopeEnumSet = EnumSet.allOf(IteratorUtil.IteratorScope.class);
+        } else {
+          // 'all' is not involved, examine the scope arguments and populate 
iterator scope EnumSet
+          validateScopes(scopeArgs);
 
 Review comment:
   I wasn't sure if EnumSets were mutable, so I did an experiment and they are. 
 Therefore this code could be simplified to use what `valueOf` returns to 
insert into the enum set.
   
   ```java
     public static void main(String[] args) {
       EnumSet<IteratorScope> scopes = EnumSet.noneOf(IteratorScope.class);
   
       List<String> scopeStrs = new ArrayList<>();
       scopeStrs.add("scan");
       scopeStrs.add("minc");
       scopeStrs.add("scan");
   
       for (String scopeStr : scopeStrs) {
         IteratorScope scope = IteratorScope.valueOf(scopeStr);
         if (!scopes.add(scope)) {
           System.out.println("dupe " + scope);
         }
       }
       System.out.println(scopes);
     }
   ```
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to