Skip to content

Commit 1814f29

Browse files
committed
feat(bigtable): add simple integration test for query support
1 parent 966ce17 commit 1814f29

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

google/cloud/bigtable/internal/data_connection_impl.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,11 @@ StatusOr<bigtable::PreparedQuery> DataConnectionImpl::PrepareQuery(
713713
}
714714
auto operation_context = operation_context_factory_->PrepareQuery(
715715
instance_full_name, app_profile_id(*current));
716+
auto retry = retry_policy(*current);
717+
auto backoff = backoff_policy(*current);
718+
716719
auto response = google::cloud::internal::RetryLoop(
717-
retry_policy(*current), backoff_policy(*current),
720+
std::move(retry), std::move(backoff),
718721
Idempotency::kIdempotent,
719722
[this, operation_context](
720723
grpc::ClientContext& context, Options const& options,
@@ -747,6 +750,7 @@ StatusOr<bigtable::PreparedQuery> DataConnectionImpl::PrepareQuery(
747750
};
748751
auto query_plan = QueryPlan::Create(background_->cq(), *std::move(response),
749752
std::move(refresh_fn));
753+
750754
return bigtable::PreparedQuery(
751755
params.instance, std::move(params.sql_statement), std::move(query_plan));
752756
}

google/cloud/bigtable/table.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,10 @@ class Table {
10001000
ChangePolicies(std::forward<Policies>(policies)...);
10011001
}
10021002

1003+
std::shared_ptr<DataConnection> connection() const {
1004+
return connection_;
1005+
}
1006+
10031007
private:
10041008
/**
10051009
* Send request ReadModifyWriteRowRequest to modify the row and get it back
@@ -1043,6 +1047,7 @@ class Table {
10431047
return idempotent_mutation_policy_->clone();
10441048
}
10451049

1050+
10461051
///@{
10471052
/// @name Helper functions to implement constructors with changed policies.
10481053
void ChangePolicy(RPCRetryPolicy const& policy) {

google/cloud/bigtable/tests/data_integration_test.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/bigtable/internal/defaults.h"
16+
#include "google/cloud/bigtable/client.h"
1617
#include "google/cloud/bigtable/testing/table_integration_test.h"
1718
#include "google/cloud/log.h"
1819
#include "google/cloud/testing_util/chrono_literals.h"
@@ -186,6 +187,45 @@ TEST_P(DataIntegrationTest, TableReadRowTest) {
186187
CheckEqualUnordered(expected, actual);
187188
}
188189

190+
TEST_P(DataIntegrationTest, ClientQueryTest) {
191+
auto table = GetTable(GetParam());
192+
std::string const row_key = "row-key-for-client-query-test";
193+
std::string const family = kFamily4;
194+
std::string const column1 = "c1";
195+
std::string const column2 = "c2";
196+
std::string const value1 = "v1";
197+
std::string const value2 = "v2";
198+
199+
std::vector<Cell> created{
200+
{row_key, family, column1, 0, value1},
201+
{row_key, family, column2, 0, value2},
202+
};
203+
// CreateCells(table, created);
204+
BulkApply(table, created);
205+
206+
auto data_connection = table.connection();
207+
auto client = Client(data_connection);
208+
std::vector<std::string> full_table_path =
209+
absl::StrSplit(table.table_name(), "/");
210+
auto table_name = full_table_path.back();
211+
Project project(project_id());
212+
InstanceResource instance_resource(project, instance_id());
213+
auto prepared_query = client.PrepareQuery(
214+
instance_resource,
215+
SqlStatement("SELECT " + column1 + " FROM " + table_name + " WHERE row_key = '" + row_key + "'"));
216+
ASSERT_STATUS_OK(prepared_query);
217+
218+
auto bound_query = prepared_query->BindParameters({});
219+
auto row_stream = client.ExecuteQuery(std::move(bound_query));
220+
221+
std::vector<StatusOr<bigtable::QueryRow>> rows;
222+
for (auto const& row : std::move(row_stream)) {
223+
rows.push_back(row);
224+
}
225+
226+
ASSERT_EQ(rows.size(), 1);
227+
}
228+
189229
TEST_P(DataIntegrationTest, TableReadRowNotExistTest) {
190230
auto table = GetTable(GetParam());
191231
std::string const row_key1 = "row-key-1";

0 commit comments

Comments
 (0)