Skip to content
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: Prevent exceptions due to PostgreSQL xml data type #1384

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

nj1973
Copy link
Contributor

@nj1973 nj1973 commented Jan 3, 2025

This PR duplicates Ibis 9.2 behaviour for PostgreSQL xml data type to DVT. In essence this maps xml columns to data type "unknown".

I tested with the commands below.

Schema validation no longer throws an exception but does show the type as "unknown":

$ data-validation validate schema -sc pg -tc pg --tables-list "dvt_test.tab_xml"

╒══════╤═══════════════════╤═══════════════════╤══════════╤═════════════════════╤═════════════════════╤══════════════════════╤══════════════════════╤════════════════════╤════════════════════╤═════════════════════╕
│ run_ │ validation_name   │ validation_type   │ labels   │ source_table_name   │ target_table_name   │ source_column_name   │ target_column_name   │ source_agg_value   │ target_agg_value   │ validation_status   │
╞══════╪═══════════════════╪═══════════════════╪══════════╪═════════════════════╪═════════════════════╪══════════════════════╪══════════════════════╪════════════════════╪════════════════════╪═════════════════════╡
...
├──────┼───────────────────┼───────────────────┼──────────┼─────────────────────┼─────────────────────┼──────────────────────┼──────────────────────┼────────────────────┼────────────────────┼─────────────────────┤
│ d..d │ Schema            │ Schema            │ []       │ dvt_test.tab_xml    │ dvt_test.tab_xml    │ xml_data             │ xml_data             │ unknown            │ unknown            │ success             │
╘══════╧═══════════════════╧═══════════════════╧══════════╧═════════════════════╧═════════════════════╧══════════════════════╧══════════════════════╧════════════════════╧════════════════════╧═════════════════════╛

Column validation includes the XML column for count but skips it for min/max/sum:

$ data-validation validate column -sc pg -tc pg --tables-list "dvt_test.tab_xml" --count="*" --min="*" --sum="*"

╒═══════════════════╤═══════════════════╤═════════════════════╤══════════════════════╤════════════════════╤════════════════════╤══════════════════╤═════════════════════╤══════════════════════════════════════╕
│ validation_name   │ validation_type   │ source_table_name   │ source_column_name   │ source_agg_value   │ target_agg_value   │   pct_difference │ validation_status   │ run_id                               │
╞═══════════════════╪═══════════════════╪═════════════════════╪══════════════════════╪════════════════════╪════════════════════╪══════════════════╪═════════════════════╪══════════════════════════════════════╡
│ count__xml_data   │ Column            │ dvt_test.tab_xml    │ xml_data             │ 0                  │ 0                  │                0 │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
├───────────────────┼───────────────────┼─────────────────────┼──────────────────────┼────────────────────┼────────────────────┼──────────────────┼─────────────────────┼──────────────────────────────────────┤
│ min__batch_id     │ Column            │ dvt_test.tab_xml    │ batch_id             │ None               │ None               │              nan │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
├───────────────────┼───────────────────┼─────────────────────┼──────────────────────┼────────────────────┼────────────────────┼──────────────────┼─────────────────────┼──────────────────────────────────────┤
│ sum__id           │ Column            │ dvt_test.tab_xml    │ id                   │ None               │ None               │              nan │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
├───────────────────┼───────────────────┼─────────────────────┼──────────────────────┼────────────────────┼────────────────────┼──────────────────┼─────────────────────┼──────────────────────────────────────┤
│ min__id           │ Column            │ dvt_test.tab_xml    │ id                   │ None               │ None               │              nan │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
├───────────────────┼───────────────────┼─────────────────────┼──────────────────────┼────────────────────┼────────────────────┼──────────────────┼─────────────────────┼──────────────────────────────────────┤
│ count__batch_id   │ Column            │ dvt_test.tab_xml    │ batch_id             │ 0                  │ 0                  │              nan │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
├───────────────────┼───────────────────┼─────────────────────┼──────────────────────┼────────────────────┼────────────────────┼──────────────────┼─────────────────────┼──────────────────────────────────────┤
│ count             │ Column            │ dvt_test.tab_xml    │                      │ 0                  │ 0                  │                0 │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
├───────────────────┼───────────────────┼─────────────────────┼──────────────────────┼────────────────────┼────────────────────┼──────────────────┼─────────────────────┼──────────────────────────────────────┤
│ sum__batch_id     │ Column            │ dvt_test.tab_xml    │ batch_id             │ None               │ None               │              nan │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
├───────────────────┼───────────────────┼─────────────────────┼──────────────────────┼────────────────────┼────────────────────┼──────────────────┼─────────────────────┼──────────────────────────────────────┤
│ count__id         │ Column            │ dvt_test.tab_xml    │ id                   │ 0                  │ 0                  │              nan │ success             │ 9f7fe71a-ec1b-45ce-9d11-5b5bceb0e50a │
╘═══════════════════╧═══════════════════╧═════════════════════╧══════════════════════╧════════════════════╧════════════════════╧══════════════════╧═════════════════════╧══════════════════════════════════════╛

Row validation includes the column:

$ data-validation validate row -sc pg_local -tc pg_local --tables-list "dvt_test.tab_xml" --concat="*"

╒═══════════════════╤═══════════════════╤═════════════════════╤══════════════════════╤═════════════════════════════════╤═════════════════════════════════╤══════════════════╤═════════════════════╤══════════════════════════════════════╕
│ validation_name   │ validation_type   │ source_table_name   │ source_column_name   │ source_agg_value                │ target_agg_value                │ pct_difference   │ validation_status   │ run_id                               │
╞═══════════════════╪═══════════════════╪═════════════════════╪══════════════════════╪═════════════════════════════════╪═════════════════════════════════╪══════════════════╪═════════════════════╪══════════════════════════════════════╡
│ concat__all       │ Row               │ dvt_test.tab_xml    │ concat__all          │ 11<?xml version="1.0"?>         │ 11<?xml version="1.0"?>         │                  │ success             │ f2fa1d9f-3a08-420a-beed-4ff075689d0d │
│                   │                   │                     │                      │ <Tests>                         │ <Tests>                         │                  │                     │                                      │
│                   │                   │                     │                      │   <Test Id="1">                 │   <Test Id="1">                 │                  │                     │                                      │
│                   │                   │                     │                      │     <Name>Test 1</Name>         │     <Name>Test 1</Name>         │                  │                     │                                      │
│                   │                   │                     │                      │     <Command>test1.sh</Command> │     <Command>test1.sh</Command> │                  │                     │                                      │
│                   │                   │                     │                      │   </Test>                       │   </Test>                       │                  │                     │                                      │
│                   │                   │                     │                      │   <Test Id="2">                 │   <Test Id="2">                 │                  │                     │                                      │
│                   │                   │                     │                      │     <Name>Test 2</Name>         │     <Name>Test 2</Name>         │                  │                     │                                      │
│                   │                   │                     │                      │     <Command>test2.sh</Command> │     <Command>test2.sh</Command> │                  │                     │                                      │
│                   │                   │                     │                      │   </Test>                       │   </Test>                       │                  │                     │                                      │
│                   │                   │                     │                      │ </Tests>                        │ </Tests>                        │                  │                     │                                      │
╘═══════════════════╧═══════════════════╧═════════════════════╧══════════════════════╧═════════════════════════════════╧═════════════════════════════════╧══════════════════╧═════════════════════╧══════════════════════════════════════╛

$ data-validation validate row -sc pg_local -tc pg_local --tables-list "dvt_test.tab_xml" --hash="*"
╒═══════════════════╤═══════════════════╤═════════════════════╤══════════════════════╤══════════════════════════════════════════════════════════════════╤══════════════════════════════════════════════════════════════════╤══════════════════╤═════════════════════╤══════════════════════════════════════╕
│ validation_name   │ validation_type   │ source_table_name   │ source_column_name   │ source_agg_value                                                 │ target_agg_value                                                 │ pct_difference   │ validation_status   │ run_id                               │
╞═══════════════════╪═══════════════════╪═════════════════════╪══════════════════════╪══════════════════════════════════════════════════════════════════╪══════════════════════════════════════════════════════════════════╪══════════════════╪═════════════════════╪══════════════════════════════════════╡
│ hash__all         │ Row               │ dvt_test.tab_xml    │ hash__all            │ 4b5b2e664058162cf31c1c8a9bb3ef862398dd015616b069d05df0b25f909618 │ 4b5b2e664058162cf31c1c8a9bb3ef862398dd015616b069d05df0b25f909618 │                  │ success             │ cb821d2a-4c0a-415a-8668-38ca3ed086f4 │
╘═══════════════════╧═══════════════════╧═════════════════════╧══════════════════════╧══════════════════════════════════════════════════════════════════╧══════════════════════════════════════════════════════════════════╧══════════════════╧═════════════════════╧══════════════════════════════════════╛

I've added a column to the pso_data_validator.dvt_pg_types test table in the repo but cannot yet add it to the actual test table because tests on other branches will then fail. I do that part after we decide on correct behaviour and approve the PR in principal.

@nj1973 nj1973 linked an issue Jan 3, 2025 that may be closed by this pull request
@nj1973
Copy link
Contributor Author

nj1973 commented Jan 3, 2025

/gcbrun

@nj1973 nj1973 marked this pull request as ready for review January 3, 2025 11:54
@nj1973 nj1973 requested a review from a team as a code owner January 3, 2025 11:54
Copy link
Collaborator

@helensilva14 helensilva14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Minor suggestion added but it's not a blocker for merging.

third_party/ibis/ibis_postgres/datatypes.py Outdated Show resolved Hide resolved
Co-authored-by: Helen Cristina <helensilva14@gmail.com>
@nj1973
Copy link
Contributor Author

nj1973 commented Jan 7, 2025

/gcbrun

@nj1973 nj1973 merged commit 3828c4a into develop Jan 7, 2025
5 checks passed
@nj1973 nj1973 deleted the 1330-postgresql-xml-data-type branch January 7, 2025 11:30
helensilva14 added a commit that referenced this pull request Jan 20, 2025
* feat: Prevent exceptions due to PostgreSQL xml data type

* Update third_party/ibis/ibis_postgres/datatypes.py

Co-authored-by: Helen Cristina <helensilva14@gmail.com>

---------

Co-authored-by: Helen Cristina <helensilva14@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PostgreSQL XML data type not supported
3 participants