patch_scenario_results_schema.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # Use to patch schema of existing scenario results tables (after adding fields).
  16. from __future__ import print_function
  17. import argparse
  18. import calendar
  19. import json
  20. import os
  21. import sys
  22. import time
  23. import uuid
  24. gcp_utils_dir = os.path.abspath(
  25. os.path.join(os.path.dirname(__file__), '../../gcp/utils'))
  26. sys.path.append(gcp_utils_dir)
  27. import big_query_utils
  28. _PROJECT_ID = 'grpc-testing'
  29. def _patch_results_table(dataset_id, table_id):
  30. bq = big_query_utils.create_big_query()
  31. with open(os.path.dirname(__file__) + '/scenario_result_schema.json',
  32. 'r') as f:
  33. table_schema = json.loads(f.read())
  34. desc = 'Results of performance benchmarks.'
  35. return big_query_utils.patch_table(bq, _PROJECT_ID, dataset_id, table_id,
  36. table_schema)
  37. argp = argparse.ArgumentParser(
  38. description='Patch schema of scenario results table.')
  39. argp.add_argument('--bq_result_table',
  40. required=True,
  41. default=None,
  42. type=str,
  43. help='Bigquery "dataset.table" to patch.')
  44. args = argp.parse_args()
  45. dataset_id, table_id = args.bq_result_table.split('.', 2)
  46. _patch_results_table(dataset_id, table_id)
  47. print('Successfully patched schema of %s.\n' % args.bq_result_table)