|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | #include "google/cloud/bigtable/internal/defaults.h" |
| 16 | +#include "google/cloud/bigtable/client.h" |
16 | 17 | #include "google/cloud/bigtable/testing/table_integration_test.h" |
17 | 18 | #include "google/cloud/log.h" |
18 | 19 | #include "google/cloud/testing_util/chrono_literals.h" |
@@ -186,6 +187,45 @@ TEST_P(DataIntegrationTest, TableReadRowTest) { |
186 | 187 | CheckEqualUnordered(expected, actual); |
187 | 188 | } |
188 | 189 |
|
| 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 | + |
189 | 229 | TEST_P(DataIntegrationTest, TableReadRowNotExistTest) { |
190 | 230 | auto table = GetTable(GetParam()); |
191 | 231 | std::string const row_key1 = "row-key-1"; |
|
0 commit comments