Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions ibis-server/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ repos:
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: local
hooks:
- id: taplo
name: taplo
language: system
entry: taplo
args: [ "fmt" ]
types:
- toml
1 change: 1 addition & 0 deletions ibis-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ just run
- Install [poetry](https://github.com/python-poetry/poetry) with version 1.7.1: `curl -sSL https://install.python-poetry.org | python3 - --version 1.7.1`
- Install [casey/just](https://github.com/casey/just)
- Install [pre-commit](https://pre-commit.com) hooks: `just pre-commit-install`
- Install [taplo](https://github.com/tamasfe/taplo) for TOML linting

### Modeling Core
The modeling core is written in Rust and provides the Python adaptor. \
Expand Down
16 changes: 16 additions & 0 deletions ibis-server/app/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class QuerySnowflakeDTO(QueryDTO):
connection_info: SnowflakeConnectionInfo = connection_info_field


class QueryTrinoDTO(QueryDTO):
connection_info: ConnectionUrl | TrinoConnectionInfo = connection_info_field


class BigQueryConnectionInfo(BaseModel):
project_id: str
dataset_id: str
Expand Down Expand Up @@ -97,13 +101,25 @@ class SnowflakeConnectionInfo(BaseModel):
) # Use `sf_schema` to avoid `schema` shadowing in BaseModel


class TrinoConnectionInfo(BaseModel):
host: str
port: int = Field(default=8080)
catalog: str
trino_schema: str = Field(
alias="schema"
) # Use `trino_schema` to avoid `schema` shadowing in BaseModel
user: str | None = None
password: str | None = None


ConnectionInfo = (
BigQueryConnectionInfo
| ConnectionUrl
| MSSqlConnectionInfo
| MySqlConnectionInfo
| PostgresConnectionInfo
| SnowflakeConnectionInfo
| TrinoConnectionInfo
)


Expand Down
20 changes: 20 additions & 0 deletions ibis-server/app/model/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
QueryMySqlDTO,
QueryPostgresDTO,
QuerySnowflakeDTO,
QueryTrinoDTO,
SnowflakeConnectionInfo,
TrinoConnectionInfo,
)


Expand All @@ -35,6 +37,7 @@ class DataSource(StrEnum):
mysql = auto()
postgres = auto()
snowflake = auto()
trino = auto()

def get_connection(self, info: ConnectionInfo) -> BaseBackend:
try:
Expand All @@ -56,6 +59,7 @@ class DataSourceExtension(Enum):
mysql = QueryMySqlDTO
postgres = QueryPostgresDTO
snowflake = QuerySnowflakeDTO
trino = QueryTrinoDTO

def __init__(self, dto: QueryDTO):
self.dto = dto
Expand Down Expand Up @@ -136,3 +140,19 @@ def get_snowflake_connection(info: SnowflakeConnectionInfo) -> BaseBackend:
database=info.database,
schema=info.sf_schema,
)

@staticmethod
def get_trino_connection(
info: ConnectionUrl | TrinoConnectionInfo,
) -> BaseBackend:
if hasattr(info, "connection_url"):
return ibis.connect(info.connection_url)

return ibis.trino.connect(
host=info.host,
port=info.port,
database=info.catalog,
schema=info.trino_schema,
user=info.user,
password=info.password,
)
1 change: 1 addition & 0 deletions ibis-server/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ format:
fmt:
poetry run ruff format .
poetry run ruff check --fix .
taplo fmt
55 changes: 40 additions & 15 deletions ibis-server/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading