Skip to content

Commit 9074ce4

Browse files
committed
split with tie and sorts such that effectively capturing (ORDER BY)? (OFFSET)? FETCH (WITH TIES)? semantic
1 parent d79e6c3 commit 9074ce4

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

proto/substrait/algebra.proto

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,17 @@ message FetchRel {
320320
Expression count_expr = 6;
321321
}
322322

323-
// If specified, returns extra rows if they have the same sort column values
324-
// as the last row specified by `count_mode`.
325-
// The result of the Rel is guaranteed to be in the order of `WithTies.sorts`.
326-
WithTies with_ties = 7;
327-
328-
message WithTies {
329-
// The sort order to consider to evaluate tie.
330-
repeated SortField sorts = 1;
331-
}
323+
// List of fields to sort by to retrieve the number of records specified by `count_mode`.
324+
// At least one filed MUST be specified when `with_ties` is true.
325+
//
326+
// Note: the output records are in the order of `sorts` if at least one sort field is specified.
327+
// Otherwise, the input orderedness is assumed.
328+
repeated SortField sorts = 7;
329+
330+
// Whether to yields 'tie' records of the last record specified by `count_mode`.
331+
// Tie is determined by the `sorts` order (i.e., `sorts` field values are the same if records are 'tie').
332+
// If set to true, `sorts` MUST specify at least one sort field.
333+
bool with_ties = 8;
332334

333335
substrait.extensions.AdvancedExtension advanced_extension = 10;
334336
}

site/docs/relations/logical_relations.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,24 @@ The output type is as follows for the various operations
341341

342342
## Fetch Operation
343343

344-
The fetch operation eliminates records outside a desired window. Typically corresponds to a fetch/offset SQL clause. Will only returns records between the start offset and the end offset.
344+
The fetch operation eliminates records outside a desired window. Typically corresponds to an fetch/offset SQL clause. Will only returns records between the start offset and the end offset.
345345

346346
| Signature | Value |
347347
| -------------------- | --------------------------------------- |
348348
| Inputs | 1 |
349349
| Outputs | 1 |
350-
| Property Maintenance | Maintains distribution and orderedness. |
350+
| Property Maintenance | Maintains input distribution. Orderedness is `Sort Fields` if specified. Otherwise, input orderedness. |
351351
| Direct Output Order | Unchanged from input. |
352352

353353
### Fetch Properties
354354

355355
| Property | Description | Required |
356356
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- |
357-
| Input | A relational input, typically with a desired orderedness property. | Required |
357+
| Input | A relational input. | Required |
358358
| Offset Expression | An expression which evaluates to a non-negative integer or null (recommended type is `i64`). Declares the offset for retrieval of records. An expression evaluating to null is treated as 0. | Optional, defaults to a 0 literal. |
359359
| Count Expression | An expression which evaluates to a non-negative integer or null (recommended type is `i64`). Declares the number of records that should be returned. An expression evaluating to null indicates that all records should be returned. | Optional, defaults to a null literal. |
360+
| Sort Fields | List of one or more sort fields to define a desired window. Requires at least one sort field if 'With Ties' is true. | Optional, defaults to empty sort fields. |
361+
| With Ties | Whether to return tie rows of the last row specified by 'Count Expression'. If false, at most 'Count Expression' records are returned. If true, it may yield more recrods than 'Count Expression'. | Optional, defaults to false. |
360362

361363
=== "FetchRel Message"
362364

0 commit comments

Comments
 (0)