You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2022/07/25 14:12:08 UTC

[incubator-streampipes] branch STREAMPIPES-545 updated: [hotfix] Add order by and limit option to data lake query builder

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

zehnder pushed a commit to branch STREAMPIPES-545
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/STREAMPIPES-545 by this push:
     new 487f31fa2 [hotfix] Add order by and limit option to data lake query builder
487f31fa2 is described below

commit 487f31fa2d39d97c2b3b7cdd01aa6d8ea48dbc36
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Mon Jul 25 16:11:39 2022 +0200

    [hotfix] Add order by and limit option to data lake query builder
---
 .../dataexplorer/sdk/DataLakeQueryBuilder.java     | 37 ++++++++++++++++++++--
 .../dataexplorer/sdk/DataLakeQueryConstants.java   |  1 +
 .../dataexplorer/sdk/DataLakeQueryOrdering.java    |  5 +++
 3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryBuilder.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryBuilder.java
index ef1d50544..3dcf993d5 100644
--- a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryBuilder.java
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryBuilder.java
@@ -20,7 +20,9 @@ package org.apache.streampipes.dataexplorer.sdk;
 
 import org.apache.streampipes.config.backend.BackendConfig;
 import org.apache.streampipes.dataexplorer.v4.params.ColumnFunction;
+import org.apache.streampipes.dataexplorer.v4.query.elements.OrderingByTime;
 import org.influxdb.dto.Query;
+import org.influxdb.querybuilder.Ordering;
 import org.influxdb.querybuilder.SelectionQueryImpl;
 import org.influxdb.querybuilder.clauses.*;
 
@@ -28,7 +30,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select;
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.*;
 
 public class DataLakeQueryBuilder {
 
@@ -36,6 +38,8 @@ public class DataLakeQueryBuilder {
   private final SelectionQueryImpl selectionQuery;
   private final List<Clause> whereClauses;
   private final List<Clause> groupByClauses;
+  private Ordering ordering;
+  private int limit = Integer.MIN_VALUE;
 
   public static DataLakeQueryBuilder create(String measurementId) {
     return new DataLakeQueryBuilder(measurementId);
@@ -127,6 +131,23 @@ public class DataLakeQueryBuilder {
     return this;
   }
 
+  public DataLakeQueryBuilder withOrderBy(DataLakeQueryOrdering ordering) {
+    if (DataLakeQueryOrdering.ASC.equals(ordering)) {
+      this.ordering =  asc();
+    } else {
+      this.ordering =  desc();
+    }
+
+    return this;
+  }
+
+  public DataLakeQueryBuilder withLimit(int limit) {
+    this.limit = limit;
+
+    return this;
+  }
+
+
   private String transform(String column) {
     return column.toLowerCase();
   }
@@ -136,15 +157,27 @@ public class DataLakeQueryBuilder {
     this.whereClauses.forEach(selectQuery::where);
     this.groupByClauses.forEach(selectQuery::groupBy);
 
+    if (this.ordering != null) {
+     selectQuery.orderBy(this.ordering);
+    }
+
+    if (this.limit != Integer.MIN_VALUE) {
+      selectQuery.limit(this.limit);
+    }
+
     return selectQuery;
   }
 
   public static void main(String[] args) {
     Query query = DataLakeQueryBuilder.create("abc")
-      .withSimpleColumn("test")
+//      .withSimpleColumn("test")
+//            .withAggregatedColumn("*", ColumnFunction.LAST, "abc")
       .withTimeBoundary(1, 2)
       .withExclusiveFilter("text", "!=", Arrays.asList("a", "b"))
       .withGroupByTime("1h")
+            .withOrderBy(DataLakeQueryOrdering.ASC)
+            .withLimit(1)
+
       .build();
     System.out.println(query.getCommand());
   }
diff --git a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryConstants.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryConstants.java
index e37389bce..f6664f45a 100644
--- a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryConstants.java
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryConstants.java
@@ -26,4 +26,5 @@ public class DataLakeQueryConstants {
   public static final String GT = ">";
   public static final String EQ = "=";
   public static final String NEQ = "!=";
+
 }
diff --git a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryOrdering.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryOrdering.java
new file mode 100644
index 000000000..b187cd38a
--- /dev/null
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryOrdering.java
@@ -0,0 +1,5 @@
+package org.apache.streampipes.dataexplorer.sdk;
+
+public enum DataLakeQueryOrdering {
+    ASC, DESC
+}