• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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
18from __future__ import print_function
19
20import argparse
21import calendar
22import json
23import os
24import sys
25import time
26import uuid
27
28gcp_utils_dir = os.path.abspath(
29    os.path.join(os.path.dirname(__file__), '../../gcp/utils'))
30sys.path.append(gcp_utils_dir)
31import big_query_utils
32
33_PROJECT_ID = 'grpc-testing'
34
35
36def _patch_results_table(dataset_id, table_id):
37    bq = big_query_utils.create_big_query()
38    with open(os.path.dirname(__file__) + '/scenario_result_schema.json',
39              'r') as f:
40        table_schema = json.loads(f.read())
41    desc = 'Results of performance benchmarks.'
42    return big_query_utils.patch_table(bq, _PROJECT_ID, dataset_id, table_id,
43                                       table_schema)
44
45
46argp = argparse.ArgumentParser(
47    description='Patch schema of scenario results table.')
48argp.add_argument('--bq_result_table',
49                  required=True,
50                  default=None,
51                  type=str,
52                  help='Bigquery "dataset.table" to patch.')
53
54args = argp.parse_args()
55
56dataset_id, table_id = args.bq_result_table.split('.', 2)
57
58_patch_results_table(dataset_id, table_id)
59print('Successfully patched schema of %s.\n' % args.bq_result_table)
60