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

[FEATURE] Infer SQL types for Expectation tests #10601

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from

Conversation

joshua-stauffer
Copy link
Member

This PR adds functionality which allows test authors to skip explicit types when writing expectation tests.

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for niobium-lead-7998 canceled.

Name Link
🔨 Latest commit 9628b16
🔍 Latest deploy log https://app.netlify.com/sites/niobium-lead-7998/deploys/67232bb458f3aa000841d27f

from sqlalchemy import Column, MetaData, Table, create_engine, insert

# commented out types are present in SqlAlchemy 2.x but not 1.4
from sqlalchemy.dialects.postgresql import (
Copy link
Member Author

Choose a reason for hiding this comment

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

we shouldn't be importing these types directly off sqlalchemy

Comment on lines 52 to 55
str: postgresql.VARCHAR, # type: ignore[dict-item]
int: postgresql.INTEGER, # type: ignore[dict-item]
float: postgresql.FLOAT, # type: ignore[dict-item]
bool: postgresql.BOOLEAN, # type: ignore[dict-item]
Copy link
Member Author

Choose a reason for hiding this comment

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

@tyler-hoffman any suggestions here to fix these types?

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 67.93%. Comparing base (ee2219e) to head (9628b16).
Report is 1 commits behind head on develop.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
great_expectations/compatibility/sqlalchemy.py 50.00% 4 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (ee2219e) and HEAD (9628b16). Click for more details.

HEAD has 72 uploads less than BASE
Flag BASE (ee2219e) HEAD (9628b16)
3.10 2 1
3.9 2 1
3.12 2 1
3.9 clickhouse 2 0
3.12 big 2 0
3.9 aws_deps 2 0
3.9 big 2 0
3.12 aws_deps 2 0
3.9 athena or openpyxl or pyarrow or project or sqlite or aws_creds 2 0
3.9 spark_connect 2 0
3.9 filesystem 2 0
3.12 spark_connect 2 0
3.12 filesystem 2 0
3.12 athena or openpyxl or pyarrow or project or sqlite or aws_creds 2 0
3.9 mysql 2 0
docs-spark 1 0
docs-creds-needed 1 0
3.12 mysql 2 0
3.12 mssql 2 0
3.12 postgresql 2 0
3.9 trino 2 0
3.12 trino 2 0
3.9 mssql 2 0
3.9 postgresql 2 0
docs-basic 1 0
3.9 spark 2 0
cloud 1 0
3.12 spark 1 0
3.9 databricks 1 0
3.9 snowflake 1 0
3.12 snowflake 1 0
3.12 databricks 1 0
3.11 clickhouse 1 0
3.10 clickhouse 1 0
3.11 aws_deps 1 0
3.10 aws_deps 1 0
3.10 big 1 0
3.11 big 1 0
3.11 filesystem 1 0
3.10 filesystem 1 0
3.11 athena or openpyxl or pyarrow or project or sqlite or aws_creds 1 0
3.10 spark_connect 1 0
3.11 spark_connect 1 0
3.11 mysql 1 0
3.10 mysql 1 0
3.11 mssql 1 0
3.10 mssql 1 0
3.11 postgresql 1 0
3.10 postgresql 1 0
3.10 trino 1 0
3.11 trino 1 0
3.10 athena or openpyxl or pyarrow or project or sqlite or aws_creds 1 0
Additional details and impacted files
@@             Coverage Diff              @@
##           develop   #10601       +/-   ##
============================================
- Coverage    80.25%   67.93%   -12.33%     
============================================
  Files          461      459        -2     
  Lines        40005    40019       +14     
============================================
- Hits         32107    27187     -4920     
- Misses        7898    12832     +4934     
Flag Coverage Δ
3.10 67.92% <50.00%> (+<0.01%) ⬆️
3.10 athena or openpyxl or pyarrow or project or sqlite or aws_creds ?
3.10 aws_deps ?
3.10 big ?
3.10 clickhouse ?
3.10 filesystem ?
3.10 mssql ?
3.10 mysql ?
3.10 postgresql ?
3.10 spark_connect ?
3.10 trino ?
3.11 67.90% <50.00%> (+<0.01%) ⬆️
3.11 athena or openpyxl or pyarrow or project or sqlite or aws_creds ?
3.11 aws_deps ?
3.11 big ?
3.11 clickhouse ?
3.11 filesystem ?
3.11 mssql ?
3.11 mysql ?
3.11 postgresql ?
3.11 spark_connect ?
3.11 trino ?
3.12 67.90% <50.00%> (-0.02%) ⬇️
3.12 athena or openpyxl or pyarrow or project or sqlite or aws_creds ?
3.12 aws_deps ?
3.12 big ?
3.12 databricks ?
3.12 filesystem ?
3.12 mssql ?
3.12 mysql ?
3.12 postgresql ?
3.12 snowflake ?
3.12 spark ?
3.12 spark_connect ?
3.12 trino ?
3.9 67.94% <50.00%> (-0.02%) ⬇️
3.9 athena or openpyxl or pyarrow or project or sqlite or aws_creds ?
3.9 aws_deps ?
3.9 big ?
3.9 clickhouse ?
3.9 databricks ?
3.9 filesystem ?
3.9 mssql ?
3.9 mysql ?
3.9 postgresql ?
3.9 snowflake ?
3.9 spark ?
3.9 spark_connect ?
3.9 trino ?
cloud ?
docs-basic ?
docs-creds-needed ?
docs-spark ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tyler-hoffman tyler-hoffman left a comment

Choose a reason for hiding this comment

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

Really nice. I think there's some stuff to circle back on, but I love this.

def infer_column_types(self) -> Dict[str, TypeEngine]:
inferred_column_types: Dict[str, TypeEngine] = {}
for column, value_list in self.data.to_dict("list").items():
python_type = type(value_list[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather merge this and then circle back on this suggestion, but checking just the first item seems a bit off. Pandas looks like it has an api to infer types. No clue on if it works for us. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.api.types.infer_dtype.html



class PostgreSQLDatasourceTestConfig(DataSourceTestConfig[PostgresColumnType]):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should circle back on this loss of typing, but not now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants