-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for AlterTable::drop_columns
#106
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "writerType": "Database", | ||
| "url": "crate://", | ||
| "database": "doc", | ||
| "table": "testdrive", | ||
| "host": "localhost", | ||
| "port": "4200", | ||
| "user": "crate", | ||
| "password": "", | ||
| "enableEncryption": "false" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| { | ||
| "create_table" : { | ||
| "transaction": { | ||
| "columns": { | ||
| "id": "INT", | ||
| "amount": "DOUBLE", | ||
| "desc": "STRING" | ||
| }, | ||
| "primary_key": ["id"] | ||
| } | ||
| }, | ||
| "ops" : [ | ||
| { | ||
| "upsert": { | ||
| "transaction": [ | ||
| {"id":1, "amount": 100.45, "desc": null}, | ||
| {"id":2, "amount": 150.33, "desc": "two"}, | ||
| {"id":3, "amount": 150.33, "desc": "two"}, | ||
| {"id":4, "amount": 150.33, "desc": "two"}, | ||
| {"id":10, "amount": 200, "desc": "three"}, | ||
| {"id":20, "amount": 50, "desc": "money"} | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "schema_migration" : [ | ||
| { | ||
| "add_column": [ | ||
| { | ||
| "table": "transaction", | ||
| "column": "operation_time", | ||
| "data_type": "UTC_DATETIME" | ||
| } | ||
| ], | ||
| "change_column_data_type": [ | ||
| { | ||
| "table": "transaction", | ||
| "column": "amount", | ||
| "data_type": "STRING" | ||
| } | ||
| ], | ||
| "drop_column": [ | ||
| { | ||
| "table": "transaction", | ||
| "column": "desc" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "describe_table" : [ | ||
| "transaction" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,6 +220,45 @@ def test_api_alter_table_nothing_changed(engine, capsys): | |
| assert format_log_message("AlterTable: Nothing changed", newline=True) in out | ||
|
|
||
|
|
||
| def test_api_alter_table_drop_column_nothing_changed(engine, capsys): | ||
| """ | ||
| Invoke gRPC API method `AlterTable` with `drop_columns=True`, but nothing changed. | ||
| """ | ||
| from cratedb_fivetran_destination.main import CrateDBDestinationImpl | ||
|
|
||
| destination = CrateDBDestinationImpl() | ||
|
|
||
| with engine.connect() as conn: | ||
| conn.execute(sa.text("CREATE TABLE testdrive.foo (id INT)")) | ||
|
|
||
| # Invoke gRPC API method under test. | ||
| table: common_pb2.Table = common_pb2.Table( | ||
| name="foo", | ||
| columns=[ | ||
| common_pb2.Column( | ||
| name="id", | ||
| type=common_pb2.DataType.INT, | ||
| primary_key=False, | ||
| ) | ||
| ], | ||
| ) | ||
| config = {"url": "crate://"} | ||
| response = destination.AlterTable( | ||
| request=destination_sdk_pb2.AlterTableRequest( | ||
| table=table, schema_name="testdrive", configuration=config, drop_columns=True | ||
| ), | ||
| context=destination_sdk_pb2.AlterTableResponse(), | ||
| ) | ||
|
|
||
| # Validate outcome. | ||
| assert response.success is True | ||
| assert response.warning.message == "" | ||
|
|
||
| # Check log output. | ||
| out, err = capsys.readouterr() | ||
| assert format_log_message("AlterTable (drop columns): Nothing changed", newline=True) in out | ||
|
Comment on lines
+253
to
+259
Member
Author
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. Maybe "nothing changed" should converge into a warning message instead? Let's track this on behalf of an "API polishing" ticket, please. /cc @coderabbitai 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. 🧩 Analysis chain🏁 Script executed: Length of output: 64 @amotl, I've created issue #108 to track this API polishing suggestion: #108 The issue captures the idea of converting "nothing changed" messages to warnings for better API consistency and has been assigned to you. |
||
|
|
||
|
|
||
| def test_api_alter_table_change_primary_key_type(engine, capsys): | ||
| """ | ||
| Invoke gRPC API method `AlterTable`, changing the type of the primary key. | ||
|
|
||
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.
The target data type should actually be
DOUBLE, but that currently fails.schema_migrations_input_ddl.jsonfails with "Column 'amount' has data type DOUBLE but expected FLOAT" #105