[ https://issues.apache.org/jira/browse/FLINK-7821?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16217124#comment-16217124 ]
ASF GitHub Bot commented on FLINK-7821: --------------------------------------- Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/4813#discussion_r146605323 --- Diff: docs/dev/table/tableApi.md --- @@ -985,19 +985,22 @@ Table result = in.orderBy("a.asc"); <tr> <td> - <strong>Limit</strong><br> + <strong>Offset & Fetch</strong><br> <span class="label label-primary">Batch</span> </td> <td> - <p>Similar to a SQL LIMIT clause. Limits a sorted result to a specified number of records from an offset position. Limit is technically part of the Order By operator and thus must be preceded by it.</p> + <p>Similar to the SQL OFFSET and FETCH clauses. Offset and Fetch limit the number of records returned from a sorted result. Offset and Fetch are technically part of the Order By operator and thus must be preceded by it.</p> {% highlight java %} Table in = tableEnv.fromDataSet(ds, "a, b, c"); -Table result = in.orderBy("a.asc").limit(3); // returns unlimited number of records beginning with the 4th record -{% endhighlight %} -or -{% highlight java %} -Table in = tableEnv.fromDataSet(ds, "a, b, c"); -Table result = in.orderBy("a.asc").limit(3, 5); // returns 5 records beginning with the 4th record + +// returns the first 5 records from the sorted result +Table result1 = in.orderBy("a.asc").fetch(5); + +// returns all records beginning with the 4th record from the sorted result +Table result2 = in.orderBy("a.asc").offset(3); + +// returns the first 5 records beginning with the 10th record from the sorted result --- End diff -- I think @xccui is right. An offset of 10 means that the first 10 rows are omitted from the result. Otherwise offset 1 would not offset. I'll update the docs. > Replace Table.limit() by Table.fetch() and Table.offset() > --------------------------------------------------------- > > Key: FLINK-7821 > URL: https://issues.apache.org/jira/browse/FLINK-7821 > Project: Flink > Issue Type: Improvement > Components: Table API & SQL > Affects Versions: 1.4.0 > Reporter: Fabian Hueske > Assignee: Fabian Hueske > Priority: Minor > > The Table API method limit() exists in two variants: > - {{limit(offset)}} returns all but the first {{offset}} records. > - {{limit(offset, fetch)}} returns {{fetch}} records starting from the > {{offset}}'s record. > Especially, the behavior of {{limit(offset)}} is confusing because one would > rather expect a behavior of returning the {{offset}} first records instead of > all but the {{offset}} first records. > Moreover, the only way to return the first {{x}} records is to specify a > {{0}} offset as {{limit(0, x)}}. > I propose to deprecate and replace both {{limit()}} variants by two new > methods {{Table.offset(offset)}} and {{Table.fetch(fetch)}} that can be > combined as follows: > {code} > table.orderBy(...).fetch(x) > table.orderBy(...).offset(x) > table.orderBy(...).offset(x).fetch(y) > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)