Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion proto/substrait/algebra.proto
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ message Expression {
int64 time = 17;
IntervalYearToMonth interval_year_to_month = 19;
IntervalDayToSecond interval_day_to_second = 20;
IntervalCompound interval_compound = 36;
string fixed_char = 21;
VarChar var_char = 22;
bytes fixed_binary = 23;
Expand Down Expand Up @@ -881,7 +882,21 @@ message Expression {
message IntervalDayToSecond {
int32 days = 1;
int32 seconds = 2;
int32 microseconds = 3;

// Consumers should expect either (miroseconds) to be set or (precision and subseconds) to be set
oneof precision_mode {
int32 microseconds = 3 [deprecated = true]; // use precision and subseconds below, they cover and replace microseconds.
// Sub-second precision, 0 means the value given is in seconds, 3 is milliseconds, 6 microseconds, 9 is nanoseconds. Should be used with subseconds below.
int32 precision = 4;
}

// the number of fractional seconds using 1e(-precision) units. Should only be used with precision field, not microseconds.
int64 subseconds = 5;
}

message IntervalCompound {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially this is struct<iyear, iday>. To specify it in text one would need to use the nested struct syntax. Would this be better flattened with the fields from both types included at the top level?

Copy link
Contributor

@jacques-n jacques-n Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about the JSON representation or something else? I wasn't really worried about the json representation. Felt like this more clearly communicated the nature as opposed to field copying. It's a weak preference though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both JSON and the Substrait Text format (which was what I was thinking about since it'll require implementation) would be affected. I prefer struct<iyear, iday> to the compound approach. I would also classify my preference as weak.

Copy link
Contributor

@jacques-n jacques-n Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the substrait text format might have the fields be flattened. I don't think it is critical for it to follow the same structure as the protobufs as long as lossible translation from one to the other is possible, right?

IntervalYearToMonth interval_year_to_month = 1;
IntervalDayToSecond interval_day_to_second = 2;
}

message Struct {
Expand Down
15 changes: 14 additions & 1 deletion proto/substrait/parameterized_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ message ParameterizedType {
Type.Date date = 16;
Type.Time time = 17;
Type.IntervalYear interval_year = 19;
Type.IntervalDay interval_day = 20;
ParameterizedIntervalDay interval_day = 20;
ParameterizedIntervalCompound interval_compound = 36;
// Deprecated in favor of `ParameterizedPrecisionTimestampTZ precision_timestamp_tz`
Type.TimestampTZ timestamp_tz = 29 [deprecated = true];
Type.UUID uuid = 32;
Expand Down Expand Up @@ -92,6 +93,18 @@ message ParameterizedType {
Type.Nullability nullability = 4;
}

message ParameterizedIntervalDay {
IntegerOption precision = 1;
uint32 variation_pointer = 2;
Type.Nullability nullability = 3;
}

message ParameterizedIntervalCompound {
IntegerOption precision = 1;
uint32 variation_pointer = 2;
Type.Nullability nullability = 3;
}

message ParameterizedPrecisionTimestamp {
IntegerOption precision = 1;
uint32 variation_pointer = 2;
Expand Down
15 changes: 15 additions & 0 deletions proto/substrait/type.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ message Type {
Time time = 17;
IntervalYear interval_year = 19;
IntervalDay interval_day = 20;
IntervalCompound interval_compound = 35;
// Deprecated in favor of `PrecisionTimestampTZ precision_timestamp_tz`
TimestampTZ timestamp_tz = 29 [deprecated = true];
UUID uuid = 32;
Expand Down Expand Up @@ -122,14 +123,28 @@ message Type {
Nullability nullability = 2;
}

// An interval consisting of years and months
message IntervalYear {
uint32 type_variation_reference = 1;
Nullability nullability = 2;
}

// An interval consisting of days, seconds, and microseconds
message IntervalDay {
uint32 type_variation_reference = 1;
Nullability nullability = 2;

// Sub-second precision, 0 means the value given is in seconds, 3 is milliseconds, 6 microseconds, 9 is nanoseconds, etc.
// if unset, treat as 6.
optional int32 precision = 3;
}

// An interval consisting of the components of both IntervalMonth and IntervalDay
message IntervalCompound {
uint32 type_variation_reference = 1;
Nullability nullability = 2;
// Sub-second precision, 0 means the value given is in seconds, 3 is milliseconds, 6 microseconds, 9 is nanoseconds, etc.
int32 precision = 3;
}

message UUID {
Expand Down
15 changes: 14 additions & 1 deletion proto/substrait/type_expressions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ message DerivationExpression {
Type.Date date = 16;
Type.Time time = 17;
Type.IntervalYear interval_year = 19;
Type.IntervalDay interval_day = 20;
// Deprecated in favor of `ExpressionPrecisionTimestampTZ precision_timestamp_tz`
Type.TimestampTZ timestamp_tz = 29 [deprecated = true];
Type.UUID uuid = 32;

ExpressionIntervalDay interval_day = 20;
ExpressionIntervalCompound interval_compound = 42;
ExpressionFixedChar fixed_char = 21;
ExpressionVarChar varchar = 22;
ExpressionFixedBinary fixed_binary = 23;
Expand Down Expand Up @@ -90,6 +91,18 @@ message DerivationExpression {
Type.Nullability nullability = 3;
}

message ExpressionIntervalDay {
DerivationExpression precision = 1;
uint32 variation_pointer = 2;
Type.Nullability nullability = 3;
}

message ExpressionIntervalCompound {
DerivationExpression precision = 1;
uint32 variation_pointer = 2;
Type.Nullability nullability = 3;
}

message ExpressionPrecisionTimestampTZ {
DerivationExpression precision = 1;
uint32 variation_pointer = 2;
Expand Down
1 change: 1 addition & 0 deletions site/docs/extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Rather than using a full data type representation, the input argument types (`sh
| time | time |
| interval_year | iyear |
| interval_day | iday |
| interval_compound | icompound |
| uuid | uuid |
| fixedchar&lt;N&gt; | fchar |
| varchar&lt;N&gt; | vchar |
Expand Down
3 changes: 2 additions & 1 deletion site/docs/types/type_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Simple type classes are those that don't support any form of configuration. For
| date | A date within [1000-01-01..9999-12-31]. | `int32` days since `1970-01-01`
| time | A time since the beginning of any day. Range of [0..86,399,999,999] microseconds; leap seconds need not be supported. | `int64` microseconds past midnight
| interval_year | Interval year to month. Supports a range of [-10,000..10,000] years with month precision (= [-120,000..120,000] months). Usually stored as separate integers for years and months, but only the total number of months is significant, i.e. `1y 0m` is considered equal to `0y 12m` or `1001y -12000m`. | `int32` years and `int32` months, with the added constraint that each component can never independently specify more than 10,000 years, even if the components have opposite signs (e.g. `-10000y 200000m` is **not** allowed)
| interval_day | Interval day to second. Supports a range of [-3,650,000..3,650,000] days with microsecond precision (= [-315,360,000,000,000,000..315,360,000,000,000,000] microseconds). Usually stored as separate integers for various components, but only the total number of microseconds is significant, i.e. `1d 0s` is considered equal to `0d 86400s`. | `int32` days, `int32` seconds, and `int32` microseconds, with the added constraint that each component can never independently specify more than 10,000 years, even if the components have opposite signs (e.g. `3650001d -86400s 0us` is **not** allowed)
| uuid | A universally-unique identifier composed of 128 bits. Typically presented to users in the following hexadecimal format: `c48ffa9e-64f4-44cb-ae47-152b4e60e77b`. Any 128-bit value is allowed, without specific adherence to RFC4122. | 16-byte `binary`

## Compound Types
Expand All @@ -43,6 +42,8 @@ Compound type classes are type classes that need to be configured by means of a
| MAP&lt;K, V&gt; | An unordered list of type K keys with type V values. Keys may be repeated. While the key type could be nullable, keys may not be null. | `repeated KeyValue` (in turn two `Literal`s), all key types matching K and all value types matching V
| PRECISIONTIMESTAMP&lt;P&gt; | A timestamp with fractional second precision (P, number of digits) 0 <= P <= 9. Does not include timezone information and can thus not be unambiguously mapped to a moment on the timeline without context. Similar to naive datetime in Python. | `int64` seconds, milliseconds, microseconds or nanoseconds since 1970-01-01 00:00:00.000000000 (in an unspecified timezone)
| PRECISIONTIMESTAMPTZ&lt;P&gt; | A timezone-aware timestamp, with fractional second precision (P, number of digits) 0 <= P <= 9. Similar to aware datetime in Python. | `int64` seconds, milliseconds, microseconds or nanoseconds since 1970-01-01 00:00:00.000000000 UTC
| INTERVAL_DAY&lt;P&gt; | Interval day to second. Supports a range of [-3,650,000..3,650,000] days with fractional second precision (P, number of digits) 0 <= P <= 9. Usually stored as separate integers for various components, but only the total number of fractional seconds is significant, i.e. `1d 0s` is considered equal to `0d 86400s`. | `int32` days, `int32` seconds, and `int64` fractional seconds, with the added constraint that each component can never independently specify more than 10,000 years, even if the components have opposite signs (e.g. `3650001d -86400s 0us` is **not** allowed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is a parameterised type, do we need to update all the function extensions that refer to it as interval_day to use interval_day<P> instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'm inclined to do in a follow-along once this is merged.

| INTERVAL_COMPOUND&lt;P&gt; | A compound interval type that is composed of elements of the underlying elements and rules of both interval_month and interval_day to express arbitrary durations across multiple grains. Substrait gives no definition for the conversion of values between independent grains (e.g. months to days).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

across multiple grains

What is a grain in this context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

year/month vs day/second. there are no consistent reliable translations between each.


## User-Defined Types

Expand Down