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

Typing error for NULLIF #1240

Open
RCHowell opened this issue Oct 5, 2023 · 1 comment
Open

Typing error for NULLIF #1240

RCHowell opened this issue Oct 5, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@RCHowell
Copy link
Contributor

RCHowell commented Oct 5, 2023

Description

To Reproduce

SELECT NULLIF(NULL,'') IS NULL AS a, NULLIF(NULL,'') IS NOT NULL AS b FROM <<{'a': 1}>>
[-1:-1:<unknown>: Expression always returns null or missing., -1:-1:<unknown>: Expression always returns null or missing.]
java.lang.AssertionError: [-1:-1:<unknown>: Expression always returns null or missing., -1:-1:<unknown>: Expression always returns null or missing.]
    at org.partiql.lang.planner.transforms.PartiQLSchemaInferencerTests.runTest(PartiQLSchemaInferencerTests.kt:2831)
    at org.partiql.lang.planner.transforms.PartiQLSchemaInferencerTests.runTest(PartiQLSchemaInferencerTests.kt:2792)
    at org.partiql.lang.planner.transforms.PartiQLSchemaInferencerTests.test(PartiQLSchemaInferencerTests.kt:141)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
.....

Expected Behavior

This is not an erroneous query and we should not fail here.

Additional Context

  • Java version:.
  • PartiQL version: 0.13.2
  • Add any other context about the problem here.
@RCHowell RCHowell added the bug Something isn't working label Oct 5, 2023
@johnedquinn
Copy link
Member

johnedquinn commented Oct 5, 2023

We were actually just discussing this a few days ago. Since NULLIF essentially uses EQ internally to check equality of the operands, we can look at the PartiQL Specification for guidance:

Equality never fails in the type-checking mode and never returns MISSING in the permissive mode. Instead, it can
compare values of any two types, according to the rules of the PartiQL type system.

If the error is being thrown due to the comparison of NULL and '', then I believe we're being too haste in throwing an error. Should be an INFO message -- not a WARNING or ERROR. Therefore, the issue is valid. In the first projection (NULLIF(NULL,'')), it really has the logic of:

CASE WHEN NULL = '' THEN NULL ELSE NULL END

If it is due to NULLIF always returning NULL, then we can look further into PartiQL's specification:

In a more important and common case, an PartiQL implementation can
utilize the input data schema to prove that a path expression always returns MISSING and thus throw a compile-time
error.

While this specifically gives the example of "path expression", the PartiQL team has interpreted this excerpt to say:

In a more important and common case, a PartiQL implementation can
utilize the input data schema to prove that an expression always returns MISSING and thus throw a compile-time error.

That being said, this only relates to MISSING and, seemingly, not NULL.

So, yeah, I believe this is a bug. Needs more research into where exactly it's being thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants