You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2015/05/15 08:42:54 UTC

[08/17] drill git commit: Update sys.options table to only show options available via ALTER SYSTEM or ALTER SESSION. Move BOOT options to sys.boot table.

Update sys.options table to only show options available via ALTER SYSTEM or ALTER SESSION.  Move BOOT options to sys.boot table.


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/22d6465e
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/22d6465e
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/22d6465e

Branch: refs/heads/master
Commit: 22d6465e0037b84bd5749a2b3654de1de21bb9de
Parents: 7fccf7e
Author: Jacques Nadeau <ja...@apache.org>
Authored: Thu May 14 13:41:26 2015 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Thu May 14 21:58:53 2015 -0700

----------------------------------------------------------------------
 .../drill/exec/server/options/OptionValue.java  |   7 +-
 .../drill/exec/store/sys/OptionIterator.java    | 126 +++++++++++++++++++
 .../drill/exec/store/sys/SystemTable.java       |  84 ++-----------
 3 files changed, 143 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/22d6465e/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/OptionValue.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/OptionValue.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/OptionValue.java
index 8735fd6..487553e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/OptionValue.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/OptionValue.java
@@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.google.common.base.Preconditions;
 
 @JsonInclude(Include.NON_NULL)
-public class OptionValue {
+public class OptionValue implements Comparable<OptionValue> {
 
   public static enum OptionType {
     BOOT, SYSTEM, SESSION, QUERY
@@ -179,6 +179,11 @@ public class OptionValue {
   }
 
   @Override
+  public int compareTo(OptionValue o) {
+    return this.name.compareTo(o.name);
+  }
+
+  @Override
   public String toString() {
     return "OptionValue [type=" + type + ", name=" + name + ", value=" + getValue() + "]";
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/22d6465e/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/OptionIterator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/OptionIterator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/OptionIterator.java
new file mode 100644
index 0000000..3e42436
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/OptionIterator.java
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.store.sys;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.server.options.DrillConfigIterator;
+import org.apache.drill.exec.server.options.OptionManager;
+import org.apache.drill.exec.server.options.OptionValue;
+import org.apache.drill.exec.server.options.OptionValue.Kind;
+import org.apache.drill.exec.server.options.OptionValue.OptionType;
+
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
+public class OptionIterator implements Iterator<Object> {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OptionIterator.class);
+
+  enum Mode {
+    BOOT, SYS_SESS, BOTH
+  };
+
+  private final OptionManager fragmentOptions;
+  private final Iterator<OptionValue> mergedOptions;
+
+  public OptionIterator(FragmentContext context, Mode mode){
+    final DrillConfigIterator configOptions = new DrillConfigIterator(context.getConfig());
+    fragmentOptions = context.getOptions();
+    final Iterator<OptionValue> optionList;
+    switch(mode){
+    case BOOT:
+      optionList = configOptions.iterator();
+      break;
+    case SYS_SESS:
+      optionList = fragmentOptions.iterator();
+      break;
+    default:
+      optionList = Iterators.concat(configOptions.iterator(), fragmentOptions.iterator());
+    }
+
+    List<OptionValue> values = Lists.newArrayList(optionList);
+    Collections.sort(values);
+    mergedOptions = values.iterator();
+
+  }
+
+  @Override
+  public boolean hasNext() {
+    return mergedOptions.hasNext();
+  }
+
+  @Override
+  public OptionValueWrapper next() {
+    final OptionValue value = mergedOptions.next();
+    final Status status;
+    if (value.type == OptionType.BOOT) {
+      status = Status.BOOT;
+    } else {
+      final OptionValue def = fragmentOptions.getSystemManager().getDefault(value.name);
+      if (value.equals(def)) {
+        status = Status.DEFAULT;
+        } else {
+        status = Status.CHANGED;
+        }
+      }
+    return new OptionValueWrapper(value.name, value.kind, value.type, value.num_val, value.string_val,
+        value.bool_val, value.float_val, status);
+  }
+
+  public static enum Status {
+    BOOT, DEFAULT, CHANGED
+  }
+
+  /**
+   * Wrapper class for OptionValue to add Status
+   */
+  public static class OptionValueWrapper {
+
+
+
+    public final String name;
+    public final Kind kind;
+    public final OptionType type;
+    public final Status status;
+    public final Long num_val;
+    public final String string_val;
+    public final Boolean bool_val;
+    public final Double float_val;
+
+    public OptionValueWrapper(final String name, final Kind kind, final OptionType type, final Long num_val,
+        final String string_val, final Boolean bool_val, final Double float_val,
+        final Status status) {
+      this.name = name;
+      this.kind = kind;
+      this.type = type;
+      this.num_val = num_val;
+      this.string_val = string_val;
+      this.bool_val = bool_val;
+      this.float_val = float_val;
+      this.status = status;
+    }
+  }
+
+  @Override
+  public void remove() {
+    throw new UnsupportedOperationException();
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/22d6465e/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTable.java
index cd8af08..1d73001 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTable.java
@@ -17,17 +17,11 @@
  */
 package org.apache.drill.exec.store.sys;
 
-import com.google.common.collect.Iterators;
-import org.apache.drill.exec.ops.FragmentContext;
-import org.apache.drill.exec.server.options.DrillConfigIterator;
-import org.apache.drill.exec.server.options.OptionManager;
-import org.apache.drill.exec.server.options.OptionValue;
-import org.apache.drill.exec.server.options.OptionValue.Kind;
-import org.apache.drill.exec.server.options.OptionValue.OptionType;
-import org.apache.drill.exec.store.sys.SystemTable.OptionValueWrapper.Status;
-
 import java.util.Iterator;
 
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.store.sys.OptionIterator.OptionValueWrapper;
+
 /**
  * An enumeration of all tables in Drill's system ("sys") schema.
  * <p>
@@ -41,40 +35,14 @@ public enum SystemTable {
   OPTION("options", false, OptionValueWrapper.class) {
     @Override
     public Iterator<Object> getIterator(final FragmentContext context) {
-      final DrillConfigIterator configOptions = new DrillConfigIterator(context.getConfig());
-      final OptionManager fragmentOptions = context.getOptions();
-      final Iterator<OptionValue> mergedOptions = Iterators.concat(configOptions.iterator(), fragmentOptions.iterator());
-      final Iterator<OptionValueWrapper> optionValues = new Iterator<OptionValueWrapper>() {
-        @Override
-        public boolean hasNext() {
-          return mergedOptions.hasNext();
-        }
-
-        @Override
-        public OptionValueWrapper next() {
-          final OptionValue value = mergedOptions.next();
-          final Status status;
-          if (value.type == OptionType.BOOT) {
-            status = Status.BOOT;
-          } else {
-            final OptionValue def = fragmentOptions.getSystemManager().getDefault(value.name);
-            if (value.equals(def)) {
-              status = Status.DEFAULT;
-            } else {
-              status = Status.CHANGED;
-            }
-          }
-          return new OptionValueWrapper(value.name, value.kind, value.type, value.num_val, value.string_val,
-            value.bool_val, value.float_val, status);
-        }
-
-        @Override
-        public void remove() {
-        }
-      };
-      @SuppressWarnings("unchecked")
-      final Iterator<Object> iterator = (Iterator<Object>) (Object) optionValues;
-      return iterator;
+      return new OptionIterator(context, OptionIterator.Mode.SYS_SESS);
+    }
+  },
+
+  BOOT("boot", false, OptionValueWrapper.class) {
+    @Override
+    public Iterator<Object> getIterator(final FragmentContext context) {
+      return new OptionIterator(context, OptionIterator.Mode.BOOT);
     }
   },
 
@@ -134,35 +102,5 @@ public enum SystemTable {
     return pojoClass;
   }
 
-  /**
-   * Wrapper class for OptionValue to add Status
-   */
-  public static class OptionValueWrapper {
-
-    public static enum Status {
-      BOOT, DEFAULT, CHANGED
-    }
 
-    public final String name;
-    public final Kind kind;
-    public final OptionType type;
-    public final Status status;
-    public final Long num_val;
-    public final String string_val;
-    public final Boolean bool_val;
-    public final Double float_val;
-
-    public OptionValueWrapper(final String name, final Kind kind, final OptionType type, final Long num_val,
-                              final String string_val, final Boolean bool_val, final Double float_val,
-                              final Status status) {
-      this.name = name;
-      this.kind = kind;
-      this.type = type;
-      this.num_val = num_val;
-      this.string_val = string_val;
-      this.bool_val = bool_val;
-      this.float_val = float_val;
-      this.status = status;
-    }
-  }
 }