Skip to content

Instantly share code, notes, and snippets.

@emtwo
Created April 13, 2020 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emtwo/bc8e3303136822aa258099f0ecf63b17 to your computer and use it in GitHub Desktop.
Save emtwo/bc8e3303136822aa258099f0ecf63b17 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""Script to generate main summary test schema."""
import json
PROBES_FILE = "histograms_probes.json"
probe_lists = {"parent": [], "content": []}
with open(PROBES_FILE) as probes_file:
probes = json.load(probes_file)
for probe, processes in probes.items():
for process in processes:
probe_lists[process].append(
{"type": "STRING", "name": probe, "mode": "NULLABLE"}
)
json_schema_template = [
{"type": "TIMESTAMP", "name": "submission_timestamp", "mode": "REQUIRED"},
{"type": "INTEGER", "name": "sample_id", "mode": "REQUIRED"},
{"type": "STRING", "name": "document_id", "mode": "NULLABLE"},
{"type": "STRING", "name": "client_id", "mode": "NULLABLE"},
{"type": "STRING", "name": "normalized_channel", "mode": "NULLABLE"},
{"type": "STRING", "name": "normalized_os", "mode": "NULLABLE"},
{
"fields": [
{"type": "STRING", "name": "version", "mode": "NULLABLE"},
{"type": "STRING", "name": "build_id", "mode": "NULLABLE"},
],
"type": "RECORD",
"name": "application",
"mode": "NULLABLE",
},
{
"fields": [
{
"fields": [
{
"fields": [
{
"fields": probe_lists["content"],
"type": "RECORD",
"name": "histograms",
"mode": "NULLABLE",
}
],
"type": "RECORD",
"name": "content",
"mode": "NULLABLE",
}
],
"type": "RECORD",
"name": "processes",
"mode": "NULLABLE",
},
{
"fields": probe_lists["parent"],
"type": "RECORD",
"name": "histograms",
"mode": "NULLABLE",
},
],
"type": "RECORD",
"name": "payload",
"mode": "NULLABLE",
},
]
print(json.dumps(json_schema_template, indent=4, sort_keys=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment