Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ibis): implement mdl validation scripts #864

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ibis-server/tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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.
grieve54706 marked this conversation as resolved.
Show resolved Hide resolved
- Requires the `wren_core` library. Run `just install-core` and `just install` before using it.
47 changes: 47 additions & 0 deletions ibis-server/tools/mdl_validation.py
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
#

from wren_core import SessionContext

import json
import base64
import argparse

# 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, 'r') 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 'is_hidden' in column and column['is_hidden'] == True:
continue
sql = f"select \"{column['name']}\" from \"{model['name']}\""
try:
planned_sql = session_context.transform_sql(sql)
except Exception as e:
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")
Loading