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

[CALCITE-6275] Parser for data types ignores element nullability in collections #3698

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mihaibudiu
Copy link
Contributor

@mihaibudiu mihaibudiu commented Feb 21, 2024

This modifies the parser to accept types such as INTEGER NOT NULL ARRAY NULL for column types.
The only thing I don't like too much about this PR is the fact that this type is unparsed differently depending on where it appears:

  • in a column definition it is unparsed as INTEGER NOT NULL ARRAY
  • in a CAST it is unparsed as INTEGER ARRAY (the type can appear in a cast due to type coercion, so this is a legal use case)

These two not the same type at all, but other databases, such as Postgres, also do not accept types with nullabilities in casts. Maybe that's a bug in Postgres as well, or maybe in the SQL handling of collection types in general?

In order to provide this behavior I had to add some state to the SqlWriter which indicates the context where a type is being unparsed. Fortunately, types cannot contain other kinds of SqlNodes - e.g., expressions - so a stack of context is not necessary, a scalar will do.

…ollections

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
Copy link

sonarcloud bot commented Feb 21, 2024

.ok("CREATE TABLE `X` ("
+ "`A` INTEGER ARRAY, "
+ "`B` INTEGER ARRAY NOT NULL, "
+ "`C` INTEGER NOT NULL ARRAY, "
Copy link
Contributor

Choose a reason for hiding this comment

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

Is INTEGER NOT NULL ARRAYsupported in Postgresql?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, it does not seem to be supported.
I will discuss this topic in the JIRA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants