-
Notifications
You must be signed in to change notification settings - Fork 179
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
Feat: add risingwave engine adapter support for sqlmesh. #3436
Open
lin0303-siyuan
wants to merge
23
commits into
TobikoData:main
Choose a base branch
from
lin0303-siyuan:feature/rw
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f652202
feat(rw): support basic risingwave dialect
lin0303-siyuan a99f828
feat(rw): add risingwave integration support
lin0303-siyuan 32c763e
fix(rw): correct py style
lin0303-siyuan fe78639
fix(rw): risingwave integration test support, only sushi failed
lin0303-siyuan 9661bf6
fix(rw): use postgres engine adapter as base for rw
lin0303-siyuan 3f7fff6
feat(rw): support drop schema cascade
lin0303-siyuan ba86e19
Merge branch 'main' into feature/rw
lin0303-siyuan d5b7b83
fix(rw): fix t.Literal type error for rw connection
lin0303-siyuan f455e40
fix(rw): skip truncate test for risingwave
lin0303-siyuan 2e4e9ea
fix(rw): use latest rw image
lin0303-siyuan 650112f
Merge branch 'main' into feature/rw
lin0303-siyuan ad0b722
fix(rw): remove unnecessary log and comment
lin0303-siyuan 8bcc106
fix(rw): remove print in test_integration
lin0303-siyuan 1a7f618
fix(rw): correct default integration init and update rw tests
lin0303-siyuan d0255b5
fix(rw): set flush true in cursor init for rw
lin0303-siyuan 7ffdc42
fix(rw): impl truncate_table use delete from
lin0303-siyuan c92bffe
fix(rw): use latest rw image and delete drop schema alternative impl
lin0303-siyuan e8ebed5
fix(rw): don't skip the truncate table test for rw
lin0303-siyuan e34a716
fix(rw): password is not required for rw adapter
lin0303-siyuan badcd70
feat(rw): add risingwave docs
lin0303-siyuan 7be81a8
Merge branch 'main' into feature/rw
lin0303-siyuan 50ce26d
feat(rw): add create sink example for rw docs
lin0303-siyuan 4341e8f
fix(rw): remove unnecessary connection args
lin0303-siyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,53 @@ | ||
# RisingWave | ||
|
||
This page provides information about how to use SQLMesh with the RisingWave streaming database engine. | ||
|
||
## Connection options | ||
|
||
| Option | Description | Type | Required | | ||
|----------------|--------------------------------------------------------------|:------:|:--------:| | ||
| `type` | Engine type name - must be `risingwave` | string | Y | | ||
| `host` | The hostname of the RisingWave engine | string | Y | | ||
| `user` | The username to use for authentication with the RisingWave engine | string | Y | | ||
| `password` | The password to use for authentication with the RisingWave engine | string | N | | ||
| `port` | The port number of the RisingWave engine server | int | Y | | ||
| `database` | The name of the database instance to connect to | string | Y | | ||
| `role` | The role to use for authentication with the Postgres server | string | N | | ||
| `sslmode` | The security of the connection to the Postgres server | string | N | | ||
|
||
## Usage | ||
RisingWave engine has some different features as streaming database. You can create a resource that RisingWave can read data from with `CREATE SOURCE`. You can also create an external target where you can send data processed in RisingWave with `CREATE SINK`. | ||
|
||
To use this in SQLMesh, you can refer to optional pre-statements and post-statements as [SQL models doc](https://sqlmesh.readthedocs.io/en/stable/concepts/models/sql_models/) here specify. | ||
|
||
Below is an example of creating sink in SQLMesh models as post-statement. | ||
|
||
```sql | ||
MODEL ( | ||
name sqlmesh_example.view_model, | ||
kind VIEW ( | ||
materialized true | ||
) | ||
); | ||
|
||
SELECT | ||
item_id, | ||
COUNT(DISTINCT id) AS num_orders, | ||
FROM | ||
sqlmesh_example.incremental_model | ||
GROUP BY item_id; | ||
|
||
CREATE | ||
SINK IF NOT EXISTS kafka_sink | ||
FROM | ||
@this_model | ||
WITH ( | ||
connector='kafka', | ||
"properties.bootstrap.server"='localhost:9092', | ||
topic='test1', | ||
) | ||
FORMAT PLAIN | ||
ENCODE JSON (force_append_only=true); | ||
``` | ||
|
||
here `@this_model` macro is used to represent "sqlmesh_example.view_model" model. |
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
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,35 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import typing as t | ||
|
||
|
||
from sqlglot import exp | ||
|
||
from sqlmesh.core.engine_adapter.postgres import PostgresEngineAdapter | ||
from sqlmesh.core.engine_adapter.shared import ( | ||
set_catalog, | ||
CatalogSupport, | ||
CommentCreationView, | ||
CommentCreationTable, | ||
) | ||
|
||
|
||
if t.TYPE_CHECKING: | ||
from sqlmesh.core._typing import TableName | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@set_catalog() | ||
class RisingwaveEngineAdapter(PostgresEngineAdapter): | ||
DIALECT = "risingwave" | ||
DEFAULT_BATCH_SIZE = 400 | ||
CATALOG_SUPPORT = CatalogSupport.SINGLE_CATALOG_ONLY | ||
COMMENT_CREATION_TABLE = CommentCreationTable.COMMENT_COMMAND_ONLY | ||
COMMENT_CREATION_VIEW = CommentCreationView.UNSUPPORTED | ||
SUPPORTS_MATERIALIZED_VIEWS = True | ||
SUPPORTS_TRANSACTIONS = False | ||
|
||
def _truncate_table(self, table_name: TableName) -> None: | ||
return self.execute(exp.Delete(this=exp.to_table(table_name))) |
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
5 changes: 5 additions & 0 deletions
5
tests/core/engine_adapter/integration/docker/compose.risingwave.yaml
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,5 @@ | ||
services: | ||
risingwave: | ||
image: risingwavelabs/risingwave:nightly-20250119 | ||
ports: | ||
- "4566:4566" |
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 |
---|---|---|
|
@@ -227,6 +227,14 @@ def test_type(request): | |
pytest.mark.athena, | ||
], | ||
), | ||
pytest.param( | ||
"risingwave", | ||
marks=[ | ||
pytest.mark.docker, | ||
pytest.mark.engine, | ||
pytest.mark.risingwave, | ||
], | ||
), | ||
] | ||
) | ||
def mark_gateway(request) -> t.Tuple[str, str]: | ||
|
@@ -370,7 +378,7 @@ def test_create_table(ctx: TestContext): | |
column_descriptions={"id": "test id column description"}, | ||
table_format=ctx.default_table_format, | ||
) | ||
results = ctx.get_metadata_results() | ||
results = ctx.get_metadata_results(schema=table.db) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has changed it for all adapters? |
||
assert len(results.tables) == 1 | ||
assert len(results.views) == 0 | ||
assert len(results.materialized_views) == 0 | ||
|
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,49 @@ | ||
# type: ignore | ||
import typing as t | ||
from unittest.mock import call | ||
|
||
import pytest | ||
from sqlglot import parse_one | ||
from sqlmesh.core.engine_adapter.risingwave import RisingwaveEngineAdapter | ||
|
||
pytestmark = [pytest.mark.engine, pytest.mark.risingwave] | ||
|
||
|
||
@pytest.fixture | ||
def adapter(make_mocked_engine_adapter): | ||
adapter = make_mocked_engine_adapter(RisingwaveEngineAdapter) | ||
return adapter | ||
|
||
|
||
def test_create_view(adapter: t.Callable): | ||
adapter.create_view("db.view", parse_one("SELECT 1"), replace=True) | ||
adapter.create_view("db.view", parse_one("SELECT 1"), replace=False) | ||
|
||
adapter.cursor.execute.assert_has_calls( | ||
[ | ||
# 1st call | ||
call('DROP VIEW IF EXISTS "db"."view" CASCADE'), | ||
call('CREATE VIEW "db"."view" AS SELECT 1'), | ||
# 2nd call | ||
call('CREATE VIEW "db"."view" AS SELECT 1'), | ||
] | ||
) | ||
|
||
|
||
def test_drop_view(adapter: t.Callable): | ||
adapter.drop_view("db.view") | ||
|
||
adapter.drop_view("db.view", materialized=True) | ||
|
||
adapter.drop_view("db.view", cascade=False) | ||
|
||
adapter.cursor.execute.assert_has_calls( | ||
[ | ||
# 1st call | ||
call('DROP VIEW IF EXISTS "db"."view" CASCADE'), | ||
# 2nd call | ||
call('DROP MATERIALIZED VIEW IF EXISTS "db"."view" CASCADE'), | ||
# 3rd call | ||
call('DROP VIEW IF EXISTS "db"."view"'), | ||
] | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres?