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

Fix null input in map_keys/values #14401

Merged
merged 3 commits into from
Feb 3, 2025

Conversation

cht42
Copy link
Contributor

@cht42 cht42 commented Feb 1, 2025

Which issue does this PR close?

Closes #14400.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

)))
}

#[cfg(test)]
mod test {
Copy link
Contributor Author

@cht42 cht42 Feb 1, 2025

Choose a reason for hiding this comment

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

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 you can test it using slt with this trick (create a column with non null value and then insert a NULL into it)

DataFusion CLI v44.0.0
> create table foo as values (MAP {'foo': 'bar'});
0 row(s) fetched.
Elapsed 0.037 seconds.

> insert into foo values (NULL);
+-------+
| count |
+-------+
| 1     |
+-------+
1 row(s) fetched.
Elapsed 0.016 seconds.

> select * from foo;
+------------+
| column1    |
+------------+
| {foo: bar} |
| NULL       |
+------------+
2 row(s) fetched.
Elapsed 0.004 seconds.

> select column1, arrow_typeof(column1) from foo;
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| column1    | arrow_typeof(foo.column1)                                                                                                                                                                                                                                                                                                                            |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {foo: bar} | Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false) |
| NULL       | Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false) |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 row(s) fetched.
Elapsed 0.006 seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sweet, will update

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you very much @cht42 -- this makes sense to me 🙏

I think it would be really nice to update the tests to use slt (I left a suggestion on how to do so ) but not strictly required.

)))
}

#[cfg(test)]
mod test {
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 you can test it using slt with this trick (create a column with non null value and then insert a NULL into it)

DataFusion CLI v44.0.0
> create table foo as values (MAP {'foo': 'bar'});
0 row(s) fetched.
Elapsed 0.037 seconds.

> insert into foo values (NULL);
+-------+
| count |
+-------+
| 1     |
+-------+
1 row(s) fetched.
Elapsed 0.016 seconds.

> select * from foo;
+------------+
| column1    |
+------------+
| {foo: bar} |
| NULL       |
+------------+
2 row(s) fetched.
Elapsed 0.004 seconds.

> select column1, arrow_typeof(column1) from foo;
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| column1    | arrow_typeof(foo.column1)                                                                                                                                                                                                                                                                                                                            |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {foo: bar} | Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false) |
| NULL       | Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false) |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 row(s) fetched.
Elapsed 0.006 seconds.

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Feb 3, 2025
Copy link
Member

@xudong963 xudong963 left a comment

Choose a reason for hiding this comment

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

Thanks @cht42

@xudong963 xudong963 merged commit f5388f7 into apache:main Feb 3, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return null for null maps in map_keys and map_values
3 participants