-
Notifications
You must be signed in to change notification settings - Fork 520
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
Add YDB support #592
Add YDB support #592
Conversation
49afa82
to
3892e0a
Compare
@mfridman Can you see this PR? |
Yep, just getting back into the swing of things (long few weeks of travelling). I see there are a few PR's floating around, which one should I take a look at? I presume this one. Thanks for putting up a PR, and apologize for the delay. |
8378152
to
898d81d
Compare
@@ -219,6 +220,7 @@ Examples: | |||
goose mssql "sqlserver://user:password@dbname:1433?database=master" status | |||
goose clickhouse "tcp://127.0.0.1:9000" status | |||
goose vertica "vertica://user:password@localhost:5433/dbname?connection_load_balance=1" status | |||
goose ydb "grpcs://localhost:2135/local?go_query_mode=scripting&go_fake_tx=scripting&go_query_bind=declare,numeric" status |
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.
Can you drop a link to the docs or a comment on what these are?
go_query_mode=scripting
go_fake_tx=scripting
go_query_bind=declare,numeric
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.
go_query_mode
- it is required because YDB have different methods for different types of queries (DDL, DML, etc.). Docs
go_fake_tx
- special mode for external tools like goose, which requires a transactional DDL. Release in v3.44.0
go_query_bind=declare,numeric
- released in v3.44.0 and published in article database/sql bindings for YDB in Go
internal/testdb/ydb.go
Outdated
) | ||
|
||
const ( | ||
YDB_IMAGE = "cr.yandex/yc/yandex-docker-local-ydb" |
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.
Any chance we can pull this from DockerHub?
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.
We have an different registry ghcr.io/ydb-platform/local-ydb
(official github registry).
Is it ok for you?
If ok I will change a registry in next commit
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.
Yes, that'd be great. It makes it a bit easier to maintain if the images are pulled from the same 1-2 registries. If those are down so be it.
Nothing against other registries, but if we have many different ones it increases the chances of flakes.
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.
Switched docker image to ghcr.io/ydb-platform/local-ydb
internal/dialect/dialectquery/ydb.go
Outdated
|
||
func (c *Ydb) CreateTable(tableName string) string { | ||
return fmt.Sprintf(` | ||
CREATE TABLE %s ( |
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.
Where possible, we try to add NOT NULL and a default. Would something like this make sense for ydb?
CREATE TABLE goose_db_version (
version_id Uint64 NOT NULL,
is_applied Bool NOT NULL,
tstamp Timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (version_id)
);
Nits,
- Remove the trailing semicolons from all queries
- Use
q=<query>
andreturn fmt.Sprintf(q, tableName)
pattern like all the other dialect queries (this makes it easier to do maintain, do large search/replace, etc.)
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.
YDB not supports DEFAULT
and NOT NULL
constraints for non-pk columns in latest release (23.3). We will do that in one of the next release. With back-compatible of course. But in current release we can do autocomplete tstamp field explicitly on insert stage with built-in function CurrentUtcTimestamp()
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.
Fixed in 3dba2c8 issues about trailing semicolons and patern fmt.Sprintf(q, tableName)
internal/dialect/dialectquery/ydb.go
Outdated
} | ||
|
||
func (c *Ydb) ListMigrations(tableName string) string { | ||
return fmt.Sprintf(`--!syntax_pg |
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.
Can you explain the --!syntax_pg
? I presume this is some hint if the database supports it, otherwise it's a noop?
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.
Native YQL in YDB not supported next statement
SELECT version_id, is_applied
FROM %s
ORDER BY tstamp DESC
where ORDER BY column (tstamp
) not present in results. It provokes undefined behaviour. And in YDB is too difficult to fix because some intermediate results are materialized in processing stage and missed tstamp column meta for ordering final results.
For garanted behaviour need to add tstamp
to results like
SELECT version_id, is_applied, tstamp
FROM %s
ORDER BY tstamp DESC
But this ad-hoc brokes in database/sql
scanner - because core of goose put only two destination values in this line.
I think it is not good implicit contract for get last migration by timestamp field/column. But I understand - this is legacy.
Thats why I maked another ad-hoc for this trouble with --!syntax_pg
flag.
We have a milestone for support postgresql syntax. In this mode (--!syntax_pg
) a query
SELECT version_id, is_applied
FROM %s
ORDER BY tstamp DESC
works fine. Because in postgresql-compatible mode we are processing queries with postgresql parser. And in this level we allowed some ttrade-off's for proccessing pg-queries under ydb core
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.
added short comment into code about --!syntax_pg
@mfridman I fixed all your issues. Can you see latest version of code in PR? |
@@ -50,6 +51,9 @@ test-e2e-clickhouse: | |||
test-e2e-vertica: | |||
go test $(GO_TEST_FLAGS) ./tests/vertica | |||
|
|||
test-e2e-ydb: | |||
go test $(GO_TEST_FLAGS) -parallel=1 ./tests/e2e -dialect=ydb |
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.
Curious, why need to set -parallel=1
?
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.
Unfortunately, ydb container requires a lot of resources, and on a small machine, high parallelism with running many containers can provoke out-of-memory errors or unexpected behaviour. Because db docker image created for tests only, not for production. In production we have a distributed cluster of ydb nodes and perfect ACID guarantees
} | ||
} | ||
// Fetch port assigned to container | ||
dsn := fmt.Sprintf("grpc://%s:%s/%s", |
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.
Ah interesting, this uses grpc. Shuld try https://connect.build ;)
} | ||
|
||
func (c *Ydb) ListMigrations(tableName string) string { | ||
// "--!syntax_pg" enables query processing with PostgreSQL-compatible syntax. |
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.
Perfect, thank you!
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.
Lgtm. Thanks for contributing a database 🎉
Hello! I am part of YDB application team and we added YDB support to the Goose. We would greatly appreciate any feedback on it. Thanks!