Skip to content

Commit 5ab7b96

Browse files
committed
fix client class and tests
1 parent 1814f29 commit 5ab7b96

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

google/cloud/bigtable/client.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@
1414

1515
#include "google/cloud/bigtable/client.h"
1616
#include "internal/partial_result_set_source.h"
17+
#include "google/cloud/bigtable/internal/unary_client_utils.h"
18+
#include "google/cloud/options.h"
1719

1820
namespace google {
1921
namespace cloud {
2022
namespace bigtable {
2123
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2224

23-
StatusOr<PreparedQuery> Client::PrepareQuery(
24-
InstanceResource const& instance, SqlStatement const& statement,
25-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
26-
Options) {
25+
using ::google::cloud::internal::MergeOptions;
26+
using ::google::cloud::internal::OptionsSpan;
27+
28+
StatusOr<PreparedQuery> Client::PrepareQuery(InstanceResource const& instance,
29+
SqlStatement const& statement,
30+
Options option) {
31+
OptionsSpan span(MergeOptions(std::move(option), opts_));
2732
PrepareQueryParams params{std::move(instance), std::move(statement)};
2833
return conn_->PrepareQuery(std::move(params));
2934
}
@@ -35,8 +40,8 @@ future<StatusOr<PreparedQuery>> Client::AsyncPrepareQuery(
3540
return conn_->AsyncPrepareQuery(std::move(params));
3641
}
3742

38-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
39-
RowStream Client::ExecuteQuery(BoundQuery&& bound_query, Options) {
43+
RowStream Client::ExecuteQuery(BoundQuery&& bound_query, Options option) {
44+
OptionsSpan span(MergeOptions(std::move(option), opts_));
4045
ExecuteQueryParams params{std::move(bound_query)};
4146
auto row_stream = conn_->ExecuteQuery(params);
4247
if (!row_stream.ok()) {

google/cloud/bigtable/tests/data_integration_test.cc

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "google/cloud/bigtable/internal/defaults.h"
1615
#include "google/cloud/bigtable/client.h"
16+
#include "google/cloud/bigtable/internal/defaults.h"
1717
#include "google/cloud/bigtable/testing/table_integration_test.h"
1818
#include "google/cloud/log.h"
1919
#include "google/cloud/testing_util/chrono_literals.h"
@@ -31,12 +31,14 @@ namespace {
3131
using ::google::cloud::bigtable::testing::TableIntegrationTest;
3232
using ::google::cloud::bigtable::testing::TableTestEnvironment;
3333
using ::google::cloud::testing_util::chrono_literals::operator""_ms;
34+
using ::google::cloud::testing_util::IsOkAndHolds;
3435
using ::std::chrono::duration_cast;
3536
using ::std::chrono::microseconds;
3637
using ::std::chrono::milliseconds;
3738
using ::testing::Contains;
3839
using ::testing::ElementsAre;
3940
using ::testing::HasSubstr;
41+
using ms = std::chrono::milliseconds;
4042

4143
class DataIntegrationTest : public TableIntegrationTest,
4244
public ::testing::WithParamInterface<std::string> {
@@ -188,7 +190,11 @@ TEST_P(DataIntegrationTest, TableReadRowTest) {
188190
}
189191

190192
TEST_P(DataIntegrationTest, ClientQueryTest) {
191-
auto table = GetTable(GetParam());
193+
auto const table_id = testing::TableTestEnvironment::table_id();
194+
auto conn = MakeDataConnection(Options{}.set<DataRetryPolicyOption>(
195+
DataLimitedErrorCountRetryPolicy(0).clone()));
196+
auto table = Table(std::move(conn),
197+
TableResource(project_id(), instance_id(), table_id));
192198
std::string const row_key = "row-key-for-client-query-test";
193199
std::string const family = kFamily4;
194200
std::string const column1 = "c1";
@@ -200,19 +206,27 @@ TEST_P(DataIntegrationTest, ClientQueryTest) {
200206
{row_key, family, column1, 0, value1},
201207
{row_key, family, column2, 0, value2},
202208
};
203-
// CreateCells(table, created);
204209
BulkApply(table, created);
205-
206210
auto data_connection = table.connection();
207-
auto client = Client(data_connection);
208-
std::vector<std::string> full_table_path =
211+
auto client =
212+
Client(data_connection,
213+
Options{}
214+
.set<DataRetryPolicyOption>(
215+
DataLimitedErrorCountRetryPolicy(0).clone())
216+
.set<DataBackoffPolicyOption>(
217+
google::cloud::internal::ExponentialBackoffPolicy(
218+
ms(0), ms(0), 2.0)
219+
.clone()));
220+
std::vector<std::string> full_table_path =
209221
absl::StrSplit(table.table_name(), "/");
210222
auto table_name = full_table_path.back();
223+
std::string quoted_table_name = "`" + table_name + "`";
211224
Project project(project_id());
212225
InstanceResource instance_resource(project, instance_id());
213226
auto prepared_query = client.PrepareQuery(
214227
instance_resource,
215-
SqlStatement("SELECT " + column1 + " FROM " + table_name + " WHERE row_key = '" + row_key + "'"));
228+
SqlStatement("SELECT CAST(family4['c0'] AS STRING) AS c0 FROM " +
229+
quoted_table_name + " WHERE _key = '" + row_key + "'"));
216230
ASSERT_STATUS_OK(prepared_query);
217231

218232
auto bound_query = prepared_query->BindParameters({});
@@ -224,6 +238,9 @@ TEST_P(DataIntegrationTest, ClientQueryTest) {
224238
}
225239

226240
ASSERT_EQ(rows.size(), 1);
241+
ASSERT_STATUS_OK(rows[0]);
242+
auto const& row1 = *rows[0];
243+
EXPECT_THAT(row1.columns().at(0), "c0");
227244
}
228245

229246
TEST_P(DataIntegrationTest, TableReadRowNotExistTest) {

0 commit comments

Comments
 (0)