You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2016/07/11 23:48:38 UTC
[45/50] [abbrv] hbase git commit: HBASE-15945 Patch for Cell
HBASE-15945 Patch for Cell
This patch consists of Cell implementation without additional interfaces.
Signed-off-by: Elliott Clark <ec...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/fa3ab420
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/fa3ab420
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/fa3ab420
Branch: refs/heads/HBASE-14850
Commit: fa3ab420d19bba853d96576176257b5c12f1a48f
Parents: 2b6341d
Author: Sudeep Sunthankar <su...@gmail.com>
Authored: Mon Jul 4 21:02:25 2016 +1000
Committer: Elliott Clark <ec...@apache.org>
Committed: Mon Jul 11 16:47:26 2016 -0700
----------------------------------------------------------------------
hbase-native-client/core/cell-test.cc | 175 +++++++++++++++++++++++++++++
hbase-native-client/core/cell.cc | 77 +++++++++++++
hbase-native-client/core/cell.h | 60 ++++++++++
3 files changed, 312 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/fa3ab420/hbase-native-client/core/cell-test.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/cell-test.cc b/hbase-native-client/core/cell-test.cc
new file mode 100644
index 0000000..cbe50eb
--- /dev/null
+++ b/hbase-native-client/core/cell-test.cc
@@ -0,0 +1,175 @@
+/*
+ * 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 "core/cell.h"
+
+#include <memory>
+#include <gtest/gtest.h>
+#include <glog/logging.h>
+
+using namespace hbase;
+TEST(CellTest, CellFailureTest) {
+ CellType cell_type = CellType::PUT;
+ std::string row = "row";
+ std::string family = "family";
+ std::string column = "column";
+ std::string value = "value";
+ long timestamp = std::numeric_limits<long>::max();
+ std::string tags = "";
+ std::unique_ptr<Cell> cell(
+ new Cell(row, family, column, timestamp, value, cell_type));
+ if (cell.get()) {
+ EXPECT_NE("row-value", cell.get()->Row());
+ EXPECT_NE("family-value", cell.get()->Family());
+ EXPECT_NE("column-value", cell.get()->Qualifier());
+ EXPECT_NE("value-value", cell.get()->Value());
+ EXPECT_NE(8975431260, cell.get()->Timestamp());
+ EXPECT_NE(CellType::MAXIMUM, cell.get()->Type());
+ }
+}
+
+TEST(CellTest, CellSuceessTest) {
+ std::string row = "row-value";
+ std::string family = "family-value";
+ std::string column = "column-value";
+ std::string value = "value-value";
+ long timestamp = std::numeric_limits<long>::max();
+ CellType cell_type = CellType::PUT;
+ const std::unique_ptr<Cell> cell(
+ new Cell(row, family, column, timestamp, value, cell_type));
+ if (cell.get()) {
+ EXPECT_EQ(row, cell.get()->Row());
+ EXPECT_EQ(family, cell.get()->Family());
+ EXPECT_EQ(column, cell.get()->Qualifier());
+ EXPECT_EQ(value, cell.get()->Value());
+ EXPECT_EQ(timestamp, cell.get()->Timestamp());
+ EXPECT_EQ(cell_type, cell.get()->Type());
+ }
+}
+
+TEST(CellTest, MultipleCellsTest) {
+ std::vector<const Cell *> cells;
+ for (int i = 0; i < 5; i++) {
+ std::string row = "row-value";
+ std::string family = "family-value";
+ std::string column = "column-value";
+ std::string value = "value-value";
+ long timestamp = std::numeric_limits<long>::max();
+ row += std::to_string(i);
+ value += std::to_string(i);
+ CellType cell_type = CellType::PUT;
+ const Cell *cell = new Cell(row, family, column, timestamp, value,
+ cell_type);
+ cells.push_back(cell);
+ }
+ int i = 0;
+ for (const auto cell : cells) {
+ std::string row = "row-value";
+ std::string value = "value-value";
+ row += std::to_string(i);
+ value += std::to_string(i);
+ EXPECT_EQ(row, cell->Row());
+ EXPECT_EQ("family-value", cell->Family());
+ EXPECT_EQ("column-value", cell->Qualifier());
+ EXPECT_EQ(value, cell->Value());
+ EXPECT_EQ(std::numeric_limits<long>::max(), cell->Timestamp());
+ EXPECT_EQ(CellType::PUT, cell->Type());
+ i += 1;
+ }
+ for (const auto cell : cells) {
+ delete cell;
+ }
+ cells.clear();
+}
+
+TEST(CellTest, CellRowTest) {
+ std::string row = "only-row";
+ std::string family = "";
+ std::string column = "";
+ std::string value = "";
+ long timestamp = std::numeric_limits<long>::max();
+ CellType cell_type = CellType::PUT;
+ std::unique_ptr<Cell> cell(
+ new Cell(row, family, column, timestamp, value, cell_type));
+ if (cell.get()) {
+ EXPECT_EQ(row, cell.get()->Row());
+ EXPECT_EQ(family, cell.get()->Family());
+ EXPECT_EQ(column, cell.get()->Qualifier());
+ EXPECT_EQ(value, cell.get()->Value());
+ EXPECT_EQ(timestamp, cell.get()->Timestamp());
+ EXPECT_EQ(cell_type, cell.get()->Type());
+ }
+}
+
+TEST(CellTest, CellRowFamilyTest) {
+ std::string row = "only-row";
+ std::string family = "only-family";
+ std::string column = "";
+ std::string value = "";
+ long timestamp = std::numeric_limits<long>::max();
+ CellType cell_type = CellType::PUT;
+ const std::unique_ptr<Cell> cell(
+ new Cell(row, family, column, timestamp, value, cell_type));
+ if (cell.get()) {
+ EXPECT_EQ(row, cell.get()->Row());
+ EXPECT_EQ(family, cell.get()->Family());
+ EXPECT_EQ(column, cell.get()->Qualifier());
+ EXPECT_EQ(value, cell.get()->Value());
+ EXPECT_EQ(timestamp, cell.get()->Timestamp());
+ EXPECT_EQ(cell_type, cell.get()->Type());
+ }
+}
+
+TEST(CellTest, CellRowFamilyValueTest) {
+ std::string row = "only-row";
+ std::string family = "only-family";
+ std::string column = "";
+ std::string value = "only-value";
+ long timestamp = std::numeric_limits<long>::max();
+ CellType cell_type = CellType::PUT;
+ const std::unique_ptr<Cell> cell(
+ new Cell(row, family, column, timestamp, value, cell_type));
+ if (cell.get()) {
+ EXPECT_EQ(row, cell.get()->Row());
+ EXPECT_EQ(family, cell.get()->Family());
+ EXPECT_EQ(column, cell.get()->Qualifier());
+ EXPECT_EQ(value, cell.get()->Value());
+ EXPECT_EQ(timestamp, cell.get()->Timestamp());
+ EXPECT_EQ(cell_type, cell.get()->Type());
+ }
+}
+
+TEST(CellTest, CellRowFamilyColumnValueTest) {
+ std::string row = "only-row";
+ std::string family = "only-family";
+ std::string column = "only-column";
+ std::string value = "only-value";
+ long timestamp = std::numeric_limits<long>::max();
+ CellType cell_type = CellType::PUT;
+ std::unique_ptr<Cell> cell(
+ new Cell(row, family, column, timestamp, value, cell_type));
+ if (cell.get()) {
+ EXPECT_EQ(row, cell.get()->Row());
+ EXPECT_EQ(family, cell.get()->Family());
+ EXPECT_EQ(column, cell.get()->Qualifier());
+ EXPECT_EQ(value, cell.get()->Value());
+ EXPECT_EQ(timestamp, cell.get()->Timestamp());
+ EXPECT_EQ(cell_type, cell.get()->Type());
+ }
+}
http://git-wip-us.apache.org/repos/asf/hbase/blob/fa3ab420/hbase-native-client/core/cell.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/cell.cc b/hbase-native-client/core/cell.cc
new file mode 100644
index 0000000..f214479
--- /dev/null
+++ b/hbase-native-client/core/cell.cc
@@ -0,0 +1,77 @@
+/*
+ * 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 "core/cell.h"
+#include <stdexcept>
+
+namespace hbase {
+
+Cell::Cell(const std::string &row, const std::string &family,
+ const std::string &qualifier, const long ×tamp,
+ const std::string &value, const hbase::CellType &cell_type)
+ : row_(row),
+ family_(family),
+ qualifier_(qualifier),
+ timestamp_(timestamp),
+ cell_type_(cell_type),
+ value_(value),
+ sequence_id_(0) {
+
+ if (0 == row.size())
+ throw std::runtime_error("Row size should be greater than 0");
+
+ if (0 == family.size())
+ throw std::runtime_error("Column family size should be greater than 0");
+
+ if (0 >= timestamp)
+ throw std::runtime_error("Timestamp should be greater than 0");
+}
+
+Cell::~Cell() {
+}
+
+const std::string &Cell::Row() const {
+ return row_;
+}
+
+const std::string &Cell::Family() const {
+ return family_;
+}
+
+const std::string &Cell::Qualifier() const {
+ return qualifier_;
+}
+
+unsigned long Cell::Timestamp() const {
+ return timestamp_;
+}
+
+const std::string &Cell::Value() const {
+ return value_;
+}
+
+hbase::CellType Cell::Type() const {
+ return cell_type_;
+}
+
+long Cell::SequenceId() const {
+ return sequence_id_;
+}
+
+} /* namespace hbase */
http://git-wip-us.apache.org/repos/asf/hbase/blob/fa3ab420/hbase-native-client/core/cell.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/cell.h b/hbase-native-client/core/cell.h
new file mode 100644
index 0000000..16ed280
--- /dev/null
+++ b/hbase-native-client/core/cell.h
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ *
+ */
+
+#pragma once
+
+#include <string>
+
+namespace hbase {
+
+enum CellType {
+ MINIMUM = 0,
+ PUT = 4,
+ DELETE = 8,
+ DELETEFAMILYVERSION = 10,
+ DELETE_COLUMN = 12,
+ DELETE_FAMILY = 14,
+ MAXIMUM = 255
+};
+
+class Cell {
+ public:
+ Cell(const std::string &row, const std::string &family,
+ const std::string &qualifier, const long ×tamp,
+ const std::string &value, const hbase::CellType &cell_type);
+ virtual ~Cell();
+ const std::string &Row() const;
+ const std::string &Family() const;
+ const std::string &Qualifier() const;
+ unsigned long Timestamp() const;
+ const std::string &Value() const;
+ CellType Type() const;
+ long SequenceId() const;
+
+ private:
+ std::string row_;
+ std::string family_;
+ std::string qualifier_;
+ unsigned long timestamp_;
+ hbase::CellType cell_type_;
+ std::string value_;
+ long sequence_id_;
+};
+
+} /* namespace hbase */