-
Notifications
You must be signed in to change notification settings - Fork 226
Fix SQL type converter: respect physicalType with constraints and maxLength for string types #1087
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f50de2
Initial plan
Copilot 81fcb48
Fix SQL type converter to handle physicalType with precision/length a…
Copilot 5dd2e91
Remove module-level docstring from test file header
Copilot 2f36bb7
Fix ruff I001: sort import block in test_sql_type_converter.py
Copilot 4bdfdc4
Replace complex unit tests with simple SQL exporter test using fixtur…
Copilot 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 hidden or 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
31 changes: 31 additions & 0 deletions
31
tests/fixtures/postgres-export-string-types/datacontract.yaml
This file contains hidden or 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,31 @@ | ||
| dataProduct: string-types-test | ||
| version: 1.0.0 | ||
| status: current | ||
| id: string-types-postgres-test | ||
|
|
||
| kind: DataContract | ||
| apiVersion: v3.0.0 | ||
|
|
||
| servers: | ||
| - server: production | ||
| type: postgres | ||
| host: localhost | ||
| port: 5432 | ||
| database: mydb | ||
| schema: public | ||
|
|
||
| schema: | ||
| - name: my_table | ||
| physicalType: table | ||
| properties: | ||
| - name: field_physical_type | ||
| logicalType: string | ||
| physicalType: VARCHAR(255) | ||
| - name: field_max_length | ||
| logicalType: string | ||
| logicalTypeOptions: | ||
| maxLength: 100 | ||
| - name: field_plain_string | ||
| logicalType: string | ||
| - name: field_integer | ||
| logicalType: integer |
This file contains hidden or 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,16 @@ | ||
| from datacontract.data_contract import DataContract | ||
|
|
||
|
|
||
| def test_to_sql_ddl_postgres_string_types(): | ||
| actual = DataContract(data_contract_file="fixtures/postgres-export-string-types/datacontract.yaml").export("sql") | ||
| expected = """ | ||
| -- Data Contract: string-types-postgres-test | ||
| -- SQL Dialect: postgres | ||
| CREATE TABLE my_table ( | ||
| field_physical_type VARCHAR(255), | ||
| field_max_length varchar(100), | ||
| field_plain_string text, | ||
| field_integer integer | ||
| ); | ||
| """.strip() | ||
| assert actual == expected |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@copilot The test is too complicated for me. I want an Sql Exporter test that is simple to understand.
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.
@copilot
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.
Replaced in 4bdfdc4. The test is now a single, simple SQL exporter test (matching
test_export_sql.pystyle) with a fixture YAML attests/fixtures/postgres-export-string-types/datacontract.yaml— asserting the full DDL output coveringphysicalTypepass-through (VARCHAR(255)),maxLength(varchar(100)), plain string (text), and integer.