-
Notifications
You must be signed in to change notification settings - Fork 63
Initializes PType #1488
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
Initializes PType #1488
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v1 #1488 +/- ##
=====================================
Coverage ? 80.07%
Complexity ? 47
=====================================
Files ? 19
Lines ? 507
Branches ? 23
=====================================
Hits ? 406
Misses ? 88
Partials ? 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
partiql-eval/src/main/java/org/partiql/eval/value/DatumChars.java
Outdated
Show resolved
Hide resolved
partiql-eval/src/main/java/org/partiql/eval/value/DatumDecimal.java
Outdated
Show resolved
Hide resolved
partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelExclude.kt
Show resolved
Hide resolved
@@ -130,7 +130,7 @@ internal class ExprCallDynamic( | |||
|
|||
init { | |||
val lookupsMutable = mutableListOf<CandidateIndex>() | |||
val accumulator = mutableListOf<Pair<List<PartiQLValueType>, Candidate>>() | |||
val accumulator = mutableListOf<Pair<List<PType>, Candidate>>() |
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.
Interesting, why not the enum? We now could have different accumulators for different types even though this is not how the candidate resolution works.
char(3)
and char(4)
would not be different accumulators, but they might be backed by a candidate with signature foo(<string>)
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.
ACK -- currently the function definitions have PType as the parameter types. Once this is changed (I know you're actively working on this), this can be changed accordingly.
@@ -14,7 +13,7 @@ internal class ExprCoalesce( | |||
override fun eval(env: Environment): Datum { | |||
for (arg in args) { | |||
val result = arg.eval(env) | |||
if (!result.isNull && result.type != PartiQLValueType.MISSING) { | |||
if (!result.isNull && !result.isMissing) { |
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.
Perhaps we have an isAbsent
now.
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.
As this PR is specific to PType, I'll defer this addition until later if you agree.
Adds experimental, deprecation notices Updates Datum implementations
Updates factory method to creat PType.Kind.CHAR
I've made a few updates since the first revision including:
I've also created an issue to track items discussed offline: #1489. This issue should not block this merge. |
// 2. Discard functions that cannot be matched (via implicit coercion or exact matches) | ||
var matches = match(candidates, args).ifEmpty { return null } | ||
if (matches.size == 1) { | ||
return matches.first().match | ||
} | ||
|
||
// Order based on original candidate function ordering | ||
val orderedUniqueMatches = matches.toSet().toList() | ||
val orderedCandidates = candidates.flatMap { candidate -> | ||
orderedUniqueMatches.filter { it.signature == candidate } | ||
// 3. Run through all candidates and keep those with the most exact matches on input types. | ||
matches = matchOn(matches) { it.numberOfExactInputTypes } | ||
if (matches.size == 1) { | ||
return matches.first().match | ||
} |
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.
nit, but this should be one loop. out-of-scope for the PR
when (toCompare(candidate).compareTo(mostExactMatches)) { | ||
-1 -> continue | ||
0 -> matches.add(candidate) | ||
1 -> { | ||
mostExactMatches = toCompare(candidate) | ||
matches.clear() | ||
matches.add(candidate) | ||
} | ||
else -> error("CompareTo should never return outside of range [-1, 1]") |
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.
nit, but we could just have
val n = toCompare(candidate).compareTo(mostExactMatches)
when {
n < 0 -> continue
n == 0 -> ...
n > 0 -> ...
}
to eliminate the need for an else
/** | ||
* This is largely just to show that the planner does not need to use [_delegate] ([PType]) directly. Using an | ||
* internal representation, we can leverage the APIs of [PType] while carrying some additional information such | ||
* as [isMissingValue]. |
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.
This is what I was trying to get at with a PartiQLType (public) -> PType (internal)
thing with a higher class hierarchy, but a fat internal. To be experimented with..
Description
Other Changes
Coercions.kt
. This uses the rules directly from SQL:1999 Section 4.12 and is extended to include PartiQL structs, bags, lists, and s-expressions.V1
? Frommain
?BINARY
,BYTE
, andINTERVAL
. This is not supported inmain
and it is not in SQL:1999. Therefore, it has been left out of this PR.NULL
orMISSING
type. Please see the applicable design document for guidance on this topic.CompilerType
. This is an IR that wraps the underlying PType while retaining information such asisNullValue
andisMissingValue
to denote that these expressions will always return null/missing.UNKNOWN
type, we can now defer typing of literal null and missing values. You will see this withDynamicTyper
which now returns a list of both coercions and replacement expressions. The replacements are specifically to convert "unknown" typed null and missing literals to typed null and missing literals.1 + NULL
this used to get compiled to<int32> + <any>
=<any>
resulting in a dynamic call (with all possible plus implementations to be dynamically invoked). This is not only computationally expensive, but it also cedes the right to type our literal nulls and resolve to a single static function. Hence, our plan would look like:Call.Dynamic(Candidates = [ Call.Static("PLUS", Lit.Int32(1), Cast(Lit.Null(), INT32)), ... ] )
<int32> + <unknown>
. Using PostgreSQL's function resolution logic, this would get further typed to:<int32> + <int32>
=<int32>
. The plan would look something like:Call.Static("PLUS", Lit.Int32(1), Lit.Int32.Null())
Reviewing
org.partiql.types.PType
(Java)org.partiql.eval.value.Datum
(Java)org.partiql.spi.connector.ConnectorObject
(Kotlin)In general, I'd look at the
.api
files to understand how these interfaces will be used by the public.I'd also take a keen eye to the testing. See the
Testing
section below.Testing
PType.fromStaticType
which is used extensively in testing. ForAnyOf
types, one should be aware that this is typed asDYNAMIC
. "You can't escape dynamic."1 + <dynamic>
=<dynamic>
. This is different from our previous implementation which would compute all possible permutations of the types and union the resulting type. Reviewers will notice, however, that the tests haven't changed very much. This is due to the above bullet point. A union of two types is implicitly the dynamic type and therefore the tests have not needed to be modified much.User Experience Impact
PType
fat interface. This enforces the use of our own type semantics without using the overhead of Java types.PType
for user-guidance.Future Changes
The following items should be addressed further before release of V1.0:
type
rather thanstatic_type
.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.