You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2018/10/31 23:21:31 UTC
kudu git commit: common: add equality methods to ColumnBlock and
SelectionVector
Repository: kudu
Updated Branches:
refs/heads/master dc71ab7ea -> 75e264cb2
common: add equality methods to ColumnBlock and SelectionVector
These are useful in tests.
I also snuck in a change to ScopedColumnBlock that should simplify tests:
all rows begin nulled out. This means two freshly created ScopedColumnBlocks
are equal as per ColumnBlock::Equals; previously the garbage data in data_
and null_bitmap_ virtually guaranteed inequality.
Change-Id: I9712bd7748bb01af7b6f68897a453a0aa149cdcf
Reviewed-on: http://gerrit.cloudera.org:8080/11267
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/75e264cb
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/75e264cb
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/75e264cb
Branch: refs/heads/master
Commit: 75e264cb28c89c119e90c9637580cc260521f533
Parents: dc71ab7
Author: Adar Dembo <ad...@cloudera.com>
Authored: Fri Aug 17 17:21:55 2018 -0700
Committer: Adar Dembo <ad...@cloudera.com>
Committed: Wed Oct 31 23:18:52 2018 +0000
----------------------------------------------------------------------
src/kudu/common/CMakeLists.txt | 2 ++
src/kudu/common/columnblock-test.cc | 59 ++++++++++++++++++++++++++++++++
src/kudu/common/columnblock.h | 37 ++++++++++++++++++++
src/kudu/common/rowblock-test.cc | 46 +++++++++++++++++++++++++
src/kudu/common/rowblock.cc | 11 ++++++
src/kudu/common/rowblock.h | 7 ++--
6 files changed, 160 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/75e264cb/src/kudu/common/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/common/CMakeLists.txt b/src/kudu/common/CMakeLists.txt
index a789ccb..1517f19 100644
--- a/src/kudu/common/CMakeLists.txt
+++ b/src/kudu/common/CMakeLists.txt
@@ -79,6 +79,7 @@ ADD_EXPORTABLE_LIBRARY(kudu_common
DEPS ${COMMON_LIBS})
SET_KUDU_TEST_LINK_LIBS(kudu_common)
+ADD_KUDU_TEST(columnblock-test)
ADD_KUDU_TEST(column_predicate-test)
ADD_KUDU_TEST(encoded_key-test)
ADD_KUDU_TEST(generic_iterators-test)
@@ -87,6 +88,7 @@ ADD_KUDU_TEST(key_util-test)
ADD_KUDU_TEST(partial_row-test)
ADD_KUDU_TEST(partition-test)
ADD_KUDU_TEST(partition_pruner-test)
+ADD_KUDU_TEST(rowblock-test)
ADD_KUDU_TEST(row_changelist-test)
ADD_KUDU_TEST(row_operations-test)
ADD_KUDU_TEST(scan_spec-test)
http://git-wip-us.apache.org/repos/asf/kudu/blob/75e264cb/src/kudu/common/columnblock-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/columnblock-test.cc b/src/kudu/common/columnblock-test.cc
new file mode 100644
index 0000000..9ded126
--- /dev/null
+++ b/src/kudu/common/columnblock-test.cc
@@ -0,0 +1,59 @@
+// 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.
+
+#include "kudu/common/columnblock.h"
+
+#include <gtest/gtest.h>
+
+#include "kudu/common/common.pb.h"
+
+namespace kudu {
+
+TEST(TestColumnBlock, TestEquals) {
+ ScopedColumnBlock<UINT32> scb1(1);
+ ScopedColumnBlock<UINT32> scb2(1);
+ ASSERT_EQ(scb1, scb2);
+
+ // Even though this updates a value, scb2 is still entirely null.
+ scb2[0] = 5;
+ ASSERT_EQ(scb1, scb2);
+
+ // If we un-null that cell in scb2, the two column blocks are no longer equal.
+ scb2.SetCellIsNull(0, false);
+ ASSERT_NE(scb1, scb2);
+
+ // Now let's also un-null that cell in scb1. The null bitmaps match again, but
+ // the data itself does not.
+ scb1.SetCellIsNull(0, false);
+ ASSERT_NE(scb1, scb2);
+
+ // These two column blocks aren't the same length.
+ ScopedColumnBlock<UINT32> scb3(1);
+ ScopedColumnBlock<UINT32> scb4(2);
+ ASSERT_NE(scb3, scb4);
+
+ // Let's make sure they're equal even when the data is indirected.
+ ScopedColumnBlock<STRING> scb5(1);
+ ScopedColumnBlock<STRING> scb6(1);
+ scb5.SetCellIsNull(0, false);
+ scb5[0] = "foo";
+ scb6.SetCellIsNull(0, false);
+ scb6[0] = "foo";
+ ASSERT_EQ(scb5, scb6);
+}
+
+} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/75e264cb/src/kudu/common/columnblock.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/columnblock.h b/src/kudu/common/columnblock.h
index b91c316..72046ba 100644
--- a/src/kudu/common/columnblock.h
+++ b/src/kudu/common/columnblock.h
@@ -123,6 +123,41 @@ class ColumnBlock {
Arena *arena_;
};
+inline bool operator==(const ColumnBlock& a, const ColumnBlock& b) {
+ // 1. Same number of rows.
+ if (a.nrows() != b.nrows()) {
+ return false;
+ }
+
+ // 2. Same nullability.
+ if (a.is_nullable() != b.is_nullable()) {
+ return false;
+ }
+
+ // 3. If nullable, same null bitmap contents.
+ if (a.is_nullable() &&
+ !BitmapEquals(a.null_bitmap(), b.null_bitmap(), a.nrows())) {
+ return false;
+ }
+
+ // 4. Same data. We can't just compare the raw data because some entries may
+ // be pointers to the actual data elsewhere.
+ for (int i = 0; i < a.nrows(); i++) {
+ if (a.is_nullable() && a.is_null(i)) {
+ continue;
+ }
+ if (a.type_info()->Compare(a.cell_ptr(i), b.cell_ptr(i)) != 0) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+inline bool operator!=(const ColumnBlock& a, const ColumnBlock& b) {
+ return !(a == b);
+}
+
// One of the cells in a ColumnBlock.
class ColumnBlockCell {
public:
@@ -221,6 +256,8 @@ class ScopedColumnBlock : public ColumnBlock {
null_bitmap_(null_bitmap()),
data_(reinterpret_cast<cpp_type *>(data())),
arena_(arena()) {
+ // All rows begin null.
+ BitmapChangeBits(null_bitmap(), /*offset=*/ 0, n_rows, /*value=*/ false);
}
const cpp_type &operator[](size_t idx) const {
http://git-wip-us.apache.org/repos/asf/kudu/blob/75e264cb/src/kudu/common/rowblock-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/rowblock-test.cc b/src/kudu/common/rowblock-test.cc
new file mode 100644
index 0000000..0865289
--- /dev/null
+++ b/src/kudu/common/rowblock-test.cc
@@ -0,0 +1,46 @@
+// 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.
+
+#include "kudu/common/rowblock.h"
+
+#include <gtest/gtest.h>
+
+namespace kudu {
+
+TEST(TestSelectionVector, TestEquals) {
+ SelectionVector sv1(10);
+ SelectionVector sv2(10);
+
+ // Test both false and true.
+ sv1.SetAllFalse();
+ sv2.SetAllFalse();
+ ASSERT_EQ(sv1, sv2);
+ sv1.SetAllTrue();
+ sv2.SetAllTrue();
+ ASSERT_EQ(sv1, sv2);
+
+ // One row differs.
+ sv2.SetRowUnselected(0);
+ ASSERT_NE(sv1, sv2);
+
+ // The length differs.
+ SelectionVector sv3(5);
+ sv3.SetAllTrue();
+ ASSERT_NE(sv1, sv3);
+}
+
+} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/75e264cb/src/kudu/common/rowblock.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/rowblock.cc b/src/kudu/common/rowblock.cc
index 2b8cd65..df43eda 100644
--- a/src/kudu/common/rowblock.cc
+++ b/src/kudu/common/rowblock.cc
@@ -96,6 +96,17 @@ bool SelectionVector::AnySelected() const {
return false;
}
+bool operator==(const SelectionVector& a, const SelectionVector& b) {
+ if (a.nrows() != b.nrows()) {
+ return false;
+ }
+ return BitmapEquals(a.bitmap(), b.bitmap(), a.nrows());
+}
+
+bool operator!=(const SelectionVector& a, const SelectionVector& b) {
+ return !(a == b);
+}
+
//////////////////////////////
// RowBlock
//////////////////////////////
http://git-wip-us.apache.org/repos/asf/kudu/blob/75e264cb/src/kudu/common/rowblock.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/rowblock.h b/src/kudu/common/rowblock.h
index eaea3ec..653c0a6 100644
--- a/src/kudu/common/rowblock.h
+++ b/src/kudu/common/rowblock.h
@@ -120,8 +120,6 @@ class SelectionVector {
size_t nrows() const { return n_rows_; }
private:
- DISALLOW_COPY_AND_ASSIGN(SelectionVector);
-
// The number of allocated bytes in bitmap_
size_t bytes_capacity_;
@@ -129,8 +127,13 @@ class SelectionVector {
size_t n_bytes_;
gscoped_array<uint8_t> bitmap_;
+
+ DISALLOW_COPY_AND_ASSIGN(SelectionVector);
};
+bool operator==(const SelectionVector& a, const SelectionVector& b);
+bool operator!=(const SelectionVector& a, const SelectionVector& b);
+
// A SelectionVectorView keeps track of where in the selection vector a given
// batch will start from. After processing a batch, Advance() should be called
// and the view will move forward by the appropriate amount. In this way, the