hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject hbase git commit: HBASE-15945 Patch for Cell
Date Tue, 05 Jul 2016 17:48:41 GMT
Repository: hbase
Updated Branches:
  refs/heads/HBASE-14850 6c0216034 -> ad276ef32


HBASE-15945 Patch for Cell

This patch consists of Cell implementation without additional interfaces.

Signed-off-by: Elliott Clark <eclark@apache.org>


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

Branch: refs/heads/HBASE-14850
Commit: ad276ef3225ee2058dc2fec7b866b3eaa4d537cb
Parents: 6c02160
Author: Sudeep Sunthankar <sudeep.sunthankar@gmail.com>
Authored: Mon Jul 4 21:02:25 2016 +1000
Committer: Elliott Clark <eclark@apache.org>
Committed: Tue Jul 5 10:43:41 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/ad276ef3/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/ad276ef3/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 &timestamp,
+           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/ad276ef3/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 &timestamp,
+       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 */


Mime
View raw message