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

SNOW-1794355: [API Coverage] StructType #2623

Merged
merged 25 commits into from
Nov 18, 2024
Merged

SNOW-1794355: [API Coverage] StructType #2623

merged 25 commits into from
Nov 18, 2024

Conversation

sfc-gh-yuwang
Copy link
Collaborator

@sfc-gh-yuwang sfc-gh-yuwang commented Nov 13, 2024

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1794355

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines
  3. Please describe how your code solves the related issue.

    This PR meant to add from_json() method to StructType and other type classes that need it(ArrayType, MapType).
    All the toInternal and fromInternal methods are not added because they are specific to pyspark to covert python object to/from internal java spark object

@sfc-gh-yuwang sfc-gh-yuwang marked this pull request as ready for review November 14, 2024 23:20
@sfc-gh-yuwang sfc-gh-yuwang requested review from a team as code owners November 14, 2024 23:20
Copy link
Contributor

@sfc-gh-jrose sfc-gh-jrose left a comment

Choose a reason for hiding this comment

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

Change looks good to me. Can you add a test that shows expected behavior in some negative cases?

CHANGELOG.md Outdated
@@ -11,6 +11,11 @@
- `simple_string`
- `json_value`
- `json`
- Added support for method `from_json` in the following type classes:
Copy link
Contributor

Choose a reason for hiding this comment

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

we could possible combine all types related improvement summary in a common changelog.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you mean I should add all of them under ##### Types ?

Copy link
Contributor

Choose a reason for hiding this comment

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

something like

- Added new methods to enhance data type handling and JSON serialization/deserialization:
  - To `DataType`, its derived classes, and `StructField`:
    - `type_name`: Returns the type name of the data.
    - `simple_string`: Provides a simple string representation of the data.
    - `json_value`: Returns the data as a JSON-compatible value.
    - `json`: Converts the data to a JSON string.
  - To `ArrayType`, `MapType`, `StructField`, and `StructType`:
    - `from_json`: Enables these types to be created from JSON data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, will do

Comment on lines 677 to 678
_FIXED_DECIMAL = re.compile(r"decimal\(\s*(\d+)\s*,\s*(-?\d+)\s*\)")

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_FIXED_DECIMAL = re.compile(r"decimal\(\s*(\d+)\s*,\s*(-?\d+)\s*\)")
_FIXED_DECIMAL = re.compile(r"decimal\(\s*(\d+)\s*,\s*(\d+)\s*\)")

we shouldn't be expecting negative numbers right?

v.typeName(): v for v in _complex_types
}

_FIXED_DECIMAL = re.compile(r"decimal\(\s*(\d+)\s*,\s*(-?\d+)\s*\)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_FIXED_DECIMAL = re.compile(r"decimal\(\s*(\d+)\s*,\s*(-?\d+)\s*\)")
_FIXED_DECIMAL_PATTERN = re.compile(r"decimal\(\s*(\d+)\s*,\s*(-?\d+)\s*\)")

Comment on lines 1362 to 1365
def test_structtype_from_json(tpe, json_dict, expected_result):
result = tpe.from_json(json_dict)
assert result == expected_result
assert isinstance(result, tpe)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we can write some round-trip tests instead of re-writing a full set.

something like

datatype = MapType(IntegerType(), StringType())
json_value = datatype.jsonValue()
assert datatype == MapType.fromJson(json_value)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i changed the test so that it is more concise

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you! looks nice.

Copy link
Contributor

@sfc-gh-aalam sfc-gh-aalam left a comment

Choose a reason for hiding this comment

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

LGTM.

@sfc-gh-aalam
Copy link
Contributor

Could you please also fill the description so future readers have more context.

@sfc-gh-yuwang sfc-gh-yuwang merged commit 53291b4 into main Nov 18, 2024
40 checks passed
@sfc-gh-yuwang sfc-gh-yuwang deleted the SNOW-1794355 branch November 18, 2024 22:08
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants