You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@livy.apache.org by gg...@apache.org on 2023/04/11 12:14:38 UTC

[incubator-livy] branch master updated: [LIVY-970][SERVER] Ordering and pagination support in GET /statement (#389)

This is an automated email from the ASF dual-hosted git repository.

ggal pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-livy.git


The following commit(s) were added to refs/heads/master by this push:
     new e4c2676c [LIVY-970][SERVER] Ordering and pagination support in GET /statement (#389)
e4c2676c is described below

commit e4c2676c161edf585bf9bb543a9277aaf92283a5
Author: Asif Khatri <12...@users.noreply.github.com>
AuthorDate: Tue Apr 11 17:44:33 2023 +0530

    [LIVY-970][SERVER] Ordering and pagination support in GET /statement (#389)
    
    ## What changes were proposed in this pull request?
    
    GET /sessions/id/statements returns a list of statements run in a session. However the ordering of the statements are older ones first. Livy could expose a parameter (something like orderBy=latest) that will order the list of statements as latest first.
    JIRA: https://issues.apache.org/jira/browse/LIVY-970
    
    ## How was this patch tested?
    
    Verified manually by creating interactive session and statements via REST API call in a local Yarn cluster.
---
 docs/rest-api.md                                    | 21 +++++++++++++++++++++
 .../interactive/InteractiveSessionServlet.scala     |  7 ++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/docs/rest-api.md b/docs/rest-api.md
index 342bd59a..903bb5b2 100644
--- a/docs/rest-api.md
+++ b/docs/rest-api.md
@@ -251,6 +251,27 @@ Gets the log lines from this session.
 
 Returns all the statements in a session.
 
+#### Request Parameters
+
+<table class="table">
+  <tr><th>Name</th><th>Description</th><th>Type</th></tr>
+  <tr>
+    <td>from</td>
+    <td>The start index to fetch sessions</td>
+    <td>int</td>
+  </tr>
+  <tr>
+    <td>size</td>
+    <td>Number of sessions to fetch</td>
+    <td>int</td>
+  </tr>
+  <tr>
+    <td>order</td>
+    <td>Provide value as "desc" to get statements in descending order (By default, the list is in ascending order)</td>
+    <td>string</td>
+  </tr>
+</table>
+
 #### Response Body
 
 <table class="table">
diff --git a/server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala b/server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala
index 4440c775..85407b04 100644
--- a/server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala
+++ b/server/src/main/scala/org/apache/livy/server/interactive/InteractiveSessionServlet.scala
@@ -113,7 +113,12 @@ class InteractiveSessionServlet(
 
   get("/:id/statements") {
     withViewAccessSession { session =>
-      val statements = session.statements
+      val order = params.get("order")
+      val statements = if (order.map(_.trim).exists(_.equalsIgnoreCase("desc"))) {
+        session.statements.reverse
+      } else {
+        session.statements
+      }
       val from = params.get("from").map(_.toInt).getOrElse(0)
       val size = params.get("size").map(_.toInt).getOrElse(statements.length)