• 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(
49    '--bq_result_table',
50    required=True,
51    default=None,
52    type=str,
53    help='Bigquery "dataset.table" to patch.')
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