Skip to content

Commit

Permalink
Merge pull request #523 from DalgoT4D/flatten-json
Browse files Browse the repository at this point in the history
send json keys
  • Loading branch information
fatchat authored Mar 26, 2024
2 parents ca36d88 + 0dd3c27 commit c31520a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ddpui/api/warehouse_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic.error_wrappers import ValidationError as PydanticValidationError

from ddpui import auth
from ddpui.core import dbtautomation_service
from ddpui.models.org import OrgWarehouse
from ddpui.utils import secretsmanager
from ddpui.utils.custom_logger import CustomLogger
Expand Down Expand Up @@ -151,3 +152,21 @@ def get_table_count(request, schema_name: str, table_name: str):
raise HttpError(
500, f"Failed to fetch total rows for {schema_name}.{table_name}"
)


@warehouseapi.get("/dbt_project/json_columnspec/", auth=auth.CanManagePipelines())
def get_json_column_spec(request, source_schema: str, input_name: str, json_column: str):
"""Get the json column spec of a table in a warehouse"""
orguser = request.orguser
org = orguser.org

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "Please set up your warehouse first")

if not all([source_schema, input_name, json_column]):
raise HttpError(400, "Missing required parameters")

json_columnspec = dbtautomation_service.json_columnspec(
org_warehouse, source_schema, input_name, json_column)
return json_columnspec
7 changes: 7 additions & 0 deletions ddpui/core/dbtautomation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,10 @@ def warehouse_datatypes(org_warehouse: OrgWarehouse):
"""Get the datatypes of a table in a warehouse"""
wclient = _get_wclient(org_warehouse)
return wclient.get_column_data_types()


def json_columnspec(warehouse: OrgWarehouse, source_schema, input_name, json_column):
"""Get json keys of a table in warehouse"""
wclient = _get_wclient(warehouse)
json_columnspec = wclient.get_json_columnspec(source_schema, input_name, json_column)
return json_columnspec

0 comments on commit c31520a

Please sign in to comment.