Skip to content

docs: Add documentation for supported casts with complex types - #2760

Closed
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:cast-complex-types
Closed

andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:cast-complex-types

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #2743

Rationale for this change

What changes are included in this PR?

How are these changes tested?

#### Struct Type Casting

- **Struct to Struct**: Structs can be cast to other struct types if all field types are compatible.
- Requires the same number of fields in source and target structs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not quite correct!

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.

Thanks @martin-g appreciate if you can provide an example. so it would be more clear for the user and we can also track this in the issue as future work

- Recursively checks that the array element type supports casting to string
- Example: `CAST(array(1, 2, 3) AS STRING)` → `"[1, 2, 3]"`

- **Array to Array**: Arrays can be cast to other array types if the element types are compatible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are no tests for this.

test("cast ArrayType to StringType") {

cast ArrayType to StringType seems to be the only cast ArrayType to ... test in the suite

- Example: `CAST(array(1, 2, 3) AS ARRAY<BIGINT>)` → `array(1L, 2L, 3L)`
- The compatibility level (Compatible/Incompatible/Unsupported) is determined by the element type cast

- **Special case**: Arrays with `NullType` elements (empty arrays) can be cast to any array type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it correct to say empty arrays here ?

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.

Agree with @martin-g

array(null) and array() are not quite the same

@comphead comphead left a comment

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.

This is supergreat @andygrove
The nice follow up would be adding examples what is not supported

@andygrove

Copy link
Copy Markdown
Member Author

Thanks for reviews @martin-g and @comphead. Let's address this for 0.13 since we are out of time for the 0.12 release. I filed #2766 for addressing the gaps in testing.

I'll close this PR and we can create a new one once the tests are in place.

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.

Add documentation for cast support for complex types

3 participants