-
Notifications
You must be signed in to change notification settings - Fork 63
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 Datum and adds functionality to evaluator #1451
Conversation
4ab73d6
to
eee755f
Compare
5d9957f
to
d25de2d
Compare
d25de2d
to
d201667
Compare
class CharValue implements PQLValue { | ||
|
||
@NotNull | ||
final String _value; |
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.
final String _value; | |
final char _value; |
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.
The character data type in SQL doesn't represent the char in Java. It's more like a char array
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.
Oh the fixed-length character. In my head I had
char <-> char(1) -- fixed-length character with length 1
partiql-eval/src/main/java/org/partiql/eval/DecimalArbitraryValue.java
Outdated
Show resolved
Hide resolved
@NotNull | ||
static PQLValue nullValue(@NotNull PartiQLValueType type) { | ||
return new NullValue(type); | ||
} |
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.
Hmm I'm not sure about typed nulls if we are going ahead and changing the value system.
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.
In order to pass existing tests, this is necessary. I can mark it as deprecated, but for this PR I'd like to avoid removing PartiQLValueType.NULL as it touches many things
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.
See PR #1463. This will have a pretty significant impact on this comment.
/** | ||
* Represents the key-value pairs that are embedded within values of type {@link org.partiql.value.PartiQLValueType#STRUCT}. | ||
*/ | ||
public interface StructField { |
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.
Why an interface?
Struct fields should have just two values,
- name -> field name original casing
- value -> field value
We should also consider private, but non-final field members
partiql-eval/src/main/kotlin/org/partiql/eval/internal/Compiler.kt
Outdated
Show resolved
Hide resolved
@OptIn(PartiQLValueExperimental::class) | ||
fun PQLValue.getInt32Coerced(): Int { | ||
return when (this.type) { | ||
PartiQLValueType.INT8 -> this.int8Value.toInt() | ||
PartiQLValueType.INT16 -> this.int16Value.toInt() | ||
PartiQLValueType.INT32 -> this.int32Value | ||
PartiQLValueType.INT64 -> this.int64Value.toInt() | ||
PartiQLValueType.INT -> this.intValue.toInt() | ||
else -> throw TypeCheckException() | ||
} | ||
} |
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.
I suggest adding all of these coerces to the PQLValue implementations.
class Int32Value ... {
private Int value;
@Override
short toShort() {
// throw DataException on overflow etc.
return value as short;
}
@Override
int getInt() { return value };
@Override
long getLong() { return value };
}
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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v1 #1451 +/- ##
=====================================
Coverage ? 72.30%
Complexity ? 2539
=====================================
Files ? 283
Lines ? 20282
Branches ? 3700
=====================================
Hits ? 14664
Misses ? 4596
Partials ? 1022
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
/** | ||
* This shall always be package-private (internal). | ||
*/ | ||
class DecimalArbitraryValue implements PQLValue { |
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.
I don't think we need both Decimal and DecimalArbitrary for runtime values.
class Float32Value implements PQLValue { | ||
|
||
private final float _value; | ||
|
||
Float32Value(float value) { | ||
_value = value; | ||
} | ||
|
||
@Override | ||
public boolean isNull() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public float getFloat() { | ||
return _value; | ||
} | ||
|
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 starting to look exactly like PartiQLValue just in Java and with the getFloat()
.. getLong()
etc. I have a couple of questions.
- What's the difference now? (besides flat class hierarchy)
- Why don't we have the coercions in the PQLValue? (in this case
getDouble()
)
Perhaps its been too long since I looked, but I don't think I understand the value prop here.
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.
Yes, this PR aims to replace PartiQLValue incrementally. I'd suggest:
- Add PQLValue without releasing.
- Update functions to use PQLValue. (subsequent PR)
- Move the existing PartiQLValue to the plan package (maybe called PlanLiteral) (since it's use is more for the DOM)
- Rename PQLValue to PartiQLValue
The difference is that we are moving away from using Java's type semantics in favor of our own type system. With this, we can/should be using our own type information to determine how to extract the underlying data. The idea is that this logic should be exposed by partiql-eval
instead of partiql-types
.
There shouldn't be a need for coercions that are not represented in the plan. What I'd like to see is that when the executor receives a plan, without any modification, the executor shall execute the plan. If a JVM double is expected, then the planner should have inserted the appropriate coercion.
Consider Rex.Op.Path.Index
. The planner currently allows all integer types as the index, and then the executor is actually under the hood coercing any integer value into a JVM int. In my opinion, the "function signature" of the path index should have required that the index be a PartiQL int_32. With this mindset, the expressions representing the index (say its typed to be an INT16) would be wrapped with a coercion by the planner. We're currently making up for our lack of planning by adding all of these additional coercions in the execution.
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.
Discussed other points offline to create more distance from DOM.
There shouldn't be a need for coercions that are not represented in the plan. What I'd like to see is that when the executor receives a plan, without any modification, the executor shall execute the plan. If a JVM double is expected, then the planner should have inserted the appropriate coercion.
Agreed, makes sense now. Thank you.
* - The comparator for ordering and aggregations | ||
* - Adding support for annotations | ||
*/ | ||
public interface PQLValue extends Iterable<PQLValue> { |
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.
I don't think it should be public if it's not a replacement. I also thought we discussed them solving different problems?
We shouldn't introduce another duplication of something existing when PartiQLValue is still under experimental. We either replace it completely or change it however we need to.
* @return the underlying value applicable to the types: | ||
* {@link PartiQLValueType#INT32} | ||
* @throws UnsupportedOperationException if the operation is not applicable to the type returned from |
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.
I'm confused why coercions wouldn't fit like Int16Value
/** | ||
* This shall always be package-private (internal). | ||
*/ | ||
class BagValue implements PQLValue { |
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.
I don't think we need Bag/List/Sexp classes if we have a type enum. Because this is always internal, we can add additional classes later, but it doesn't provide additional value. Same for Decimal/DecimalArbitrary.
/** | ||
* This shall always be package-private (internal). | ||
*/ | ||
class CharValue implements PQLValue { |
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.
Similar comment, but seems we don't need Char and String considering their identical implementations.
/** | ||
* This shall always be package-private (internal). | ||
*/ | ||
class ClobValue implements PQLValue { |
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.
Clob/Blob -> ByteArray or Lob
Updates all implementing classes of Datum
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.
Only change is to fix the test/partiql-tests submodule otherwise ship it.
internal class RecordValueIterator( | ||
collectionValue: CollectionValue<*> | ||
collectionValue: Iterator<Datum> | ||
) : Iterator<Record> { | ||
|
||
private val collectionIter = collectionValue.iterator() |
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 now we can have private val iterator: Iterator<Dataum>
I believe there is a bug in GitHub's rendering of the submodule diff. For some reason, the commit is the same on |
Relevant Issues
Description
x is StructValue<*>
) rather than relying on our plumbing: (x.type == PartiQLValueType.STRUCT
). On top of that, as part of the JOIN PR, I found it incredibly difficult (and sub-optimal performance-wise) to coerce nulls of a particular type to a null of another type. This PR takes these learnings and completely overhaulsPartiQLValue
to a representation that we are all familiar with: Ion'sAnyElement
. In a way, this modelling is as close as we can get to C's Union type, and by modelling it this way, we gain control over our type system.PQLValue
. I intend for its core to be copied and pasted directly intoPartiQLValue
. I have also written this in Java, as I've noticed our inability to control our public API by writing in Kotlin. On top of that,PQLValue
is written in Java to get us closer to using primitives directly. That being said,PQLValue
will NOT exist during theV1
release. Its contents will replace the contents ofPartiQLValue
-- andPartiQLValue
will be written in Java.Internal Notes
@NotNull
.PQLValue
. These include adding the comparator, equals, hashCode, etc. These should be able to be added fairly quickly.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.