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 SQL ArrayType / CustomType failure mode #5445

Merged
merged 3 commits into from
May 2, 2024

Conversation

devinrsmith
Copy link
Member

@devinrsmith devinrsmith commented May 1, 2024

The following code block now successfully runs. A couple of failure modes are indicated when a "bad" column type is used in an invalid way. In some cases Calcite will notice the issue, and other times, it will pass the query to the engine where it might fail.

from deephaven.experimental import sql
from deephaven import empty_table

a = {}
t1 = empty_table(4).view(["I=ii"])
t2 = t1.update("A = a")

# equivalent to t1_all = t1
t1_all = sql.evaluate('SELECT * FROM t1')

# equivalent to t2_all = t2
t2_all = sql.evaluate('SELECT * FROM t2')

# org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply '+' to arguments of type '<JAVATYPE(CLASS IO.DEEPHAVEN.SQL.TYPEADAPTER$SQLTODOCUSTOMTYPE)> + <INTEGER>'. Supported form(s): '<NUMERIC> + <NUMERIC>'
# '<DATETIME_INTERVAL> + <DATETIME_INTERVAL>'
# '<DATETIME> + <DATETIME_INTERVAL>'
# '<DATETIME_INTERVAL> + <DATETIME>'
# 	at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
# 	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
#	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
#	at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:507)
#	at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:601)
#	... 53 more
#t2_bad_op = sql.evaluate('SELECT A + 1 FROM t2')

# Requirement failed: required Comparable.class.isAssignableFrom(sortColumns[ii].getType()) || sortColumns[ii].getType().isPrimitive(), instead sortColumnNames[ii] == "A", sortColumns[ii].getType() == class org.jpy.PyDictWrapper.
#	at io.deephaven.base.verify.Require.fail(Require.java:108)
#	at io.deephaven.base.verify.Require.requirement(Require.java:169)
#	at io.deephaven.base.verify.Require.requirement(Require.java:175)
#	at io.deephaven.engine.table.impl.SortOperation.<init>(SortOperation.java:69)
#t2_engine_sort = sql.evaluate('SELECT A FROM t2 ORDER BY A')

Fixes #5443

The following code block now successfully runs. A couple of failure modes are indicated when a "bad" column type is used in an invalid way. In some cases Calcite will notice the issue, and other tim
es, it will pass the query to the engine where it might fail.

```python
from deephaven.experimental import sql
from deephaven import empty_table

a = {}
t1 = empty_table(4).view(["I=ii"])
t2 = t1.update("A = a")

# equivalent to t1_all = t1
t1_all = sql.evaluate('SELECT * FROM t1')

# equivalent to t2_all = t2
t2_all = sql.evaluate('SELECT * FROM t2')

# org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply '+' to arguments of type '<JAVATYPE(CLASS IO.DEEPHAVEN.SQL.TYPEADAPTER$SQLTODOCUSTOMTYPE)> + <INTEGER>'. Supported form(s): '<NUMERIC> + <NUMERIC>'
# '<DATETIME_INTERVAL> + <DATETIME_INTERVAL>'
# '<DATETIME> + <DATETIME_INTERVAL>'
# '<DATETIME_INTERVAL> + <DATETIME>'
# 	at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
# 	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
#	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
#	at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:507)
#	at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:601)
#	... 53 more
#t2_bad_op = sql.evaluate('SELECT A + 1 FROM t2')

# Requirement failed: required Comparable.class.isAssignableFrom(sortColumns[ii].getType()) || sortColumns[ii].getType().isPrimitive(), instead sortColumnNames[ii] == "A", sortColumns[ii].getType() == class org.jpy.PyDictWrapper.
#	at io.deephaven.base.verify.Require.fail(Require.java:108)
#	at io.deephaven.base.verify.Require.requirement(Require.java:169)
#	at io.deephaven.base.verify.Require.requirement(Require.java:175)
#	at io.deephaven.engine.table.impl.SortOperation.<init>(SortOperation.java:69)
#t2_engine_sort = sql.evaluate('SELECT A FROM t2 ORDER BY A')
```

Fixes deephaven#5443
@devinrsmith devinrsmith added this to the 2. April 2024 milestone May 1, 2024
@devinrsmith devinrsmith requested a review from niloc132 May 1, 2024 23:44
@devinrsmith devinrsmith self-assigned this May 1, 2024
@rcaudy rcaudy merged commit 78d454e into deephaven:main May 2, 2024
15 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL can't evaluate statement if any unrelated table in scope is incompatible
3 participants