DRILL-3122: Ignore OptionType for option status
Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/5bd92f83 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/5bd92f83 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/5bd92f83 Branch: refs/heads/master Commit: 5bd92f832aae4c87b7e0ab0619ea9b2cfbf81b55 Parents: f0b29a4 Author: Sudheesh Katkam <[email protected]> Authored: Mon Jul 13 16:56:58 2015 -0700 Committer: Jason Altekruse <[email protected]> Committed: Tue Aug 4 08:49:02 2015 -0700 ---------------------------------------------------------------------- .../drill/exec/server/options/OptionValue.java | 50 +++++++++++--------- .../drill/exec/store/sys/OptionIterator.java | 4 +- .../apache/drill/exec/server/TestOptions.java | 14 ++++++ 3 files changed, 42 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/5bd92f83/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 487553e..b73b669 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 @@ -17,9 +17,11 @@ */ package org.apache.drill.exec.server.options; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Preconditions; @JsonInclude(Include.NON_NULL) @@ -33,22 +35,13 @@ public class OptionValue implements Comparable<OptionValue> { BOOLEAN, LONG, STRING, DOUBLE } - public String name; - public Kind kind; - public OptionType type; - public Long num_val; - public String string_val; - public Boolean bool_val; - public Double float_val; - - /** - * Constructor. - * - * <p>Unfortunately, we have to have this variant, and are unable to make the members final, - * in order to support JSON deserialization into this structure. - */ - public OptionValue() { - } + public final String name; + public final Kind kind; + public final OptionType type; + public final Long num_val; + public final String string_val; + public final Boolean bool_val; + public final Double float_val; public static OptionValue createLong(OptionType type, String name, long val) { return new OptionValue(Kind.LONG, type, name, val, null, null, null); @@ -80,8 +73,14 @@ public class OptionValue implements Comparable<OptionValue> { return null; } - private OptionValue(Kind kind, OptionType type, String name, - Long num_val, String string_val, Boolean bool_val, Double float_val) { + @JsonCreator + private OptionValue(@JsonProperty("kind") Kind kind, + @JsonProperty("type") OptionType type, + @JsonProperty("name") String name, + @JsonProperty("num_val") Long num_val, + @JsonProperty("string_val") String string_val, + @JsonProperty("bool_val") Boolean bool_val, + @JsonProperty("float_val") Double float_val) { Preconditions.checkArgument(num_val != null || string_val != null || bool_val != null || float_val != null); this.kind = kind; this.type = type; @@ -122,8 +121,7 @@ public class OptionValue implements Comparable<OptionValue> { return result; } - @Override - public boolean equals(Object obj) { + public boolean equalsIgnoreType(Object obj) { if (this == obj) { return true; } @@ -133,7 +131,7 @@ public class OptionValue implements Comparable<OptionValue> { if (getClass() != obj.getClass()) { return false; } - OptionValue other = (OptionValue) obj; + final OptionValue other = (OptionValue) obj; if (bool_val == null) { if (other.bool_val != null) { return false; @@ -172,10 +170,16 @@ public class OptionValue implements Comparable<OptionValue> { } else if (!string_val.equals(other.string_val)) { return false; } - if (type != other.type) { + return true; + } + + @Override + public boolean equals(Object obj) { + if (!equalsIgnoreType(obj)) { return false; } - return true; + final OptionValue other = (OptionValue) obj; + return type == other.type; } @Override http://git-wip-us.apache.org/repos/asf/drill/blob/5bd92f83/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 index 3e42436..93109b7 100644 --- 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 @@ -75,7 +75,7 @@ public class OptionIterator implements Iterator<Object> { status = Status.BOOT; } else { final OptionValue def = fragmentOptions.getSystemManager().getDefault(value.name); - if (value.equals(def)) { + if (value.equalsIgnoreType(def)) { status = Status.DEFAULT; } else { status = Status.CHANGED; @@ -94,8 +94,6 @@ public class OptionIterator implements Iterator<Object> { */ public static class OptionValueWrapper { - - public final String name; public final Kind kind; public final OptionType type; http://git-wip-us.apache.org/repos/asf/drill/blob/5bd92f83/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptions.java index c522da8..71ac653 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptions.java @@ -18,6 +18,7 @@ package org.apache.drill.exec.server; import org.apache.drill.BaseTestQuery; +import org.apache.drill.exec.ExecConstants; import org.junit.Test; public class TestOptions extends BaseTestQuery{ @@ -38,4 +39,17 @@ public class TestOptions extends BaseTestQuery{ "select * from sys.options;" ); } + + @Test // DRILL-3122 + public void checkChangedColumn() throws Exception { + test(String.format("ALTER session SET `%s` = %d;", ExecConstants.SLICE_TARGET, + ExecConstants.SLICE_TARGET_DEFAULT)); + testBuilder() + .sqlQuery(String.format("SELECT status FROM sys.options WHERE name = '%s' AND type = 'SESSION'", ExecConstants.SLICE_TARGET)) + .unOrdered() + .baselineColumns("status") + .baselineValues("DEFAULT") + .build() + .run(); + } }
