Skip to content

DATA-2937 Improve get_metadata_from_sample_data with psycopg type map… - #79

Open
Shrikey wants to merge 1 commit into
mainfrom
DATA-2937_improve_get_metadata_from_sample_data
Open

DATA-2937 Improve get_metadata_from_sample_data with psycopg type map…#79
Shrikey wants to merge 1 commit into
mainfrom
DATA-2937_improve_get_metadata_from_sample_data

Conversation

@Shrikey

@Shrikey Shrikey commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

…ping

Add a module-level TYPE_MAPPING (based on FreshServiceWrapper.TYPE_MAPPING in the warehouse repository) and use it in infer_postgres_type, so datetime, date, time, Decimal, UUID, timedelta and list values map to proper PostgreSQL types instead of falling back to text. Mapping keys are corrected to Python 3 class names (Decimal instead of decimal; long/unicode/None dropped) so lookups on type(value).name actually match. float maps to numeric (not real as in the FreshService mapping) to avoid float4 precision loss.

Behavior change: int now always maps to bigint (previously int for small sample values), following the mapping.

Adds a unit test suite for the helper functions in wherescape/tests/.

Issue number

{if exists provide related issue}

Expected behaviour

{what should have happened}

Actual behaviour

{what happens}

Description of fix

{small description of what fixes the issue}

Other info

{anything else that might be related/useful}

…ping

Add a module-level TYPE_MAPPING (based on FreshServiceWrapper.TYPE_MAPPING in
the warehouse repository) and use it in infer_postgres_type, so datetime,
date, time, Decimal, UUID, timedelta and list values map to proper PostgreSQL
types instead of falling back to text. Mapping keys are corrected to Python 3
class names (Decimal instead of decimal; long/unicode/None dropped) so
lookups on type(value).__name__ actually match. float maps to numeric
(not real as in the FreshService mapping) to avoid float4 precision loss.

Behavior change: int now always maps to bigint (previously int for small
sample values), following the mapping.

Adds a unit test suite for the helper functions in wherescape/tests/.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Shrikey
Shrikey requested a review from BFJonk August 11, 2026 09:54
@Shrikey Shrikey self-assigned this Aug 11, 2026
class TestGetMetadataFromSampleData:
def test_docstring_example(self):
sample_data = [
{"id": 1, "name": "John", "score": 95.5, "created_at": "2025-01-01", "active": True},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thought: I would create seperate tests for type based and name based type guesses, mainly because the latter should be extended over time.

assert {type(value).__name__ for value in samples} == set(TYPE_MAPPING)


class TestGetMetadataFromSampleData:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: I would add a docstring on this class for readability / reviewablity

assert {type(value).__name__ for value in samples} == set(TYPE_MAPPING)


class TestGetMetadataFromSampleData:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: I'm missing a rainy day scenario, what happens if there is no expected value for a certain type? or can thus never happen?

"datetime": "timestamp",
"timedelta": "interval",
"list": "text",
# "list": "text[]",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: isn't the commented out version better?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If not, a commented on why is warranted

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