-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ibis): implement mdl validation scripts (#864)
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Description | ||
|
||
This folder contains useful tools and scripts for debugging and validation. | ||
|
||
# Tools | ||
- `mdl_validation.py`: Used to validate a Wren MDL. This script attempts to select all columns in all models. | ||
- Requires the `wren_core` library. Run `just install-core` and `just install` before using it. | ||
``` | ||
poetry run python tools/mdl_validation.py mdl.json function_list/bigquery.csv | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# | ||
# This script is used to validate the MDL file by transforming the SQL queries | ||
# in the MDL file to the SQL queries. This script only validate if it can be transformed | ||
# by Wren core. It does not validate the SQL can be executed by the data source. | ||
# | ||
# Argements: | ||
# - manifest_json_path: Path to the JSON file | ||
# - function_list_path: Path to the function list CSV file | ||
# | ||
|
||
import argparse | ||
import base64 | ||
import json | ||
|
||
from wren_core import SessionContext | ||
|
||
# Set up argument parsing | ||
parser = argparse.ArgumentParser(description="Validate the MDL file") | ||
parser.add_argument("manifest_json_path", help="Path to the JSON file") | ||
parser.add_argument("function_list_path", help="Path to the function list CSV file") | ||
|
||
args = parser.parse_args() | ||
|
||
# Read and encode the JSON data | ||
with open(args.manifest_json_path) as file: | ||
mdl = json.load(file) | ||
# Convert to JSON string | ||
json_str = json.dumps(mdl) | ||
# Encode to base64 | ||
encoded_str = base64.b64encode(json_str.encode("utf-8")).decode("utf-8") | ||
|
||
session_context = SessionContext(encoded_str, args.function_list_path) | ||
error_cases = [] | ||
for model in mdl["models"]: | ||
for column in model["columns"]: | ||
# ignore hidden columns | ||
if column.get("is_hidden"): | ||
continue | ||
sql = f"select \"{column['name']}\" from \"{model['name']}\"" | ||
try: | ||
planned_sql = session_context.transform_sql(sql) | ||
except Exception: | ||
error_cases.append((model, column)) | ||
print(f"Error transforming {model['name']} {column['name']}") | ||
|
||
if len(error_cases) > 0: | ||
raise Exception(f"Error transforming {len(error_cases)} columns") |