| 247 | } |
| 248 | |
| 249 | Status BigQueryTableAccessor::ReadSchema() { |
| 250 | string auth_token; |
| 251 | TF_RETURN_IF_ERROR(AuthProvider::GetToken(auth_provider_.get(), &auth_token)); |
| 252 | |
| 253 | // Send a request to read the schema. |
| 254 | std::unique_ptr<HttpRequest> request(http_request_factory_->Create()); |
| 255 | std::vector<char> output_buffer; |
| 256 | output_buffer.reserve(kBufferSize); |
| 257 | request->SetUri(BigQueryUriPrefix()); |
| 258 | request->AddAuthBearerHeader(auth_token); |
| 259 | request->SetResultBuffer(&output_buffer); |
| 260 | TF_RETURN_WITH_CONTEXT_IF_ERROR(request->Send(), " when reading schema for ", |
| 261 | FullTableName()); |
| 262 | |
| 263 | // Parse the schema. |
| 264 | StringPiece response_piece = |
| 265 | StringPiece(&output_buffer[0], output_buffer.size()); |
| 266 | |
| 267 | Json::Value root; |
| 268 | TF_RETURN_IF_ERROR(ParseJson(response_piece, &root)); |
| 269 | const auto& columns = root["schema"]["fields"]; |
| 270 | string column_name_prefix = ""; |
| 271 | schema_root_ = {"", ColumnType::kNone}; |
| 272 | TF_RETURN_IF_ERROR( |
| 273 | ExtractColumnType(columns, column_name_prefix, &schema_root_)); |
| 274 | if (root["numRows"].isNull()) { |
| 275 | return errors::Internal("Number of rows cannot be extracted for table ", |
| 276 | FullTableName()); |
| 277 | } |
| 278 | strings::safe_strto64(root["numRows"].asString().c_str(), &total_num_rows_); |
| 279 | return Status::OK(); |
| 280 | } |
| 281 | |
| 282 | Status BigQueryTableAccessor::ExtractColumnType( |
| 283 | const Json::Value& columns, const string& column_name_prefix, |
no test coverage detected