kudu git commit: KUDU-2471: Fix ColumnSchema.equals NPE with non-Decimal columns
Repository: kudu Updated Branches: refs/heads/branch-1.7.x 8d7221570 -> a307f2a31 KUDU-2471: Fix ColumnSchema.equals NPE with non-Decimal columns Fixes a potential NPE on non-decimal columns and adds tests to prevent the issue in the future. Change-Id: Ica7afcbbbd9197e6ffd34761a5298f29e7306dd6 Reviewed-on: http://gerrit.cloudera.org:8080/10826 Tested-by: Kudu Jenkins Reviewed-by: Dan Burkert (cherry picked from commit 81828ba64f6348da2a4aec3fab3e7833f7ad01f0) Reviewed-on: http://gerrit.cloudera.org:8080/10837 Tested-by: Grant Henke Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/a307f2a3 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/a307f2a3 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/a307f2a3 Branch: refs/heads/branch-1.7.x Commit: a307f2a31c19f96932e608d1aecfc0dd471c9a9e Parents: 8d72215 Author: Grant Henke Authored: Tue Jun 26 15:00:39 2018 -0500 Committer: Grant Henke Committed: Wed Jun 27 18:37:28 2018 + -- .../main/java/org/apache/kudu/ColumnSchema.java | 28 +++-- .../java/org/apache/kudu/TestColumnSchema.java | 44 2 files changed, 50 insertions(+), 22 deletions(-) -- http://git-wip-us.apache.org/repos/asf/kudu/blob/a307f2a3/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java -- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java index 3072076..964c50e 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java @@ -191,29 +191,13 @@ public class ColumnSchema { @Override public boolean equals(Object o) { -if (this == o) { - return true; -} -if (o == null || getClass() != o.getClass()) { - return false; -} - +if (this == o) return true; +if (o == null || getClass() != o.getClass()) return false; ColumnSchema that = (ColumnSchema) o; - -if (key != that.key) { - return false; -} -if (!name.equals(that.name)) { - return false; -} -if (!type.equals(that.type)) { - return false; -} -if (!typeAttributes.equals(that.typeAttributes)) { - return false; -} - -return true; +return Objects.equals(name, that.name) && +Objects.equals(type, that.type) && +Objects.equals(key, that.key) && +Objects.equals(typeAttributes, that.typeAttributes); } @Override http://git-wip-us.apache.org/repos/asf/kudu/blob/a307f2a3/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java -- diff --git a/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java index d2d0710..51d5cb8 100644 --- a/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java +++ b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java @@ -21,6 +21,7 @@ import org.apache.kudu.util.DecimalUtil; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; public class TestColumnSchema { @@ -36,4 +37,47 @@ public class TestColumnSchema { assertEquals("Column name: col2, type: int64", col2.toString()); assertEquals("Column name: col3, type: decimal(5, 2)", col3.toString()); } + + @Test + public void testEquals() { +ColumnSchema stringCol1 = new ColumnSchemaBuilder("col1", Type.STRING) +.defaultValue("test") +.build(); +// Same instance +assertEquals(stringCol1, stringCol1); + +// Same value +ColumnSchema stringCol2 = new ColumnSchemaBuilder("col1", Type.STRING) +.defaultValue("test") +.build(); +assertEquals(stringCol1, stringCol2); + +// Different by key +ColumnSchema isKey = new ColumnSchemaBuilder("col1", Type.STRING) +.key(true) +.build(); +assertNotEquals(stringCol1, isKey); + +// Different by type +ColumnSchema isInt = new ColumnSchemaBuilder("col1", Type.INT32) +.build(); +assertNotEquals(stringCol1, isInt); + +// Same with type attributes +ColumnSchema decCol1 = new ColumnSchemaBuilder("col1", Type.DECIMAL) +.typeAttributes(DecimalUtil.typeAttributes(9, 2)) +.build(); +ColumnSchema decCol2 = new ColumnSchemaBuilder("col1", Type.DECIMAL) +.typeAttributes(DecimalUtil.typeAttributes(9, 2)) +.build(); +assertEquals(decCol1, decCol2); + +// Different by type attributes +ColumnSchema decCol3 = new ColumnSchemaBuilder("col1", Type.DECIMAL) +
[1/2] kudu git commit: KUDU-2471: Fix ColumnSchema.equals NPE with non-Decimal columns
Repository: kudu Updated Branches: refs/heads/master 4479c20bb -> e0a4c6cfa KUDU-2471: Fix ColumnSchema.equals NPE with non-Decimal columns Fixes a potential NPE on non-decimal columns and adds tests to prevent the issue in the future. Change-Id: Ica7afcbbbd9197e6ffd34761a5298f29e7306dd6 Reviewed-on: http://gerrit.cloudera.org:8080/10826 Tested-by: Kudu Jenkins Reviewed-by: Dan Burkert Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/81828ba6 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/81828ba6 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/81828ba6 Branch: refs/heads/master Commit: 81828ba64f6348da2a4aec3fab3e7833f7ad01f0 Parents: 4479c20 Author: Grant Henke Authored: Tue Jun 26 15:00:39 2018 -0500 Committer: Grant Henke Committed: Wed Jun 27 13:03:22 2018 + -- .../main/java/org/apache/kudu/ColumnSchema.java | 28 +++-- .../java/org/apache/kudu/TestColumnSchema.java | 44 2 files changed, 50 insertions(+), 22 deletions(-) -- http://git-wip-us.apache.org/repos/asf/kudu/blob/81828ba6/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java -- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java index 6bb8263..212ce78 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java @@ -195,29 +195,13 @@ public class ColumnSchema { @Override public boolean equals(Object o) { -if (this == o) { - return true; -} -if (o == null || getClass() != o.getClass()) { - return false; -} - +if (this == o) return true; +if (o == null || getClass() != o.getClass()) return false; ColumnSchema that = (ColumnSchema) o; - -if (key != that.key) { - return false; -} -if (!name.equals(that.name)) { - return false; -} -if (!type.equals(that.type)) { - return false; -} -if (!typeAttributes.equals(that.typeAttributes)) { - return false; -} - -return true; +return Objects.equals(name, that.name) && +Objects.equals(type, that.type) && +Objects.equals(key, that.key) && +Objects.equals(typeAttributes, that.typeAttributes); } @Override http://git-wip-us.apache.org/repos/asf/kudu/blob/81828ba6/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java -- diff --git a/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java index d2d0710..51d5cb8 100644 --- a/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java +++ b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java @@ -21,6 +21,7 @@ import org.apache.kudu.util.DecimalUtil; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; public class TestColumnSchema { @@ -36,4 +37,47 @@ public class TestColumnSchema { assertEquals("Column name: col2, type: int64", col2.toString()); assertEquals("Column name: col3, type: decimal(5, 2)", col3.toString()); } + + @Test + public void testEquals() { +ColumnSchema stringCol1 = new ColumnSchemaBuilder("col1", Type.STRING) +.defaultValue("test") +.build(); +// Same instance +assertEquals(stringCol1, stringCol1); + +// Same value +ColumnSchema stringCol2 = new ColumnSchemaBuilder("col1", Type.STRING) +.defaultValue("test") +.build(); +assertEquals(stringCol1, stringCol2); + +// Different by key +ColumnSchema isKey = new ColumnSchemaBuilder("col1", Type.STRING) +.key(true) +.build(); +assertNotEquals(stringCol1, isKey); + +// Different by type +ColumnSchema isInt = new ColumnSchemaBuilder("col1", Type.INT32) +.build(); +assertNotEquals(stringCol1, isInt); + +// Same with type attributes +ColumnSchema decCol1 = new ColumnSchemaBuilder("col1", Type.DECIMAL) +.typeAttributes(DecimalUtil.typeAttributes(9, 2)) +.build(); +ColumnSchema decCol2 = new ColumnSchemaBuilder("col1", Type.DECIMAL) +.typeAttributes(DecimalUtil.typeAttributes(9, 2)) +.build(); +assertEquals(decCol1, decCol2); + +// Different by type attributes +ColumnSchema decCol3 = new ColumnSchemaBuilder("col1", Type.DECIMAL) +.typeAttributes(DecimalUtil.typeAttributes(9, 0)) +.build(); +assertNotEquals(decCol1, decCol3); + + + } }