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

Improve the error message for STRUCT to STRUCT casts #10508

Closed

Conversation

taniabogatsch
Copy link
Contributor

See #10486.

We should also update this in our documentation. I think rewriting the code to support rearranging the child vectors is not necessary?

CREATE TABLE t1 (s STRUCT(str STRING, i INT));
CREATE TABLE t2 (s STRUCT(i INT, str STRING));
INSERT INTO t1 SELECT {'str': 'hello', 'i': 42};
INSERT INTO t2 SELECT {'i': t1.s.i, 'str': t1.s.str} FROM t1;
FROM t1;
┌────────────────────────────────┐
│               s                │
│ struct(str varchar, i integer) │
├────────────────────────────────┤
│ {'str': hello, 'i': 42}        │
└────────────────────────────────┘
FROM t2;
┌────────────────────────────────┐
│               s                │
│ struct(i integer, str varchar) │
├────────────────────────────────┤
│ {'i': 42, 'str': hello}        │
└────────────────────────────────┘

@plaflamme
Copy link

FWIW: this came up while doing something like

df = pd.DataFrame([{"s":{"a": "foo", "b": 42}}]) # some dataframe with a struct
con.query("INSERT INTO t1 SELECT * FROM df")

(In my particular case, df came from BigQuery, e.g.: df = job.to_dataframe())

In this case, it's not always possible to control the order of the struct members. When the struct is backed by pyarrow, then I believe this is possible, but when it's a python object, I'm unsure it is possible to have a strict / consistent / predictable ordering.

@Mytherin
Copy link
Collaborator

Mytherin commented Feb 8, 2024

Superseded by #10537

@Mytherin Mytherin closed this Feb 8, 2024
@taniabogatsch taniabogatsch deleted the struct-cast-improve-err-msg branch February 9, 2024 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Documentation Use for issues or PRs that require changes in the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants