• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2016 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Use to patch schema of existing scenario results tables (after adding fields).
17
18import argparse
19import json
20import os
21import sys
22
23gcp_utils_dir = os.path.abspath(
24    os.path.join(os.path.dirname(__file__), "../../gcp/utils")
25)
26sys.path.append(gcp_utils_dir)
27import big_query_utils
28
29_PROJECT_ID = "grpc-testing"
30
31
32def _patch_results_table(dataset_id, table_id):
33    bq = big_query_utils.create_big_query()
34    with open(
35        os.path.dirname(__file__) + "/scenario_result_schema.json", "r"
36    ) as f:
37        table_schema = json.loads(f.read())
38    desc = "Results of performance benchmarks."
39    return big_query_utils.patch_table(
40        bq, _PROJECT_ID, dataset_id, table_id, table_schema
41    )
42
43
44argp = argparse.ArgumentParser(
45    description="Patch schema of scenario results table."
46)
47argp.add_argument(
48    "--bq_result_table",
49    required=True,
50    default=None,
51    type=str,
52    help='Bigquery "dataset.table" to patch.',
53)
54
55args = argp.parse_args()
56
57dataset_id, table_id = args.bq_result_table.split(".", 2)
58
59_patch_results_table(dataset_id, table_id)
60print("Successfully patched schema of %s.\n" % args.bq_result_table)
61