You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by en...@apache.org on 2017/09/15 21:20:38 UTC
[21/25] hbase git commit: HBASE-18725 [C++] Install header files as
well as library
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/cell.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/cell.cc b/hbase-native-client/core/cell.cc
deleted file mode 100644
index e475d49..0000000
--- a/hbase-native-client/core/cell.cc
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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 <climits>
-#include <limits>
-#include <stdexcept>
-
-#include "folly/Conv.h"
-#include "utils/bytes-util.h"
-
-namespace hbase {
-
-Cell::Cell(const std::string &row, const std::string &family, const std::string &qualifier,
- const int64_t 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 >= timestamp) throw std::runtime_error("Timestamp should be greater than 0");
-}
-
-Cell::Cell(const Cell &cell)
- : row_(cell.row_),
- family_(cell.family_),
- qualifier_(cell.qualifier_),
- timestamp_(cell.timestamp_),
- cell_type_(cell.cell_type_),
- value_(cell.value_),
- sequence_id_(cell.sequence_id_) {}
-
-Cell &Cell::operator=(const Cell &cell) {
- row_ = cell.row_;
- family_ = cell.family_;
- qualifier_ = cell.qualifier_;
- timestamp_ = cell.timestamp_;
- cell_type_ = cell.cell_type_;
- value_ = cell.value_;
- sequence_id_ = cell.sequence_id_;
-
- return *this;
-}
-
-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_; }
-
-int64_t Cell::Timestamp() const { return timestamp_; }
-
-const std::string &Cell::Value() const { return value_; }
-
-hbase::CellType Cell::Type() const { return cell_type_; }
-
-int64_t Cell::SequenceId() const { return sequence_id_; }
-
-std::string Cell::DebugString() const {
- std::string timestamp_str;
- if (timestamp_ == std::numeric_limits<int64_t>::max()) {
- timestamp_str = "LATEST_TIMESTAMP";
- } else {
- timestamp_str = folly::to<std::string>(timestamp_);
- }
-
- return BytesUtil::ToStringBinary(row_) + "/" + BytesUtil::ToStringBinary(family_) +
- (family_.empty() ? "" : ":") + BytesUtil::ToStringBinary(qualifier_) + "/" +
- timestamp_str + "/" + TypeToString(cell_type_) + "/vlen=" +
- folly::to<std::string>(value_.size()) + "/seqid=" + folly::to<std::string>(sequence_id_);
-}
-
-const char *Cell::TypeToString(CellType type) {
- switch (type) {
- case CellType::MINIMUM:
- return "MINIMUM";
- case CellType::PUT:
- return "PUT";
- case CellType::DELETE:
- return "DELETE";
- case CellType::DELETE_COLUMN:
- return "DELETE_COLUMN";
- case CellType::DELETE_FAMILY:
- return "DELETE_FAMILY";
- case CellType::MAXIMUM:
- return "MAXIMUM";
- default:
- return "UNKNOWN";
- }
-}
-
-size_t Cell::EstimatedSize() const {
- size_t s = sizeof(Cell);
- s += row_.capacity();
- s += family_.capacity();
- s += qualifier_.capacity();
- s += value_.capacity();
- return s;
-}
-
-} /* namespace hbase */
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/cell.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/cell.h b/hbase-native-client/core/cell.h
deleted file mode 100644
index 7a62a9b..0000000
--- a/hbase-native-client/core/cell.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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 <cstdint>
-#include <string>
-
-namespace hbase {
-
-enum class CellType {
- MINIMUM = 0,
- PUT = 4,
- DELETE = 8,
- DELETE_FAMILY_VERSION = 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 int64_t timestamp, const std::string &value, const hbase::CellType &cell_type);
- Cell(const Cell &cell);
- Cell &operator=(const Cell &cell);
- virtual ~Cell();
- const std::string &Row() const;
- const std::string &Family() const;
- const std::string &Qualifier() const;
- int64_t Timestamp() const;
- const std::string &Value() const;
- CellType Type() const;
- int64_t SequenceId() const;
- std::string DebugString() const;
- /** Returns estimated size of the Cell object including deep heap space usage
- * of its data. Notice that this is a very rough estimate. */
- size_t EstimatedSize() const;
-
- private:
- std::string row_;
- std::string family_;
- std::string qualifier_;
- // Since java does not have unsigned, we are also using signed numerics here
- // so that we won't have surprises when large uint64's are treated as
- // negative values in the java server side
- int64_t timestamp_;
- hbase::CellType cell_type_;
- std::string value_;
- int64_t sequence_id_;
-
- private:
- static const char *TypeToString(CellType type);
-};
-
-} // namespace hbase
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/client-test.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/client-test.cc b/hbase-native-client/core/client-test.cc
deleted file mode 100644
index 3f72880..0000000
--- a/hbase-native-client/core/client-test.cc
+++ /dev/null
@@ -1,697 +0,0 @@
-/*
- * 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 <gtest/gtest.h>
-
-#include "core/append.h"
-#include "core/cell.h"
-#include "core/client.h"
-#include "core/configuration.h"
-#include "core/delete.h"
-#include "core/get.h"
-#include "core/hbase-configuration-loader.h"
-#include "core/increment.h"
-#include "core/put.h"
-#include "core/result.h"
-#include "core/table.h"
-#include "exceptions/exception.h"
-#include "serde/table-name.h"
-#include "test-util/test-util.h"
-#include "utils/bytes-util.h"
-
-using hbase::Cell;
-using hbase::Configuration;
-using hbase::Get;
-using hbase::RetriesExhaustedException;
-using hbase::Put;
-using hbase::Table;
-using hbase::TestUtil;
-using std::experimental::nullopt;
-
-class ClientTest : public ::testing::Test {
- public:
- static const constexpr char *kDefHBaseConfPath = "./build/test-data/client-test/conf/";
- static const constexpr char *kHBaseDefaultXml = "hbase-default.xml";
- static const constexpr char *kHBaseSiteXml = "hbase-site.xml";
- static const constexpr char *kHBaseXmlData =
- "<?xml version=\"1.0\"?>\n<?xml-stylesheet type=\"text/xsl\" "
- "href=\"configuration.xsl\"?>\n<!--\n/**\n *\n * Licensed to the Apache "
- "Software Foundation (ASF) under one\n * or more contributor license "
- "agreements. See the NOTICE file\n * distributed with this work for "
- "additional information\n * regarding copyright ownership. The ASF "
- "licenses this file\n * to you under the Apache License, Version 2.0 "
- "(the\n * \"License\"); you may not use this file except in compliance\n * "
- "with the License. You may obtain a copy of the License at\n *\n * "
- "http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by "
- "applicable law or agreed to in writing, software\n * distributed under "
- "the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES "
- "OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License "
- "for the specific language governing permissions and\n * limitations under "
- "the License.\n "
- "*/\n-->\n<configuration>\n\n</configuration>";
-
- static void WriteDataToFile(const std::string &file, const std::string &xml_data) {
- std::ofstream hbase_conf;
- hbase_conf.open(file.c_str());
- hbase_conf << xml_data;
- hbase_conf.close();
- }
-
- static void CreateHBaseConf(const std::string &dir, const std::string &file,
- const std::string xml_data) {
- // Remove temp file always
- boost::filesystem::remove((dir + file).c_str());
- boost::filesystem::create_directories(dir.c_str());
- WriteDataToFile((dir + file), xml_data);
- }
-
- static void CreateHBaseConfWithEnv() {
- // Creating Empty Config Files so that we dont get a Configuration exception @Client
- CreateHBaseConf(kDefHBaseConfPath, kHBaseDefaultXml, kHBaseXmlData);
- // the hbase-site.xml would be persisted by MiniCluster
- setenv("HBASE_CONF", kDefHBaseConfPath, 1);
- }
- static std::unique_ptr<hbase::TestUtil> test_util;
-
- static void SetUpTestCase() {
- google::InstallFailureSignalHandler();
- test_util = std::make_unique<hbase::TestUtil>();
- test_util->StartMiniCluster(2);
- }
-};
-std::unique_ptr<hbase::TestUtil> ClientTest::test_util = nullptr;
-
-TEST_F(ClientTest, EmptyConfigurationPassedToClient) { ASSERT_ANY_THROW(hbase::Client client); }
-
-TEST_F(ClientTest, ConfigurationPassedToClient) {
- // Remove already configured env if present.
- unsetenv("HBASE_CONF");
- ClientTest::CreateHBaseConfWithEnv();
-
- // Create Configuration
- hbase::HBaseConfigurationLoader loader;
- auto conf = loader.LoadDefaultResources();
- // Create a client
- hbase::Client client(conf.value());
- client.Close();
-}
-
-TEST_F(ClientTest, DefaultConfiguration) {
- // Remove already configured env if present.
- unsetenv("HBASE_CONF");
- ClientTest::CreateHBaseConfWithEnv();
-
- // Create Configuration
- hbase::Client client;
- client.Close();
-}
-
-TEST_F(ClientTest, Append) {
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable("t", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t");
- auto row = "test1";
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
- std::string val1 = "a";
- auto result = table->Append(hbase::Append{row}.Add("d", "1", val1));
-
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- EXPECT_EQ(row, result->Row());
- EXPECT_EQ(val1, *(result->Value("d", "1")));
-
- std::string val2 = "b";
- result = table->Append(hbase::Append{row}.Add("d", "1", val2));
-
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- EXPECT_EQ(row, result->Row());
- EXPECT_EQ("ab", *(result->Value("d", "1")));
-}
-
-TEST_F(ClientTest, PutGetDelete) {
- // Using TestUtil to populate test data
- std::string tableName = "t1";
- ClientTest::test_util->CreateTable(tableName, "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>(tableName);
- auto row = "test1";
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- // Perform Puts
- std::string valExtra = "value for extra";
- std::string valExt = "value for ext";
- table->Put(Put{row}.AddColumn("d", "1", "value1"));
- // Put two values for column "extra"
- table->Put(Put{row}.AddColumn("d", "extra", "1st val extra"));
- usleep(1000);
- table->Put(Put{row}.AddColumn("d", "extra", valExtra));
- table->Put(Put{row}.AddColumn("d", "ext", valExt));
-
- // Perform the Get
- hbase::Get get(row);
- auto result = table->Get(get);
-
- // Test the values, should be same as in put executed on hbase shell
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- EXPECT_EQ("test1", result->Row());
- EXPECT_EQ("value1", *(result->Value("d", "1")));
- EXPECT_EQ(valExtra, *(result->Value("d", "extra")));
- auto cell = *(result->ColumnCells("d", "extra"))[0];
- auto tsExtra = cell.Timestamp();
- auto tsExt = (*(result->ColumnCells("d", "ext"))[0]).Timestamp();
-
- // delete column "1"
- table->Delete(hbase::Delete{row}.AddColumn("d", "1"));
- result = table->Get(get);
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- ASSERT_FALSE(result->Value("d", "1")) << "Column 1 should be gone";
- EXPECT_EQ(valExtra, *(result->Value("d", "extra")));
-
- // delete cell from column "extra" with timestamp tsExtra
- table->Delete(hbase::Delete{row}.AddColumn("d", "extra", tsExtra));
- result = table->Get(get);
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- ASSERT_FALSE(result->Value("d", "1")) << "Column 1 should be gone";
- ASSERT_TRUE(result->Value("d", "extra") != nullopt) << "Column extra should have value";
- EXPECT_EQ(valExt, *(result->Value("d", "ext"))) << "Column ext should have value";
-
- // delete all cells from "extra" column
- table->Delete(hbase::Delete{row}.AddColumns("d", "extra"));
- result = table->Get(get);
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- ASSERT_FALSE(result->Value("d", "1")) << "Column 1 should be gone";
- ASSERT_FALSE(result->Value("d", "extra")) << "Column extra should be gone";
- EXPECT_EQ(valExt, *(result->Value("d", "ext"))) << "Column ext should have value";
-
- // Delete the row and verify that subsequent Get returns nothing
- table->Delete(hbase::Delete{row}.AddFamily("d"));
- result = table->Get(get);
- ASSERT_TRUE(result->IsEmpty()) << "Result should be empty.";
-
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, Increment) {
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable("t1", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t1");
- auto row = "test1";
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
- int64_t incr1 = 1235;
- auto result = table->Increment(hbase::Increment{row}.AddColumn("d", "1", incr1));
- EXPECT_EQ(row, result->Row());
-
- long l = hbase::BytesUtil::ToInt64(*(result->Value("d", "1")));
- EXPECT_EQ(incr1, l);
-
- int64_t incr2 = -2;
- result = table->Increment(hbase::Increment{row}.AddColumn("d", "1", incr2));
-
- EXPECT_EQ(row, result->Row());
- EXPECT_EQ(incr1 + incr2, hbase::BytesUtil::ToInt64(*(result->Value("d", "1"))));
-}
-
-TEST_F(ClientTest, CheckAndPut) {
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable("check", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("check");
- auto row = "test1";
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- // Perform Puts
- table->Put(Put{row}.AddColumn("d", "1", "value1"));
- auto result = table->CheckAndPut(row, "d", "1", "value1", Put{row}.AddColumn("d", "1", "value2"));
- ASSERT_TRUE(result) << "CheckAndPut didn't replace value";
-
- result = table->CheckAndPut(row, "d", "1", "value1", Put{row}.AddColumn("d", "1", "value3"));
-
- // Perform the Get
- hbase::Get get(row);
- auto result1 = table->Get(get);
- EXPECT_EQ("value2", *(result1->Value("d", "1")));
- ASSERT_FALSE(result) << "CheckAndPut shouldn't replace value";
-}
-
-TEST_F(ClientTest, CheckAndDelete) {
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable("checkDel", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("checkDel");
- auto row = "test1";
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- auto val1 = "value1";
-
- // Perform Puts
- table->Put(Put{row}.AddColumn("d", "1", val1));
- table->Put(Put{row}.AddColumn("d", "2", "value2"));
- auto result = table->CheckAndDelete(row, "d", "1", val1, hbase::Delete{row}.AddColumn("d", "2"));
- ASSERT_TRUE(result) << "CheckAndDelete didn't replace value";
-
- // Perform the Get
- hbase::Get get(row);
- auto result1 = table->Get(get);
- EXPECT_EQ(val1, *(result1->Value("d", "1")));
- ASSERT_FALSE(result1->Value("d", "2")) << "Column 2 should be gone";
-}
-
-TEST_F(ClientTest, PutGet) {
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable("t", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t");
- auto row = "test1";
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- // Perform Puts
- table->Put(Put{"test1"}.AddColumn("d", "1", "value1"));
- table->Put(Put{"test1"}.AddColumn("d", "extra", "value for extra"));
-
- // Perform the Get
- hbase::Get get(row);
- auto result = table->Get(get);
-
- // Test the values, should be same as in put executed on hbase shell
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- EXPECT_EQ("test1", result->Row());
- EXPECT_EQ("value1", *(result->Value("d", "1")));
- EXPECT_EQ("value for extra", *(result->Value("d", "extra")));
-
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, GetForNonExistentTable) {
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t_not_exists");
- auto row = "test1";
-
- // Get to be performed on above HBase Table
- hbase::Get get(row);
-
- ClientTest::test_util->conf()->SetInt("hbase.client.retries.number", 5);
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- // Perform the Get
- try {
- table->Get(get);
- FAIL() << "Should have thrown RetriesExhaustedException";
- } catch (const RetriesExhaustedException &ex) {
- ASSERT_EQ(0, ex.num_retries());
- } catch (...) {
- FAIL() << "Should have thrown RetriesExhaustedException";
- }
-
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, GetForNonExistentRow) {
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable("t_exists", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t_exists");
- auto row = "row_not_exists";
-
- // Get to be performed on above HBase Table
- hbase::Get get(row);
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- // Perform the Get
- auto result = table->Get(get);
- ASSERT_TRUE(result->IsEmpty()) << "Result should be empty.";
-
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, PutsWithTimestamp) {
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable("t_puts_with_timestamp", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t_puts_with_timestamp");
- auto row = "test1";
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- int64_t ts = 42;
- // Perform Puts
- table->Put(Put{"test1"}.AddColumn("d", "1", ts, "value1"));
- auto cell =
- std::make_unique<Cell>("test1", "d", "extra", ts, "value for extra", hbase::CellType::PUT);
- table->Put(Put{"test1"}.Add(std::move(cell)));
-
- // Perform the Get
- hbase::Get get(row);
- auto result = table->Get(get);
-
- // Test the values, should be same as in put executed on hbase shell
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- EXPECT_EQ("test1", result->Row());
- EXPECT_EQ("value1", *(result->Value("d", "1")));
- EXPECT_EQ("value for extra", *(result->Value("d", "extra")));
- EXPECT_EQ(ts, result->ColumnLatestCell("d", "1")->Timestamp());
- EXPECT_EQ(ts, result->ColumnLatestCell("d", "extra")->Timestamp());
-
- table->Close();
- client.Close();
-}
-
-void SetClientParams() {
- ClientTest::test_util->conf()->SetInt("hbase.client.cpu.thread.pool.size", 6);
- ClientTest::test_util->conf()->SetInt("hbase.client.operation.timeout", 600000);
- ClientTest::test_util->conf()->SetInt("hbase.client.retries.number", 7);
- ClientTest::test_util->conf()->SetInt("hbase.client.start.log.errors.counter", 1);
-}
-
-void PerformPuts(uint64_t num_rows, std::shared_ptr<hbase::Client> client,
- const std::string &table_name) {
- auto tn = folly::to<hbase::pb::TableName>(table_name);
- auto table = client->Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
- // Perform Puts
- for (uint64_t i = 0; i < num_rows; i++) {
- table->Put(Put{"test" + std::to_string(i)}.AddColumn("d", std::to_string(i),
- "value" + std::to_string(i)));
- }
-}
-
-void MakeGets(uint64_t num_rows, const std::string &row_prefix, std::vector<hbase::Get> &gets) {
- // Perform the Gets
- for (uint64_t i = 0; i < num_rows; ++i) {
- auto row = "test" + std::to_string(i);
- hbase::Get get(row);
- gets.push_back(get);
- }
- gets.push_back(hbase::Get("test2"));
- gets.push_back(hbase::Get("testextra"));
-}
-
-void TestMultiResults(uint64_t num_rows, const std::vector<std::shared_ptr<hbase::Result>> &results,
- const std::vector<hbase::Get> &gets) {
- // Test the values, should be same as in put executed on hbase shell
- ASSERT_TRUE(!results.empty()) << "Result vector shouldn't be empty.";
-
- uint32_t i = 0;
- for (; i < num_rows; ++i) {
- ASSERT_TRUE(!results[i]->IsEmpty()) << "Result for Get " << gets[i].row()
- << " must not be empty";
- EXPECT_EQ("test" + std::to_string(i), results[i]->Row());
- EXPECT_EQ("value" + std::to_string(i), results[i]->Value("d", std::to_string(i)).value());
- }
- // We are inserting test2 twice so the below test should pass
- ASSERT_TRUE(!results[i]->IsEmpty()) << "Result for Get " << gets[i].row() << " must not be empty";
-
- ++i;
- ASSERT_TRUE(results[i]->IsEmpty()) << "Result for Get " << gets[i].row() << " must be empty";
-}
-
-TEST_F(ClientTest, MultiGets) {
- std::string table_name = "t";
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable(table_name, "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>(table_name);
-
- SetClientParams();
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- uint64_t num_rows = 50000;
- PerformPuts(num_rows, std::make_shared<hbase::Client>(client), table_name);
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- std::vector<hbase::Get> gets;
- MakeGets(num_rows, "test", gets);
-
- auto results = table->Get(gets);
-
- TestMultiResults(num_rows, results, gets);
-
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, MultiGetsWithRegionSplits) {
- // Using TestUtil to populate test data
- std::vector<std::string> keys{"test0", "test100", "test200", "test300", "test400",
- "test500", "test600", "test700", "test800", "test900"};
- std::string table_name = "t";
- ClientTest::test_util->CreateTable(table_name, "d", keys);
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>(table_name);
-
- SetClientParams();
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- uint64_t num_rows = 50000;
- PerformPuts(num_rows, std::make_shared<hbase::Client>(client), table_name);
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table != nullptr) << "Unable to get connection to Table.";
-
- std::vector<hbase::Get> gets;
- MakeGets(num_rows, "test", gets);
-
- auto results = table->Get(gets);
-
- TestMultiResults(num_rows, results, gets);
-
- table->Close();
- client.Close();
-}
-
-void PerformMultiPuts(uint64_t num_rows, std::shared_ptr<hbase::Client> client,
- const std::string &table_name) {
- auto tn = folly::to<hbase::pb::TableName>(table_name);
- auto table = client->Table(tn);
- ASSERT_TRUE(table) << "Unable to get connection to Table.";
- std::vector<hbase::Put> puts;
- // Perform Puts
- for (uint64_t i = 0; i < num_rows; i++) {
- puts.push_back(Put{"test" + std::to_string(i)}.AddColumn("d", std::to_string(i),
- "value" + std::to_string(i)));
- }
- table->Put(puts);
-}
-
-void PerformMultiPuts(std::vector<hbase::Put> &puts, std::shared_ptr<Table> table) {
- table->Put(puts);
-}
-
-TEST_F(ClientTest, MultiGetsWithMultiPuts) {
- std::string table_name = "t";
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable(table_name, "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>(table_name);
-
- SetClientParams();
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- uint64_t num_rows = 50000;
- PerformMultiPuts(num_rows, std::make_shared<hbase::Client>(client), table_name);
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table) << "Unable to get connection to Table.";
-
- std::vector<hbase::Get> gets;
- MakeGets(num_rows, "test", gets);
-
- auto results = table->Get(gets);
-
- TestMultiResults(num_rows, results, gets);
-
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, MultiGetsWithMultiPutsAndSplitRegions) {
- // Using TestUtil to populate test data
- std::vector<std::string> keys{"test0", "test100", "test200", "test300", "test400",
- "test500", "test600", "test700", "test800", "test900"};
- std::string table_name = "t";
- ClientTest::test_util->CreateTable(table_name, "d", keys);
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>(table_name);
-
- SetClientParams();
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
-
- uint64_t num_rows = 50000;
- PerformMultiPuts(num_rows, std::make_shared<hbase::Client>(client), table_name);
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
- ASSERT_TRUE(table) << "Unable to get connection to Table.";
-
- std::vector<hbase::Get> gets;
- MakeGets(num_rows, "test", gets);
-
- auto results = table->Get(gets);
-
- TestMultiResults(num_rows, results, gets);
-
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, MultiPuts) {
- std::string table_name = "t";
- // Using TestUtil to populate test data
- ClientTest::test_util->CreateTable(table_name, "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>(table_name);
-
- SetClientParams();
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
- std::shared_ptr<Table> table = client.Table(tn);
- ASSERT_TRUE(table) << "Unable to get connection to Table.";
-
- uint64_t num_rows = 80000;
- uint64_t batch_num_rows = 10000;
- std::vector<hbase::Put> puts;
- for (uint64_t i = 0; i < num_rows;) {
- puts.clear();
- // accumulate batch_num_rows at a time
- for (uint64_t j = 0; j < batch_num_rows && i < num_rows; ++j) {
- hbase::Put put("test" + std::to_string(i));
- put.AddColumn("d", std::to_string(i), "value" + std::to_string(i));
- puts.push_back(put);
- i++;
- }
- PerformMultiPuts(puts, table);
- }
- table->Close();
- client.Close();
-}
-
-TEST_F(ClientTest, MultiPutsWithRegionSplits) {
- // Using TestUtil to populate test data
- std::vector<std::string> keys{"test0", "test100", "test200", "test300", "test400",
- "test500", "test600", "test700", "test800", "test900"};
- std::string table_name = "t";
- ClientTest::test_util->CreateTable(table_name, "d", keys);
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>(table_name);
-
- SetClientParams();
-
- // Create a client
- hbase::Client client(*ClientTest::test_util->conf());
- std::shared_ptr<Table> table = client.Table(tn);
- ASSERT_TRUE(table) << "Unable to get connection to Table.";
-
- uint64_t num_rows = 80000;
- uint64_t batch_num_rows = 10000;
- std::vector<hbase::Put> puts;
- for (uint64_t i = 0; i < num_rows;) {
- puts.clear();
- // accumulate batch_num_rows at a time
- for (uint64_t j = 0; j < batch_num_rows && i < num_rows; ++j) {
- hbase::Put put("test" + std::to_string(i));
- put.AddColumn("d", std::to_string(i), "value" + std::to_string(i));
- puts.push_back(put);
- i++;
- }
- PerformMultiPuts(puts, table);
- }
- table->Close();
- client.Close();
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/client.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/client.cc b/hbase-native-client/core/client.cc
deleted file mode 100644
index e23aeae..0000000
--- a/hbase-native-client/core/client.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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/client.h"
-
-#include <glog/logging.h>
-#include <chrono>
-#include <exception>
-#include <memory>
-#include <utility>
-
-using hbase::pb::TableName;
-
-namespace hbase {
-
-Client::Client() {
- HBaseConfigurationLoader loader;
- auto conf = loader.LoadDefaultResources();
- if (!conf) {
- LOG(ERROR) << "Unable to create default Configuration object. Either hbase-default.xml or "
- "hbase-site.xml is absent in the search path or problems in XML parsing";
- throw std::runtime_error("Configuration object not present.");
- }
- Init(conf.value());
-}
-
-Client::Client(const Configuration &conf) { Init(conf); }
-
-void Client::Init(const Configuration &conf) {
- auto conf_ = std::make_shared<Configuration>(conf);
- async_connection_ = AsyncConnectionImpl::Create(conf_);
-}
-
-std::unique_ptr<Table> Client::Table(const TableName &table_name) {
- return std::make_unique<hbase::Table>(table_name, async_connection_);
-}
-
-void Client::Close() { async_connection_->Close(); }
-} // namespace hbase
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/client.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/client.h b/hbase-native-client/core/client.h
deleted file mode 100644
index 5563a15..0000000
--- a/hbase-native-client/core/client.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 <memory>
-#include <string>
-
-#include "connection/rpc-client.h"
-#include "core/async-connection.h"
-#include "core/configuration.h"
-
-#include "core/table.h"
-#include "serde/table-name.h"
-
-namespace hbase {
-
-class Table;
-/**
- * Client.
- *
- * This is the class that provides access to an HBase cluster.
- * It is thread safe and does connection pooling. Current recommendations are to
- * have only one Client per cluster around.
- */
-class Client {
- public:
- /**
- * @brief Create a new client.
- * @param quorum_spec Where to connect to get Zookeeper bootstrap information.
- */
- Client();
- explicit Client(const Configuration& conf);
- ~Client() = default;
-
- /**
- * @brief Retrieve a Table implementation for accessing a table.
- * @param - table_name
- */
- std::unique_ptr<::hbase::Table> Table(const pb::TableName& table_name);
-
- /**
- * @brief Close the Client connection.
- */
- void Close();
-
- /**
- * @brief Internal. DO NOT USE.
- */
- std::shared_ptr<AsyncConnectionImpl> async_connection() { return async_connection_; }
-
- private:
- /** Data */
- std::shared_ptr<AsyncConnectionImpl> async_connection_;
-
- private:
- /** Methods */
- void Init(const Configuration& conf);
-};
-
-} // namespace hbase
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/configuration-test.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/configuration-test.cc b/hbase-native-client/core/configuration-test.cc
deleted file mode 100644
index abdf0c7..0000000
--- a/hbase-native-client/core/configuration-test.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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/configuration.h"
-#include <gtest/gtest.h>
-
-using hbase::Configuration;
-
-TEST(Configuration, SetGetBool) {
- Configuration conf;
-
- /* test true/false */
- conf.SetBool("bool_key1", true);
- EXPECT_EQ(true, conf.GetBool("bool_key1", false));
- conf.SetBool("bool_key2", false);
- EXPECT_EQ(false, conf.GetBool("bool_key2", true));
-
- /* test 1/0 */
- conf.SetBool("bool_key3", 1);
- EXPECT_EQ(true, conf.GetBool("bool_key3", false));
- conf.SetBool("bool_key4", 0);
- EXPECT_EQ(false, conf.GetBool("bool_key4", true));
-
- /* test non zero integer */
- conf.SetBool("bool_key5", 5);
- EXPECT_EQ(true, conf.GetBool("bool_key5", false));
- conf.SetBool("bool_key6", -1);
- EXPECT_EQ(true, conf.GetBool("bool_key5", false));
-
- /* test non zero float */
- conf.SetBool("bool_key7", 5.1);
- EXPECT_EQ(true, conf.GetBool("bool_key7", false));
- conf.SetBool("bool_key8", -1.2);
- EXPECT_EQ(true, conf.GetBool("bool_key8", false));
-}
-
-TEST(Configuration, SetGetForBool) {
- Configuration conf;
-
- /* test true/false */
- conf.Set("bool_key1", "true");
- EXPECT_EQ(true, conf.GetBool("bool_key1", false));
- conf.Set("bool_key2", "false");
- EXPECT_EQ(false, conf.GetBool("bool_key2", true));
-
- /* test 1/0 */
- conf.Set("bool_key3", "1");
- EXPECT_EQ(true, conf.GetBool("bool_key3", false));
- conf.Set("bool_key4", "0");
- EXPECT_EQ(false, conf.GetBool("bool_key4", true));
-
- /* test non zero integer */
- conf.Set("bool_key5", "5");
- EXPECT_THROW(conf.GetBool("bool_key5", false), std::runtime_error);
- conf.Set("bool_key6", "-1");
- EXPECT_THROW(conf.GetBool("bool_key6", false), std::runtime_error);
-
- /* test non zero float */
- conf.Set("bool_key7", "5.1");
- EXPECT_THROW(conf.GetBool("bool_key7", false), std::runtime_error);
- conf.Set("bool_key8", "-1.2");
- EXPECT_THROW(conf.GetBool("bool_key8", false), std::runtime_error);
-}
-
-TEST(Configuration, SetGet) {
- Configuration conf;
-
- EXPECT_EQ(conf.Get("foo", "default"), "default");
- conf.Set("foo", "bar");
- EXPECT_EQ(conf.Get("foo", "default"), "bar");
-}
-
-TEST(Configuration, SetGetInt) {
- Configuration conf;
-
- EXPECT_EQ(conf.GetInt("foo", 0), 0);
- conf.SetInt("foo", 42);
- EXPECT_EQ(conf.GetInt("foo", 0), 42);
-}
-
-TEST(Configuration, SetGetLong) {
- Configuration conf;
-
- EXPECT_EQ(conf.GetLong("foo", 0), 0);
- conf.SetLong("foo", 42);
- EXPECT_EQ(conf.GetLong("foo", 0), 42);
-}
-
-TEST(Configuration, SetGetDouble) {
- Configuration conf;
-
- EXPECT_EQ(conf.GetDouble("foo", 0), 0);
- conf.SetDouble("foo", 42.0);
- EXPECT_EQ(conf.GetDouble("foo", 0), 42.0);
-}
-
-TEST(Configuration, SetGetBoolBasic) {
- Configuration conf;
-
- EXPECT_EQ(conf.GetBool("foo", false), false);
- conf.SetInt("foo", true);
- EXPECT_EQ(conf.GetInt("foo", false), true);
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/configuration.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/configuration.cc b/hbase-native-client/core/configuration.cc
deleted file mode 100644
index 1fd2851..0000000
--- a/hbase-native-client/core/configuration.cc
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * 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/configuration.h"
-
-#include <memory>
-#include <stdexcept>
-#include <utility>
-
-#include <glog/logging.h>
-#include <boost/format.hpp>
-#include <boost/lexical_cast.hpp>
-
-namespace hbase {
-
-Configuration::Configuration() : hb_property_() {}
-
-Configuration::Configuration(ConfigMap &config_map) : hb_property_(std::move(config_map)) {}
-
-Configuration::~Configuration() {}
-
-size_t Configuration::IsSubVariable(const std::string &expr, std::string &sub_variable) const {
- size_t start_pos = expr.find("${");
- if (std::string::npos != start_pos) {
- size_t pos_next = expr.find("}", start_pos + 1);
- if (std::string::npos != pos_next) {
- sub_variable = expr.substr(start_pos + 2, pos_next - (start_pos + 2));
- }
- }
- return start_pos;
-}
-
-std::string Configuration::SubstituteVars(const std::string &expr) const {
- if (0 == expr.size()) return expr;
-
- std::string eval(expr);
- std::string value_to_be_replaced("");
- std::string var("");
- for (int i = 0; i < kMaxSubsts; i++) {
- var = "";
- size_t start_pos = IsSubVariable(eval, var);
- if (start_pos != std::string::npos) {
- // We are blindly checking for environment property at first.
- // If we don't get any value from GetEnv, check in hbase-site.xml.
- value_to_be_replaced = GetEnv(var).value_or(GetProperty(var).value_or(""));
-
- // we haven't found any value yet so we are returning eval
- if (0 == value_to_be_replaced.size()) {
- return eval;
- }
-
- // return original expression if there is a loop
- if (value_to_be_replaced == expr) {
- return expr;
- }
-
- eval.replace(start_pos, var.size() + 3, value_to_be_replaced);
-
- } else {
- // No further expansion required.
- return eval;
- }
- }
- // We reached here if the loop is exhausted
- // If MAX_SUBSTS is exhausted, check if more variable substitution is reqd.
- // If any-more substitutions are reqd, throw an error.
- var = "";
- if (IsSubVariable(eval, var) != std::string::npos) {
- throw std::runtime_error("Variable substitution depth too large: " +
- std::to_string(kMaxSubsts) + " " + expr);
- } else {
- return eval;
- }
-}
-
-optional<std::string> Configuration::GetEnv(const std::string &key) const {
- char buf[2048];
-
- if ("user.name" == key) {
-#ifdef HAVE_GETLOGIN
- return std::experimental::make_optional(getlogin());
-#else
- DLOG(WARNING) << "Client user.name not implemented";
- return optional<std::string>();
-#endif
- }
-
- if ("user.dir" == key) {
-#ifdef HAVE_GETCWD
- if (getcwd(buf, sizeof(buf))) {
- return std::experimental::make_optional(buf);
- } else {
- return optional<std::string>();
- }
-#else
- DLOG(WARNING) << "Client user.dir not implemented";
- return optional<std::string>();
-#endif
- }
-
- if ("user.home" == key) {
-#if defined(HAVE_GETUID) && defined(HAVE_GETPWUID_R)
- uid = getuid();
- if (!getpwuid_r(uid, &pw, buf, sizeof(buf), &pwp)) {
- return std::experimental::make_optional(buf);
- } else {
- return optional<std::string>();
- }
-#else
- DLOG(WARNING) << "Client user.home not implemented";
- return optional<std::string>();
-#endif
- }
- return optional<std::string>();
-}
-
-optional<std::string> Configuration::GetProperty(const std::string &key) const {
- auto found = hb_property_.find(key);
- if (found != hb_property_.end()) {
- return std::experimental::make_optional(found->second.value);
- } else {
- return optional<std::string>();
- }
-}
-
-optional<std::string> Configuration::Get(const std::string &key) const {
- optional<std::string> raw = GetProperty(key);
- if (raw) {
- return std::experimental::make_optional(SubstituteVars(*raw));
- } else {
- return optional<std::string>();
- }
-}
-
-std::string Configuration::Get(const std::string &key, const std::string &default_value) const {
- return Get(key).value_or(default_value);
-}
-
-optional<int32_t> Configuration::GetInt(const std::string &key) const {
- optional<std::string> raw = Get(key);
- if (raw) {
- try {
- return std::experimental::make_optional(boost::lexical_cast<int32_t>(*raw));
- } catch (const boost::bad_lexical_cast &blex) {
- throw std::runtime_error(blex.what());
- }
- }
- return optional<int32_t>();
-}
-
-int32_t Configuration::GetInt(const std::string &key, int32_t default_value) const {
- return GetInt(key).value_or(default_value);
-}
-
-optional<int64_t> Configuration::GetLong(const std::string &key) const {
- optional<std::string> raw = Get(key);
- if (raw) {
- try {
- return std::experimental::make_optional(boost::lexical_cast<int64_t>(*raw));
- } catch (const boost::bad_lexical_cast &blex) {
- throw std::runtime_error(blex.what());
- }
- }
- return optional<int64_t>();
-}
-
-int64_t Configuration::GetLong(const std::string &key, int64_t default_value) const {
- return GetLong(key).value_or(default_value);
-}
-
-optional<double> Configuration::GetDouble(const std::string &key) const {
- optional<std::string> raw = Get(key);
- if (raw) {
- try {
- return std::experimental::make_optional(boost::lexical_cast<double>(*raw));
- } catch (const boost::bad_lexical_cast &blex) {
- throw std::runtime_error(blex.what());
- }
- }
- return optional<double>();
-}
-
-double Configuration::GetDouble(const std::string &key, double default_value) const {
- return GetDouble(key).value_or(default_value);
-}
-
-optional<bool> Configuration::GetBool(const std::string &key) const {
- optional<std::string> raw = Get(key);
- if (raw) {
- if (!strcasecmp((*raw).c_str(), "true") || !strcasecmp((*raw).c_str(), "1")) {
- return std::experimental::make_optional(true);
- } else if (!strcasecmp((*raw).c_str(), "false") || !strcasecmp((*raw).c_str(), "0")) {
- return std::experimental::make_optional(false);
- } else {
- boost::format what("Unexpected value \"%s\" found being converted to bool for key \"%s\"");
- what % (*raw);
- what % key;
- throw std::runtime_error(what.str());
- }
- }
- return optional<bool>();
-}
-
-bool Configuration::GetBool(const std::string &key, bool default_value) const {
- return GetBool(key).value_or(default_value);
-}
-
-void Configuration::Set(const std::string &key, const std::string &value) {
- hb_property_[key] = value;
-}
-
-void Configuration::SetInt(const std::string &key, int32_t value) {
- Set(key, boost::lexical_cast<std::string>(value));
-}
-
-void Configuration::SetLong(const std::string &key, int64_t value) {
- Set(key, boost::lexical_cast<std::string>(value));
-}
-
-void Configuration::SetDouble(const std::string &key, double value) {
- Set(key, boost::lexical_cast<std::string>(value));
-}
-
-void Configuration::SetBool(const std::string &key, bool value) {
- Set(key, boost::lexical_cast<std::string>(value));
-}
-
-} /* namespace hbase */
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/configuration.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/configuration.h b/hbase-native-client/core/configuration.h
deleted file mode 100644
index d70941c..0000000
--- a/hbase-native-client/core/configuration.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * 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.
- *
- */
-
-/* Some pieces of code have been added from HDFS-8707 */
-#pragma once
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include <experimental/optional>
-
-namespace hbase {
-
-template <class T>
-using optional = std::experimental::optional<T>;
-
-class Configuration {
- public:
- /**
- * @brief Create Configuration object using an empty map. This
- * object WILL NOT be initialized from reading XML configuration (hbase-site.xml, etc).
- * Use HBaseConfigurationLoader to initialize the configuration from
- * hbase-default.xml and hbase-site.xml files.
- */
- Configuration();
-
- ~Configuration();
-
- /**
- * @brief Returns value identified by key in ConfigMap else default value if
- * property is absent.
- * @param key Property whose value is to be fetched. SubstituteVars will be
- * called for any variable expansion.
- */
- std::string Get(const std::string &key, const std::string &default_value) const;
-
- /**
- * @brief Returns int32_t identified by key in ConfigMap else default value if
- * property is absent.
- * @param key Property whose value is to be fetched. Internally Get(key) will
- * be called.
- * @throws std::runtime_error if conversion to int32_t fails
- */
- int32_t GetInt(const std::string &key, int32_t default_value) const;
-
- /**
- * @brief Returns int64_t identified by key in ConfigMap else default value if
- * property is absent.
- * @param key Property whose value is to be fetched. Internally Get(key) will
- * be called and
- * @throws std::runtime_error if conversion to int64_t fails
- */
- int64_t GetLong(const std::string &key, int64_t default_value) const;
-
- /**
- * @brief Returns double identified by key in ConfigMap else default value if
- * property is absent.
- * @param key Property whose value is to be fetched. Internally Get(key) will
- * be called.
- * @throws std::runtime_error if conversion to double fails
- */
- double GetDouble(const std::string &key, double default_value) const;
-
- /**
- * @brief Returns bool identified by key in ConfigMap else default value if
- * property is absent.
- * @param key Property whose value is to be fetched. Internally Get(key) will
- * be called.
- * @throws std::runtime_error if conversion to bool fails
- */
- bool GetBool(const std::string &key, bool default_value) const;
-
- /**
- * @brief This method sets the given key to the value.
- * @param key property name
- * @param value property value
- */
- void Set(const std::string &key, const std::string &value);
-
- /**
- * @brief This method sets the given key to the value.
- * @param key property name
- * @param value property value
- */
- void SetInt(const std::string &key, int32_t value);
-
- /**
- * @brief This method sets the given key to the value.
- * @param key property name
- * @param value property value
- */
- void SetLong(const std::string &key, int64_t value);
-
- /**
- * @brief This method sets the given key to the value.
- * @param key property name
- * @param value property value
- */
- void SetDouble(const std::string &key, double value);
-
- /**
- * @brief This method sets the given key to the value.
- * @param key property name
- * @param value property value
- */
- void SetBool(const std::string &key, bool value);
-
- private:
- friend class HBaseConfigurationLoader;
-
- /* Transparent data holder for property values */
- /* Same as Jira HDFS-8707 */
- struct ConfigData {
- std::string value;
- bool final;
- ConfigData() : final(false) {}
- explicit ConfigData(const std::string &value) : value(value), final(false) {}
- void operator=(const std::string &new_value) {
- value = new_value;
- final = false;
- }
- };
-
- /**
- * @brief Map which hold configuration properties.
- */
- using ConfigMap = std::map<std::string, ConfigData>;
-
- /**
- * @brief Create Configuration object using config_map;
- * @param config_map - Map consisting of properties.
- */
- explicit Configuration(ConfigMap &config_map);
-
- // Property map filled all the properties loaded by ConfigurationLoader
- ConfigMap hb_property_;
-
- // Variable expansion depth
- const int kMaxSubsts = 20;
-
- /**
- * @brief returns value for a property identified by key in ConfigMap.
- * SubstituteVars will be called for any variable expansion.
- * @param key Key whose value is to be fetched.
- */
- optional<std::string> Get(const std::string &key) const;
-
- /**
- * @brief returns optional int32_t value identified by the key in ConfigMap.
- * Get(key) is called to get the string value which is then converted to
- * int32_t using boost::lexical_cast.
- * @param key Key whose value is to be fetched.
- * @throws std::runtime_error if conversion to int32_t fails
- */
- optional<int32_t> GetInt(const std::string &key) const;
-
- /**
- * @brief returns optional int64_t value identified by the key in ConfigMap.
- * Get(key) is called internally to get the string value which is then
- * converted to int64_t using boost::lexical_cast.
- * @param key Key whose value is to be fetched.
- * @throws std::runtime_error if conversion to int64_t fails
- */
- optional<int64_t> GetLong(const std::string &key) const;
-
- /**
- * @brief returns optional double value identified by the key in ConfigMap.
- * Get(key) is called to get the string value which is then converted to
- * double using boost::lexical_cast.
- * @param key Key whose value is to be fetched.
- * @throws std::runtime_error if conversion to double fails
- */
- optional<double> GetDouble(const std::string &key) const;
-
- /**
- * @brief returns optional bool for a property identified by key in ConfigMap.
- * Get(key) is called to get the string value which is then converted to bool
- * by checking the validity.
- * @param key Key whose value is to be fetched. Get(key) is called to get the
- * string value which is then converted to bool.
- * @throws std::runtime_error if conversion to bool fails
- */
- optional<bool> GetBool(const std::string &key) const;
-
- /**
- * @brief This method will perform any variable expansion if present.
- * @param expression expression string to perform substitutions on.
- * @throws std::runtime_error if MAX_SUBSTS is exhausted and any more
- * substitutions are reqd to be performed.
- */
- std::string SubstituteVars(const std::string &expr) const;
-
- /**
- * @brief This method will check if variable expansion has to be performed or
- * not. Expression will be checked for presence of "${" and "}" to perform
- * variable expansion.
- * @param expr Expression on which will be checked for validity.
- * @param sub_variable Extracted variable from expr which will be checked
- * against environment value or ConfigMap values.
- */
- size_t IsSubVariable(const std::string &expr, std::string &sub_variable) const;
-
- /**
- * @brief This method will fetch value for key from environment if present.
- * @param key key to be fetched from environment.
- */
- optional<std::string> GetEnv(const std::string &key) const;
-
- /**
- * @brief This method will fetch value for key from ConfigMap if present.
- * @param key key to be fetched from environment.
- */
- optional<std::string> GetProperty(const std::string &key) const;
-};
-} /* namespace hbase */
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/connection-configuration.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/connection-configuration.h b/hbase-native-client/core/connection-configuration.h
deleted file mode 100644
index 995798e..0000000
--- a/hbase-native-client/core/connection-configuration.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * 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 <chrono>
-#include <climits>
-#include <string>
-
-#include "core/configuration.h"
-
-namespace hbase {
-
-/**
- * Timeout configs.
- */
-class ConnectionConfiguration {
- public:
- explicit ConnectionConfiguration(const Configuration& conf) {
- connect_timeout_ =
- ToNanos(conf.GetInt(kClientSocketConnectTimeout, kDefaultClientSocketConnectTimeout));
- meta_operation_timeout_ =
- ToNanos(conf.GetLong(kClientMetaOperationTimeout, kDefaultClientOperationTimeout));
- operation_timeout_ =
- ToNanos(conf.GetLong(kClientOperationTimeout, kDefaultClientOperationTimeout));
- rpc_timeout_ = ToNanos(conf.GetLong(kRpcTimeout, kDefaultRpcTimeout));
- read_rpc_timeout_ = ToNanos(conf.GetLong(kRpcReadTimeout, ToMillis(rpc_timeout_)));
- write_rpc_timeout_ = ToNanos(conf.GetLong(kRpcWriteTimeout, ToMillis(rpc_timeout_)));
- pause_ = ToNanos(conf.GetLong(kClientPause, kDefaultClientPause));
- max_retries_ = conf.GetInt(kClientRetriesNumber, kDefaultClientRetriesNumber);
- start_log_errors_count_ =
- conf.GetInt(kStartLogErrorsAfterCount, kDefaultStartLogErrorsAfterCount);
- scan_timeout_ =
- ToNanos(conf.GetLong(kClientScannerTimeoutPeriod, kDefaultClientScannerTimeoutPeriod));
- scanner_caching_ = conf.GetInt(kClientScannerCaching, kDefaultClientScannerCaching);
- scanner_max_result_size_ =
- conf.GetLong(kClientScannerMaxResultsSize, kDefaultClientScannerMaxResultsSize);
- }
-
- // Used by tests
- ConnectionConfiguration(std::chrono::nanoseconds connect_timeout,
- std::chrono::nanoseconds operation_timeout,
- std::chrono::nanoseconds rpc_timeout, std::chrono::nanoseconds pause,
- uint32_t max_retries, uint32_t start_log_errors_count)
- : connect_timeout_(connect_timeout),
- operation_timeout_(operation_timeout),
- meta_operation_timeout_(operation_timeout),
- rpc_timeout_(rpc_timeout),
- read_rpc_timeout_(rpc_timeout),
- write_rpc_timeout_(rpc_timeout),
- pause_(pause),
- max_retries_(max_retries),
- start_log_errors_count_(start_log_errors_count) {}
-
- std::chrono::nanoseconds connect_timeout() const { return connect_timeout_; }
-
- std::chrono::nanoseconds meta_operation_timeout() const { return meta_operation_timeout_; }
-
- // timeout for a whole operation such as get, put or delete. Notice that scan will not be effected
- // by this value, see scanTimeoutNs.
- std::chrono::nanoseconds operation_timeout() const { return operation_timeout_; }
-
- // timeout for each rpc request. Can be overridden by a more specific config, such as
- // readRpcTimeout or writeRpcTimeout.
- std::chrono::nanoseconds rpc_timeout() const { return rpc_timeout_; }
-
- // timeout for each read rpc request
- std::chrono::nanoseconds read_rpc_timeout() const { return read_rpc_timeout_; }
-
- // timeout for each write rpc request
- std::chrono::nanoseconds write_rpc_timeout() const { return write_rpc_timeout_; }
-
- std::chrono::nanoseconds pause() const { return pause_; }
-
- uint32_t max_retries() const { return max_retries_; }
-
- /** How many retries are allowed before we start to log */
- uint32_t start_log_errors_count() const { return start_log_errors_count_; }
-
- // The scan timeout is used as operation timeout for every
- // operations in a scan, such as openScanner or next.
- std::chrono::nanoseconds scan_timeout() const { return scan_timeout_; }
-
- uint32_t scanner_caching() const { return scanner_caching_; }
-
- uint64_t scanner_max_result_size() const { return scanner_max_result_size_; }
-
- private:
- /** Parameter name for HBase client CPU thread pool size. Defaults to (2 * num cpus) */
- static constexpr const char* kClientSocketConnectTimeout =
- "hbase.ipc.client.socket.timeout.connect";
- /** Parameter name for HBase client CPU thread pool size. Defaults to (2 * num cpus) */
- static constexpr const uint32_t kDefaultClientSocketConnectTimeout = 10000; // 10 secs
-
- /** Parameter name for HBase client operation timeout. */
- static constexpr const char* kClientOperationTimeout = "hbase.client.operation.timeout";
-
- /** Parameter name for HBase client meta operation timeout. */
- static constexpr const char* kClientMetaOperationTimeout = "hbase.client.meta.operation.timeout";
-
- /** Default HBase client operation timeout, which is tantamount to a blocking call */
- static constexpr const uint32_t kDefaultClientOperationTimeout = 1200000;
-
- /** timeout for each RPC */
- static constexpr const char* kRpcTimeout = "hbase.rpc.timeout";
-
- /** timeout for each read RPC */
- static constexpr const char* kRpcReadTimeout = "hbase.rpc.read.timeout";
-
- /** timeout for each write RPC */
- static constexpr const char* kRpcWriteTimeout = "hbase.rpc.write.timeout";
-
- static constexpr const uint32_t kDefaultRpcTimeout = 60000;
-
- /**
- * Parameter name for client pause value, used mostly as value to wait
- * before running a retry of a failed get, region lookup, etc.
- */
- static constexpr const char* kClientPause = "hbase.client.pause";
-
- static constexpr const uint64_t kDefaultClientPause = 100;
-
- /**
- * Parameter name for maximum retries, used as maximum for all retryable
- * operations such as fetching of the root region from root region server,
- * getting a cell's value, starting a row update, etc.
- */
- static constexpr const char* kClientRetriesNumber = "hbase.client.retries.number";
-
- static constexpr const uint32_t kDefaultClientRetriesNumber = 35;
-
- /**
- * Configure the number of failures after which the client will start logging. A few failures
- * is fine: region moved, then is not opened, then is overloaded. We try to have an acceptable
- * heuristic for the number of errors we don't log. 9 was chosen because we wait for 1s at
- * this stage.
- */
- static constexpr const char* kStartLogErrorsAfterCount = "hbase.client.start.log.errors.counter";
- static constexpr const uint32_t kDefaultStartLogErrorsAfterCount = 9;
-
- /** The client scanner timeout period in milliseconds. */
- static constexpr const char* kClientScannerTimeoutPeriod = "hbase.client.scanner.timeout.period";
-
- static constexpr const uint32_t kDefaultClientScannerTimeoutPeriod = 60000;
-
- /**
- * Parameter name to set the default scanner caching for all clients.
- */
- static constexpr const char* kClientScannerCaching = "hbase.client.scanner.caching";
-
- static constexpr const uint32_t kDefaultClientScannerCaching = INT_MAX;
-
- /**
- * Parameter name for maximum number of bytes returned when calling a scanner's next method.
- * Controlled by the client.
- */
- static constexpr const char* kClientScannerMaxResultsSize =
- "hbase.client.scanner.max.result.size";
-
- /**
- * Maximum number of bytes returned when calling a scanner's next method.
- * Note that when a single row is larger than this limit the row is still
- * returned completely.
- *
- * The default value is 2MB.
- */
- static constexpr const uint64_t kDefaultClientScannerMaxResultsSize = 2 * 1024 * 1024;
-
- std::chrono::nanoseconds connect_timeout_;
- std::chrono::nanoseconds meta_operation_timeout_;
- std::chrono::nanoseconds operation_timeout_;
- std::chrono::nanoseconds rpc_timeout_;
- std::chrono::nanoseconds read_rpc_timeout_;
- std::chrono::nanoseconds write_rpc_timeout_;
- std::chrono::nanoseconds pause_;
- uint32_t max_retries_;
- uint32_t start_log_errors_count_;
- std::chrono::nanoseconds scan_timeout_;
- uint32_t scanner_caching_;
- uint64_t scanner_max_result_size_;
-
- static std::chrono::nanoseconds ToNanos(const uint64_t& millis) {
- return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(millis));
- }
-
- static uint64_t ToMillis(const std::chrono::nanoseconds& nanos) {
- return std::chrono::duration_cast<std::chrono::milliseconds>(nanos).count();
- }
-};
-
-} // namespace hbase
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/delete-test.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/delete-test.cc b/hbase-native-client/core/delete-test.cc
deleted file mode 100644
index ec1e3a9..0000000
--- a/hbase-native-client/core/delete-test.cc
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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 <glog/logging.h>
-#include <gtest/gtest.h>
-
-#include "core/delete.h"
-#include "core/mutation.h"
-#include "utils/time-util.h"
-
-using hbase::Delete;
-using hbase::Cell;
-using hbase::CellType;
-using hbase::Mutation;
-using hbase::TimeUtil;
-
-const constexpr int64_t Mutation::kLatestTimestamp;
-
-TEST(Delete, Row) {
- Delete del{"foo"};
- EXPECT_EQ("foo", del.row());
-}
-
-TEST(Delete, Timestamp) {
- Delete del{"row"};
-
- // test default timestamp
- EXPECT_EQ(Mutation::kLatestTimestamp, del.TimeStamp());
-
- // set custom timestamp
- auto ts = TimeUtil::ToMillis(TimeUtil::GetNowNanos());
- del.SetTimeStamp(ts);
- EXPECT_EQ(ts, del.TimeStamp());
-
- // Add a column with custom timestamp
- del.AddColumn("f", "q");
- auto &cell = del.FamilyMap().at("f")[0];
- EXPECT_EQ(ts, cell->Timestamp());
-}
-
-TEST(Delete, HasFamilies) {
- Delete del{"row"};
-
- EXPECT_EQ(false, del.HasFamilies());
-
- del.AddColumn("f", "q");
- EXPECT_EQ(true, del.HasFamilies());
-}
-
-TEST(Delete, Add) {
- CellType cell_type = CellType::DELETE;
- std::string row = "row";
- std::string family = "family";
- std::string column = "column";
- int64_t timestamp = std::numeric_limits<int64_t>::max();
- auto cell = std::make_unique<Cell>(row, family, column, timestamp, "", cell_type);
-
- // add first cell
- Delete del{"row"};
- del.Add(std::move(cell));
- EXPECT_EQ(1, del.FamilyMap().size());
- EXPECT_EQ(1, del.FamilyMap().at(family).size());
-
- // add a non-matching row
- auto cell2 = std::make_unique<Cell>(row, family, column, timestamp, "", cell_type);
- Delete del2{"foo"};
- ASSERT_THROW(del2.Add(std::move(cell2)), std::runtime_error); // rows don't match
-
- // add a second cell with same family
- auto cell3 = std::make_unique<Cell>(row, family, "column-2", timestamp, "", cell_type);
- del.Add(std::move(cell3));
- EXPECT_EQ(1, del.FamilyMap().size());
- EXPECT_EQ(2, del.FamilyMap().at(family).size());
-
- // add a cell to a different family
- auto cell4 = std::make_unique<Cell>(row, "family-2", "column-2", timestamp, "", cell_type);
- del.Add(std::move(cell4));
- EXPECT_EQ(2, del.FamilyMap().size());
- EXPECT_EQ(1, del.FamilyMap().at("family-2").size());
-}
-
-TEST(Delete, AddColumn) {
- std::string row = "row";
- std::string family = "family";
- std::string column = "column";
-
- Delete del{"row"};
- del.AddColumn(family, column);
- EXPECT_EQ(1, del.FamilyMap().size());
- EXPECT_EQ(1, del.FamilyMap().at(family).size());
-
- // add a second cell with same family
- del.AddColumn(family, "column-2");
- EXPECT_EQ(1, del.FamilyMap().size());
- EXPECT_EQ(2, del.FamilyMap().at(family).size());
-
- // add a cell to a different family
- del.AddColumn("family-2", column);
- EXPECT_EQ(2, del.FamilyMap().size());
- EXPECT_EQ(1, del.FamilyMap().at("family-2").size());
-
- // use the AddColumn overload
- auto ts = TimeUtil::ToMillis(TimeUtil::GetNowNanos());
- del.AddColumn(family, column, ts);
- EXPECT_EQ(2, del.FamilyMap().size());
- EXPECT_EQ(3, del.FamilyMap().at(family).size());
- auto &cell = del.FamilyMap().at(family)[2];
- EXPECT_EQ(ts, cell->Timestamp());
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/delete.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/delete.cc b/hbase-native-client/core/delete.cc
deleted file mode 100644
index 5f48782..0000000
--- a/hbase-native-client/core/delete.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-
-
-/*
- * 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/delete.h"
-#include <folly/Conv.h>
-#include <algorithm>
-#include <limits>
-#include <stdexcept>
-#include <utility>
-
-namespace hbase {
-
-/**
- * @brief Add the specified column to this Delete operation.
- * This is an expensive call in that on the server-side, it first does a
- * get to find the latest versions timestamp. Then it adds a delete using
- * the fetched cells timestamp.
- * @param family family name
- * @param qualifier column qualifier
- */
-Delete& Delete::AddColumn(const std::string& family, const std::string& qualifier) {
- return AddColumn(family, qualifier, timestamp_);
-}
-
-/**
- * @brief Add the specified column to this Delete operation.
- * @param family family name
- * @param qualifier column qualifier
- * @param timestamp version timestamp
- */
-Delete& Delete::AddColumn(const std::string& family, const std::string& qualifier,
- int64_t timestamp) {
- if (timestamp < 0) {
- throw std::runtime_error("Timestamp cannot be negative. ts=" +
- folly::to<std::string>(timestamp));
- }
-
- return Add(
- std::make_unique<Cell>(row_, family, qualifier, timestamp, "", hbase::CellType::DELETE));
-}
-/**
- * Delete all versions of the specified column.
- * @param family family name
- * @param qualifier column qualifier
- */
-Delete& Delete::AddColumns(const std::string& family, const std::string& qualifier) {
- return AddColumns(family, qualifier, timestamp_);
-}
-/**
- * Delete all versions of the specified column with a timestamp less than
- * or equal to the specified timestamp.
- * @param family family name
- * @param qualifier column qualifier
- * @param timestamp maximum version timestamp
- */
-Delete& Delete::AddColumns(const std::string& family, const std::string& qualifier,
- int64_t timestamp) {
- if (timestamp < 0) {
- throw std::runtime_error("Timestamp cannot be negative. ts=" +
- folly::to<std::string>(timestamp));
- }
-
- return Add(std::make_unique<Cell>(row_, family, qualifier, timestamp, "",
- hbase::CellType::DELETE_COLUMN));
-}
-/**
- * Delete all versions of all columns of the specified family.
- * <p>
- * Overrides previous calls to deleteColumn and deleteColumns for the
- * specified family.
- * @param family family name
- */
-Delete& Delete::AddFamily(const std::string& family) { return AddFamily(family, timestamp_); }
-
-/**
- * Delete all columns of the specified family with a timestamp less than
- * or equal to the specified timestamp.
- * <p>
- * Overrides previous calls to deleteColumn and deleteColumns for the
- * specified family.
- * @param family family name
- * @param timestamp maximum version timestamp
- */
-Delete& Delete::AddFamily(const std::string& family, int64_t timestamp) {
- const auto& it = family_map_.find(family);
- if (family_map_.end() != it) {
- it->second.clear();
- } else {
- family_map_[family];
- }
- return Add(
- std::make_unique<Cell>(row_, family, "", timestamp, "", hbase::CellType::DELETE_FAMILY));
-}
-/**
- * Delete all columns of the specified family with a timestamp equal to
- * the specified timestamp.
- * @param family family name
- * @param timestamp version timestamp
- */
-Delete& Delete::AddFamilyVersion(const std::string& family, int64_t timestamp) {
- return Add(std::make_unique<Cell>(row_, family, "", timestamp, "",
- hbase::CellType::DELETE_FAMILY_VERSION));
-}
-Delete& Delete::Add(std::unique_ptr<Cell> cell) {
- if (cell->Row() != row_) {
- throw std::runtime_error("The row in " + cell->DebugString() +
- " doesn't match the original one " + row_);
- }
-
- family_map_[cell->Family()].push_back(std::move(cell));
- return *this;
-}
-} // namespace hbase
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/delete.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/delete.h b/hbase-native-client/core/delete.h
deleted file mode 100644
index 9ebb5a6..0000000
--- a/hbase-native-client/core/delete.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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 <cstdint>
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-#include "core/cell.h"
-#include "core/mutation.h"
-
-namespace hbase {
-
-class Delete : public Mutation {
- public:
- /**
- * Constructors
- */
- /*
- * If no further operations are done, this will delete everything
- * associated with the specified row (all versions of all columns in all
- * families), with timestamp from current point in time to the past.
- * Cells defining timestamp for a future point in time
- * (timestamp > current time) will not be deleted.
- */
- explicit Delete(const std::string& row) : Mutation(row) {}
-
- Delete(const std::string& row, int64_t timestamp) : Mutation(row, timestamp) {}
- Delete(const Delete& cdelete) : Mutation(cdelete) {}
- Delete& operator=(const Delete& cdelete) {
- Mutation::operator=(cdelete);
- return *this;
- }
-
- ~Delete() = default;
-
- /**
- * @brief Add the specified column to this Delete operation.
- * @param family family name
- * @param qualifier column qualifier
- */
- Delete& AddColumn(const std::string& family, const std::string& qualifier);
-
- /**
- * @brief Add the specified column to this Delete operation.
- * @param family family name
- * @param qualifier column qualifier
- * @param timestamp version timestamp
- */
- Delete& AddColumn(const std::string& family, const std::string& qualifier, int64_t timestamp);
-
- /**
- * @brief Deletes all versions of the specified column
- * @param family family name
- * @param qualifier column qualifier
- */
- Delete& AddColumns(const std::string& family, const std::string& qualifier);
- /**
- * @brief Deletes all versions of the specified column with a timestamp less than
- * or equal to the specified timestamp
- * @param family family name
- * @param qualifier column qualifier
- * @param timestamp version timestamp
- */
- Delete& AddColumns(const std::string& family, const std::string& qualifier, int64_t timestamp);
- /**
- * @brief Add the specified family to this Delete operation.
- * @param family family name
- */
- Delete& AddFamily(const std::string& family);
-
- /**
- * @brief Deletes all columns of the specified family with a timestamp less than
- * or equal to the specified timestamp
- * @param family family name
- * @param timestamp version timestamp
- */
- Delete& AddFamily(const std::string& family, int64_t timestamp);
- /**
- * @brief Deletes all columns of the specified family with a timestamp
- * equal to the specified timestamp
- * @param family family name
- * @param timestamp version timestamp
- */
- Delete& AddFamilyVersion(const std::string& family, int64_t timestamp);
- /**
- * Advanced use only.
- * Add an existing delete marker to this Delete object.
- */
- Delete& Add(std::unique_ptr<Cell> cell);
-};
-
-} // namespace hbase
http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/core/filter-test.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/core/filter-test.cc b/hbase-native-client/core/filter-test.cc
deleted file mode 100644
index 7276dfb..0000000
--- a/hbase-native-client/core/filter-test.cc
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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 <gtest/gtest.h>
-#include "core/client.h"
-#include "core/configuration.h"
-#include "core/get.h"
-#include "core/put.h"
-#include "core/result.h"
-#include "core/table.h"
-#include "if/Comparator.pb.h"
-#include "if/HBase.pb.h"
-#include "serde/table-name.h"
-#include "test-util/test-util.h"
-
-using hbase::Configuration;
-using hbase::Get;
-using hbase::Put;
-using hbase::FilterFactory;
-using hbase::Table;
-using hbase::TestUtil;
-using hbase::pb::CompareType;
-using hbase::ComparatorFactory;
-using hbase::Comparator;
-
-class FilterTest : public ::testing::Test {
- protected:
- static void SetUpTestCase() {
- test_util_ = std::make_unique<TestUtil>();
- test_util_->StartMiniCluster(2);
- }
-
- static void TearDownTestCase() { test_util_.release(); }
-
- virtual void SetUp() {}
- virtual void TearDown() {}
-
- static std::unique_ptr<TestUtil> test_util_;
-};
-
-std::unique_ptr<TestUtil> FilterTest::test_util_ = nullptr;
-
-TEST_F(FilterTest, GetWithColumnPrefixFilter) {
- // write row1 with 3 columns (column_1, column_2, and foo_column)
- FilterTest::test_util_->CreateTable("t", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t");
- auto row = "row1";
-
- // Gets to be performed on above HBase Table
- Get get_all(row); // expected to return all 3 columns
- Get get_one(row); // expected to return 1 column
- Get get_two(row); // expected to return 2 column
-
- get_one.SetFilter(FilterFactory::ColumnPrefixFilter("foo_"));
- get_two.SetFilter(FilterFactory::ColumnPrefixFilter("column_"));
-
- // Create a client
- hbase::Client client(*(FilterTest::test_util_->conf()));
- auto table = client.Table(tn);
-
- table->Put(Put{"row1"}.AddColumn("d", "column_1", "value1"));
- table->Put(Put{"row1"}.AddColumn("d", "column_2", "value2"));
- table->Put(Put{"row1"}.AddColumn("d", "foo_column", "value3"));
-
- // Perform the Get
- auto result_all = table->Get(get_all);
- auto result_one = table->Get(get_one);
- auto result_two = table->Get(get_two);
-
- table->Close();
- client.Close();
-
- // Test the values
- ASSERT_TRUE(!result_one->IsEmpty()) << "Result shouldn't be empty.";
- ASSERT_TRUE(!result_two->IsEmpty()) << "Result shouldn't be empty.";
- ASSERT_TRUE(!result_all->IsEmpty()) << "Result shouldn't be empty.";
- EXPECT_EQ(row, result_one->Row());
- EXPECT_EQ(row, result_two->Row());
- EXPECT_EQ(row, result_all->Row());
- EXPECT_EQ(1, result_one->Size());
- EXPECT_EQ(2, result_two->Size());
- EXPECT_EQ(3, result_all->Size());
- EXPECT_EQ("value3", *(result_one->Value("d", "foo_column")));
- EXPECT_EQ("value1", *(result_two->Value("d", "column_1")));
- EXPECT_EQ("value2", *(result_two->Value("d", "column_2")));
-}
-
-TEST_F(FilterTest, GetWithQualifierFilter) {
- // write row1 with 3 columns (a,b,c)
- FilterTest::test_util_->CreateTable("t1", "d");
-
- // Create TableName and Row to be fetched from HBase
- auto tn = folly::to<hbase::pb::TableName>("t1");
- auto row = "row1";
-
- // Gets to be performed on above HBase Table
- Get get(row);
- get.SetFilter(FilterFactory::QualifierFilter(CompareType::GREATER_OR_EQUAL,
- *ComparatorFactory::BinaryComparator("b")));
-
- // Create a client
- hbase::Client client(*(FilterTest::test_util_->conf()));
-
- // Get connection to HBase Table
- auto table = client.Table(tn);
-
- table->Put(Put{"row1"}.AddColumn("d", "a", "value1"));
- table->Put(Put{"row1"}.AddColumn("d", "b", "value2"));
- table->Put(Put{"row1"}.AddColumn("d", "c", "value3"));
-
- // Perform the Get
- auto result = table->Get(get);
-
- table->Close();
- client.Close();
-
- // Test the values
- ASSERT_TRUE(!result->IsEmpty()) << "Result shouldn't be empty.";
- EXPECT_EQ(row, result->Row());
- EXPECT_EQ(2, result->Size());
- EXPECT_EQ("value2", *(result->Value("d", "b")));
- EXPECT_EQ("value3", *(result->Value("d", "c")));
-}