-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
241 additions
and
87 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
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,30 @@ | ||
from json import loads | ||
|
||
from app.mdl.rewriter import rewrite | ||
from app.model.data_source import DataSource, ConnectionInfo | ||
|
||
|
||
class Coordinator: | ||
def __init__(self, data_source: DataSource, connection_info: ConnectionInfo, manifest_str: str): | ||
self.data_source = data_source | ||
self.connection = self.data_source.get_connection(connection_info) | ||
self.manifest_str = manifest_str | ||
|
||
def query(self, sql) -> dict: | ||
rewritten_sql = rewrite(self.manifest_str, sql) | ||
return self._to_json(self.connection.sql(rewritten_sql, dialect='trino').to_pandas()) | ||
|
||
def dry_run(self, sql): | ||
try: | ||
rewritten_sql = rewrite(self.manifest_str, sql) | ||
self.connection.sql(rewritten_sql, dialect='trino') | ||
return {"status": "success"} | ||
except Exception as e: | ||
return {"status": "failure", "message": str(e)} | ||
|
||
@staticmethod | ||
def _to_json(df): | ||
json_obj = loads(df.to_json(orient='split')) | ||
del json_obj['index'] | ||
json_obj['dtypes'] = df.dtypes.apply(lambda x: x.name).to_dict() | ||
return json_obj |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
from fastapi import APIRouter | ||
|
||
import app.routers.ibis.bigquery as bigquery | ||
import app.routers.ibis.postgres as postgres | ||
import app.routers.ibis.snowflake as snowflake | ||
|
||
prefix = "/v2/ibis" | ||
|
||
router = APIRouter(prefix=prefix) | ||
|
||
router.include_router(bigquery.router) | ||
router.include_router(postgres.router) | ||
router.include_router(snowflake.router) |
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,21 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Query | ||
|
||
from app.logger import log_dto | ||
from app.model.data_source import DataSource | ||
from app.model.dto import BigQueryDTO | ||
from app.model.coordinator import Coordinator | ||
|
||
router = APIRouter(prefix='/bigquery', tags=['bigquery']) | ||
|
||
data_source = DataSource.bigquery | ||
|
||
|
||
@router.post("/query") | ||
@log_dto | ||
def query(dto: BigQueryDTO, dry_run: Annotated[bool, Query(alias="dryRun")] = False) -> dict: | ||
coord = Coordinator(data_source, dto.connection_info, dto.manifest_str) | ||
if dry_run: | ||
return coord.dry_run(dto.sql) | ||
return coord.query(dto.sql) |
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,21 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Query | ||
|
||
from app.logger import log_dto | ||
from app.model.data_source import DataSource | ||
from app.model.dto import PostgresDTO | ||
from app.model.coordinator import Coordinator | ||
|
||
router = APIRouter(prefix='/postgres', tags=['postgres']) | ||
|
||
data_source = DataSource.postgres | ||
|
||
|
||
@router.post("/query") | ||
@log_dto | ||
def query(dto: PostgresDTO, dry_run: Annotated[bool, Query(alias="dryRun")] = False) -> dict: | ||
coord = Coordinator(data_source, dto.connection_info, dto.manifest_str) | ||
if dry_run: | ||
return coord.dry_run(dto.sql) | ||
return coord.query(dto.sql) |
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,21 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Query | ||
|
||
from app.logger import log_dto | ||
from app.model.data_source import DataSource | ||
from app.model.dto import SnowflakeDTO | ||
from app.model.coordinator import Coordinator | ||
|
||
router = APIRouter(prefix='/snowflake', tags=['snowflake']) | ||
|
||
data_source = DataSource.snowflake | ||
|
||
|
||
@router.post("/query") | ||
@log_dto | ||
def query(dto: SnowflakeDTO, dry_run: Annotated[bool, Query(alias="dryRun")] = False) -> dict: | ||
coord = Coordinator(data_source, dto.connection_info, dto.manifest_str) | ||
if dry_run: | ||
return coord.dry_run(dto.sql) | ||
return coord.query(dto.sql) |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.