Skip to content

Commit

Permalink
chore: pull up func base64_to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
grieve54706 committed Dec 20, 2024
1 parent 3e1bb95 commit 7ec813a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 2 additions & 4 deletions ibis-server/app/mdl/substitute.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import base64

from orjson import orjson
from sqlglot import exp, parse_one
from sqlglot.optimizer.scope import build_scope

from app.model import UnprocessableEntityError
from app.model.data_source import DataSource
from app.util import base64_to_dict


class ModelSubstitute:
def __init__(self, data_source: DataSource, manifest_str: str):
self.data_source = data_source
self.manifest = orjson.loads(base64.b64decode(manifest_str).decode("utf-8"))
self.manifest = base64_to_dict(manifest_str)
self.model_dict = self._build_model_dict(self.manifest["models"])

def substitute(self, sql: str, write: str | None = None) -> str:
Expand Down
8 changes: 3 additions & 5 deletions ibis-server/app/model/validator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

import base64
import json

from app.mdl.rewriter import Rewriter
from app.model import NotFoundError, UnprocessableEntityError
from app.model.connector import Connector
from app.util import base64_to_dict

rules = ["column_is_valid", "relationship_is_valid"]

Expand Down Expand Up @@ -48,8 +46,8 @@ async def _validate_relationship_is_valid(
relationship_name = parameters.get("relationshipName")
if relationship_name is None:
raise MissingRequiredParameterError("relationship")
decoded_manifest = base64.b64decode(manifest_str).decode("utf-8")
manifest = json.loads(decoded_manifest)

manifest = base64_to_dict(manifest_str)

relationship = list(
filter(lambda r: r["name"] == relationship_name, manifest["relationships"])
Expand Down
5 changes: 5 additions & 0 deletions ibis-server/app/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import datetime
import decimal

Expand All @@ -6,6 +7,10 @@
from pandas.core.dtypes.common import is_datetime64_any_dtype


def base64_to_dict(base64_str: str) -> dict:
return orjson.loads(base64.b64decode(base64_str).decode("utf-8"))


def to_json(df: pd.DataFrame) -> dict:
for column in df.columns:
if is_datetime64_any_dtype(df[column].dtype):
Expand Down

0 comments on commit 7ec813a

Please sign in to comment.