-
Notifications
You must be signed in to change notification settings - Fork 62
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
Adds IS predicate as special operator #1520
Conversation
Conformance comparison report-Cross Engine
Number failing in both: 180 Number passing in legacy engine but fail in eval engine: 275 Number failing in legacy engine but pass in eval engine: 261 Conformance comparison report-Cross Commit-LEGACY
Number failing in both: 441 Number passing in Base (73db367) but now fail: 0 Number failing in Base (73db367) but now pass: 0 Conformance comparison report-Cross Commit-EVAL
Number failing in both: 455 Number passing in Base (73db367) but now fail: 1 Number failing in Base (73db367) but now pass: 3 Click here to see
Click here to see
|
if (v.isNull) { | ||
return nil | ||
} | ||
val r = when (type.kind) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val r = when (type.kind) { | |
return Datum.bool(v.type == type) |
I almost feel that <expr> IS <type>
is useful for evaluating the exact runtime type in the gradual typing use-case. For example:
CREATE FUNCTION foo(a INT, b INT)
RETURNS DECIMAL
SPECIFIC foo_1
RETURN ...;
CREATE FUNCTION foo(a SMALLINT, b STRING)
RETURNS FLOAT
SPECIFIC foo_2
RETURN ...;
SELECT
CASE
WHEN intValue IS INT THEN foo(intValue, 5)
WHEN intValue IS SMALLINT THEN foo(intValue, 'hello')
END
FROM tbl AS t
LET t.a AS intValue
Let's assume that the static type of tbl
is DYNAMIC
. At runtime, let's assume that t.a
is of type SMALLINT
. According to the logic below, SMALLINT
still passes the IS INT
predicate. Therefore foo_1
will be invoked. I feel as if foo_2
should have been invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some examples where this suggestion may not work.
- Checking if we can cast.
WHEN x IS INT CAST(x AS INT) ELSE 0
- The suggestion doesn't align with our conformance tests, perhaps decimals are an exception?
0.001 is DECIMAL(3,3) -- left-hand-side is typed as an arbitrary decimal today
In your example all decimal parameters would be ignored so we can't do that — the rules for decimal type checking should align with integer. Aka IS -> true when the exact numeric type has precision less-than-or-equal-to the given type.
- But then all parameterized things will be special cases.
-- this implementation
"abc" IS CHAR -- > false
"abc" IS CHAR(1) -- > false
"abc" IS CHAR(3) -- > true
-- suggestion
"abc" IS CHAR -- > true
"abc" IS CHAR(1) -- > true?
"abc" IS CHAR(3) -- > true
The same logic applies to all parameterized things - why not use the parameters?
- Perhaps IS cannot take parameters only kinds, but then it doesn't align with your exact runtime type checking.
You wouldn't be able to check any decimals, chars/varchar lengths, etc.
60d24b7
to
084c49f
Compare
Description
The IS Predicate is a pair of value (NULL and MISSING) predicates and a type check predicate which encapsulate the SQL and with the necessary generalization for semi-structured data.
Syntax
Notes
Questions?
Other Information
and Code Style Guidelines? YES
License Information
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.