You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by eb...@apache.org on 2021/06/14 08:05:00 UTC

[incubator-streampipes] branch STREAMPIPES-349 updated: [STREAMPIPES-349] Refactoring of Query Params Extraction: enhanced decoupling of data lake management class and database-specific statements

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

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


The following commit(s) were added to refs/heads/STREAMPIPES-349 by this push:
     new 4af58fc  [STREAMPIPES-349] Refactoring of Query Params Extraction: enhanced decoupling of data lake management class and database-specific statements
4af58fc is described below

commit 4af58fc3fc29c177264c1f5666d4e192accf1c7e
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Mon Jun 14 10:04:32 2021 +0200

    [STREAMPIPES-349] Refactoring of Query Params Extraction: enhanced decoupling of data lake management class and database-specific statements
---
 .../dataexplorer/DataLakeManagementV4.java         | 59 +--------------
 .../dataexplorer/v4/query/DataExplorerQueryV4.java | 35 ++++-----
 .../v4/utils/DataLakeManagementUtils.java          | 87 ++++++++++++++++++++++
 3 files changed, 109 insertions(+), 72 deletions(-)

diff --git a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/DataLakeManagementV4.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/DataLakeManagementV4.java
index 1eed837..e06a8cc 100644
--- a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/DataLakeManagementV4.java
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/DataLakeManagementV4.java
@@ -25,8 +25,9 @@ import org.apache.streampipes.dataexplorer.query.DeleteDataQuery;
 import org.apache.streampipes.dataexplorer.query.EditRetentionPolicyQuery;
 import org.apache.streampipes.dataexplorer.query.ShowRetentionPolicyQuery;
 import org.apache.streampipes.dataexplorer.utils.DataExplorerUtils;
-import org.apache.streampipes.dataexplorer.v4.params.*;
+import org.apache.streampipes.dataexplorer.v4.params.QueryParamsV4;
 import org.apache.streampipes.dataexplorer.v4.query.DataExplorerQueryV4;
+import org.apache.streampipes.dataexplorer.v4.utils.DataLakeManagementUtils;
 import org.apache.streampipes.model.datalake.DataLakeConfiguration;
 import org.apache.streampipes.model.datalake.DataLakeMeasure;
 import org.apache.streampipes.model.datalake.DataLakeRetentionPolicy;
@@ -39,7 +40,6 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -51,7 +51,7 @@ public class DataLakeManagementV4 {
     }
 
     public DataResult getData(String measurementID, Long startDate, Long endDate, Integer page, Integer limit, Integer offset, String groupBy, String order, String aggregationFunction, String timeInterval) {
-        Map<String, QueryParamsV4> queryParts = getQueryParams(measurementID, startDate, endDate, page, limit, offset, groupBy, order, aggregationFunction, timeInterval);
+        Map<String, QueryParamsV4> queryParts = DataLakeManagementUtils.getSelectQueryParams(measurementID, startDate, endDate, page, limit, offset, groupBy, order, aggregationFunction, timeInterval);
         return new DataExplorerQueryV4(queryParts).executeQuery();
     }
 
@@ -197,7 +197,7 @@ public class DataLakeManagementV4 {
     }
 
     public DataResult deleteData(String measurementID, Long startDate, Long endDate) {
-        Map<String, QueryParamsV4> queryParts = getDeleteQueryParams(measurementID, startDate, endDate);
+        Map<String, QueryParamsV4> queryParts = DataLakeManagementUtils.getDeleteQueryParams(measurementID, startDate, endDate);
         return new DataExplorerQueryV4(queryParts).executeQuery();
     }
 
@@ -265,57 +265,6 @@ public class DataLakeManagementV4 {
         return isSuccess;
     }
 
-    private Map<String, QueryParamsV4> getQueryParams(String measurementID, Long startDate, Long endDate, Integer page, Integer limit, Integer offset, String groupBy, String order, String aggregationFunction, String timeInterval) {
-        Map<String, QueryParamsV4> queryParts = new HashMap<>();
-
-        queryParts.put("SELECT", SelectFromStatementParams.from(measurementID, aggregationFunction));
-
-        if (startDate != null || endDate != null) {
-            queryParts.put("WHERE", TimeBoundaryParams.from(measurementID, startDate, endDate));
-        }
-
-
-        if (timeInterval != null && aggregationFunction != null) {
-            if (groupBy == null) {
-                queryParts.put("GROUPBYTIME", GroupingByTimeParams.from(measurementID, timeInterval));
-            } else {
-                groupBy = groupBy + ",time(" + timeInterval + ")";
-            }
-        }
-
-        if (groupBy != null) {
-            queryParts.put("GROUPBY", GroupingByTagsParams.from(measurementID, groupBy));
-        }
-
-        if (order != null) {
-            if (order.equals("DESC")) {
-                queryParts.put("DESCENDING", OrderingByTimeParams.from(measurementID, order));
-            }
-        }
-
-        if (limit != null) {
-            queryParts.put("LIMIT", ItemLimitationParams.from(measurementID, limit));
-        }
-
-        if (offset != null) {
-            queryParts.put("OFFSET", OffsetParams.from(measurementID, offset));
-        } else if (limit != null && page != null) {
-            queryParts.put("OFFSET", OffsetParams.from(measurementID, page * limit));
-        }
-
-        return queryParts;
-
-    }
-
-    public Map<String, QueryParamsV4> getDeleteQueryParams(String measurementID, Long startDate, Long endDate) {
-        Map<String, QueryParamsV4> queryParts = new HashMap<>();
-        queryParts.put("DELETE", DeleteFromStatementParams.from(measurementID));
-        if (startDate != null || endDate != null) {
-            queryParts.put("WHERE", TimeBoundaryParams.from(measurementID, startDate, endDate));
-        }
-        return queryParts;
-    }
-
     private byte[] toBytes(String value) {
         return value.getBytes();
     }
diff --git a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/query/DataExplorerQueryV4.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/query/DataExplorerQueryV4.java
index 6b06f21..9db9be6 100644
--- a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/query/DataExplorerQueryV4.java
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/query/DataExplorerQueryV4.java
@@ -22,6 +22,7 @@ import org.apache.streampipes.config.backend.BackendConfig;
 import org.apache.streampipes.dataexplorer.utils.DataExplorerUtils;
 import org.apache.streampipes.dataexplorer.v4.params.*;
 import org.apache.streampipes.dataexplorer.v4.query.elements.*;
+import org.apache.streampipes.dataexplorer.v4.utils.DataLakeManagementUtils;
 import org.apache.streampipes.model.datalake.DataResult;
 import org.influxdb.InfluxDB;
 import org.influxdb.dto.Query;
@@ -85,35 +86,35 @@ public class DataExplorerQueryV4 {
     protected List<QueryElement> getQueryElements() {
         List<QueryElement> queryElements = new ArrayList<>();
 
-        if (this.params.containsKey("SELECT")) {
-            queryElements.add(new SelectFromStatement((SelectFromStatementParams) this.params.get("SELECT")));
+        if (this.params.containsKey(DataLakeManagementUtils.SELECT_FROM)) {
+            queryElements.add(new SelectFromStatement((SelectFromStatementParams) this.params.get(DataLakeManagementUtils.SELECT_FROM)));
         } else {
-            queryElements.add(new DeleteFromStatement((DeleteFromStatementParams) this.params.get("DELETE")));
+            queryElements.add(new DeleteFromStatement((DeleteFromStatementParams) this.params.get(DataLakeManagementUtils.SELECT_FROM)));
         }
 
-        if (this.params.containsKey("WHERE")) {
-            queryElements.add(new TimeBoundary((TimeBoundaryParams) this.params.get("WHERE")));
+        if (this.params.containsKey(DataLakeManagementUtils.WHERE)) {
+            queryElements.add(new TimeBoundary((TimeBoundaryParams) this.params.get(DataLakeManagementUtils.WHERE)));
         }
 
-        if (this.params.containsKey("GROUPBYTIME")) {
-            queryElements.add(new GroupingByTime((GroupingByTimeParams) this.params.get("GROUPBYTIME")));
+        if (this.params.containsKey(DataLakeManagementUtils.GROUP_BY_TIME)) {
+            queryElements.add(new GroupingByTime((GroupingByTimeParams) this.params.get(DataLakeManagementUtils.GROUP_BY_TIME)));
 
-        } else if (this.params.containsKey("GROUPBY")) {
-            queryElements.add(new GroupingByTags((GroupingByTagsParams) this.params.get("GROUPBY")));
+        } else if (this.params.containsKey(DataLakeManagementUtils.GROUP_BY_TAGS)) {
+            queryElements.add(new GroupingByTags((GroupingByTagsParams) this.params.get(DataLakeManagementUtils.GROUP_BY_TAGS)));
         }
 
-        if (this.params.containsKey("DESCENDING")) {
-            queryElements.add(new OrderingByTime((OrderingByTimeParams) this.params.get("DESCENDING")));
-        } else if (this.params.containsKey("SELECT")) {
-            queryElements.add(new OrderingByTime(OrderingByTimeParams.from(this.params.get("SELECT").getIndex(), "ASC")));
+        if (this.params.containsKey(DataLakeManagementUtils.ORDER_DESCENDING)) {
+            queryElements.add(new OrderingByTime((OrderingByTimeParams) this.params.get(DataLakeManagementUtils.ORDER_DESCENDING)));
+        } else if (this.params.containsKey(DataLakeManagementUtils.SELECT_FROM)) {
+            queryElements.add(new OrderingByTime(OrderingByTimeParams.from(this.params.get(DataLakeManagementUtils.SELECT_FROM).getIndex(), "ASC")));
         }
 
-        if (this.params.containsKey("LIMIT")) {
-            queryElements.add(new ItemLimitation((ItemLimitationParams) this.params.get("LIMIT")));
+        if (this.params.containsKey(DataLakeManagementUtils.LIMIT)) {
+            queryElements.add(new ItemLimitation((ItemLimitationParams) this.params.get(DataLakeManagementUtils.LIMIT)));
         }
 
-        if (this.params.containsKey("OFFSET")) {
-            queryElements.add(new Offset((OffsetParams) this.params.get("OFFSET")));
+        if (this.params.containsKey(DataLakeManagementUtils.OFFSET)) {
+            queryElements.add(new Offset((OffsetParams) this.params.get(DataLakeManagementUtils.OFFSET)));
         }
 
         return queryElements;
diff --git a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/utils/DataLakeManagementUtils.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/utils/DataLakeManagementUtils.java
new file mode 100644
index 0000000..ca5195a
--- /dev/null
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/utils/DataLakeManagementUtils.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.dataexplorer.v4.utils;
+
+import org.apache.streampipes.dataexplorer.v4.params.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DataLakeManagementUtils {
+
+    public static final String SELECT_FROM = "SELECT";
+    public static final String WHERE = "WHERE";
+    public static final String GROUP_BY_TAGS = "GROUPBY";
+    public static final String GROUP_BY_TIME = "GROUPBYTIME";
+    public static final String ORDER_DESCENDING = "DESC";
+    public static final String LIMIT = "LIMIT";
+    public static final String OFFSET = "OFFSET";
+
+    public static final String DELETE_FROM = "DELETE";
+
+    public static Map<String, QueryParamsV4> getSelectQueryParams(String measurementID, Long startDate, Long endDate, Integer page, Integer limit, Integer offset, String groupBy, String order, String aggregationFunction, String timeInterval) {
+        Map<String, QueryParamsV4> queryParts = new HashMap<>();
+
+        queryParts.put(SELECT_FROM, SelectFromStatementParams.from(measurementID, aggregationFunction));
+
+        if (startDate != null || endDate != null) {
+            queryParts.put(WHERE, TimeBoundaryParams.from(measurementID, startDate, endDate));
+        }
+
+
+        if (timeInterval != null && aggregationFunction != null) {
+            if (groupBy == null) {
+                queryParts.put(GROUP_BY_TIME, GroupingByTimeParams.from(measurementID, timeInterval));
+            } else {
+                groupBy = groupBy + ",time(" + timeInterval + ")";
+            }
+        }
+
+        if (groupBy != null) {
+            queryParts.put(GROUP_BY_TAGS, GroupingByTagsParams.from(measurementID, groupBy));
+        }
+
+        if (order != null) {
+            if (order.equals(ORDER_DESCENDING)) {
+                queryParts.put(ORDER_DESCENDING, OrderingByTimeParams.from(measurementID, order));
+            }
+        }
+
+        if (limit != null) {
+            queryParts.put(LIMIT, ItemLimitationParams.from(measurementID, limit));
+        }
+
+        if (offset != null) {
+            queryParts.put(OFFSET, OffsetParams.from(measurementID, offset));
+        } else if (limit != null && page != null) {
+            queryParts.put(OFFSET, OffsetParams.from(measurementID, page * limit));
+        }
+
+        return queryParts;
+    }
+
+    public static Map<String, QueryParamsV4> getDeleteQueryParams(String measurementID, Long startDate, Long endDate) {
+        Map<String, QueryParamsV4> queryParts = new HashMap<>();
+        queryParts.put(DELETE_FROM, DeleteFromStatementParams.from(measurementID));
+        if (startDate != null || endDate != null) {
+            queryParts.put(WHERE, TimeBoundaryParams.from(measurementID, startDate, endDate));
+        }
+        return queryParts;
+    }
+}