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

[incubator-streampipes] branch STREAMPIPES-545 updated (bc4a28f91 -> 7e0c78f9b)

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

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


    from bc4a28f91 [hotfix] Show file selection in static properties in full width
     new b0245c21d [hotfix] Add initial builder for internal data lake queries
     new 7e0c78f9b [hotfix] Extend data lake storage API

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../dataexplorer/sdk/DataLakeQueryBuilder.java     | 146 +++++++++++++++++++++
 .../dataexplorer/sdk/DataLakeQueryConstants.java   |  17 ++-
 .../v4/params/WhereStatementParams.java            |   2 +
 .../dataexplorer/v4/query/DataExplorerQueryV4.java |  13 ++
 .../streampipes/storage/api/IDataLakeStorage.java  |   2 +
 .../storage/couchdb/impl/DataLakeStorageImpl.java  |   5 +
 6 files changed, 176 insertions(+), 9 deletions(-)
 create mode 100644 streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryBuilder.java
 copy streampipes-backend/src/main/java/org/apache/streampipes/backend/WelcomePageController.java => streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryConstants.java (71%)


[incubator-streampipes] 02/02: [hotfix] Extend data lake storage API

Posted by ri...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7e0c78f9bc74c2d5a486398ebc39ed5842af18c4
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Fri Jul 22 10:58:05 2022 +0200

    [hotfix] Extend data lake storage API
---
 .../java/org/apache/streampipes/storage/api/IDataLakeStorage.java    | 2 ++
 .../apache/streampipes/storage/couchdb/impl/DataLakeStorageImpl.java | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/IDataLakeStorage.java b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/IDataLakeStorage.java
index d16cfc21a..213e73780 100644
--- a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/IDataLakeStorage.java
+++ b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/IDataLakeStorage.java
@@ -27,4 +27,6 @@ public interface IDataLakeStorage {
     boolean storeDataLakeMeasure(DataLakeMeasure measure);
 
     List<DataLakeMeasure> getAllDataLakeMeasures();
+
+    DataLakeMeasure findOne(String id);
 }
diff --git a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/DataLakeStorageImpl.java b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/DataLakeStorageImpl.java
index 60a75596f..992654478 100644
--- a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/DataLakeStorageImpl.java
+++ b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/DataLakeStorageImpl.java
@@ -41,4 +41,9 @@ public class DataLakeStorageImpl extends AbstractDao<DataLakeMeasure> implements
         List<DataLakeMeasure> dataLakeMeasures = findAll();
         return dataLakeMeasures;
     }
+
+    @Override
+    public DataLakeMeasure findOne(String id) {
+        return find(id).orElse(null);
+    }
 }


[incubator-streampipes] 01/02: [hotfix] Add initial builder for internal data lake queries

Posted by ri...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b0245c21dbe55955f2c042c4a92b7785f8264a7c
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Fri Jul 22 10:57:53 2022 +0200

    [hotfix] Add initial builder for internal data lake queries
---
 .../dataexplorer/sdk/DataLakeQueryBuilder.java     | 146 +++++++++++++++++++++
 .../dataexplorer/sdk/DataLakeQueryConstants.java   |  29 ++++
 .../v4/params/WhereStatementParams.java            |   2 +
 .../dataexplorer/v4/query/DataExplorerQueryV4.java |  13 ++
 4 files changed, 190 insertions(+)

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
new file mode 100644
index 000000000..4c890843e
--- /dev/null
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryBuilder.java
@@ -0,0 +1,146 @@
+/*
+ * 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.sdk;
+
+import org.apache.streampipes.config.backend.BackendConfig;
+import org.apache.streampipes.dataexplorer.v4.params.ColumnFunction;
+import org.influxdb.dto.Query;
+import org.influxdb.querybuilder.SelectionQueryImpl;
+import org.influxdb.querybuilder.clauses.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select;
+
+public class DataLakeQueryBuilder {
+
+  private final String measurementId;
+  private final SelectionQueryImpl selectionQuery;
+  private final List<Clause> whereClauses;
+  private final List<Clause> groupByClauses;
+
+  public static DataLakeQueryBuilder create(String measurementId) {
+    return new DataLakeQueryBuilder(measurementId);
+  }
+
+  private DataLakeQueryBuilder(String measurementId) {
+    this.measurementId = measurementId;
+    this.selectionQuery = select();
+    this.whereClauses = new ArrayList<>();
+    this.groupByClauses = new ArrayList<>();
+  }
+
+  public DataLakeQueryBuilder withSimpleColumn(String columnName) {
+    this.selectionQuery.column(columnName);
+
+    return this;
+  }
+
+  public DataLakeQueryBuilder withAggregatedColumn(String columnName,
+                                                   ColumnFunction columnFunction,
+                                                   String targetName) {
+    String transformedColumnName = transform(columnName);
+    String transformedTargetName = transform(targetName);
+    if (columnFunction == ColumnFunction.COUNT) {
+      this.selectionQuery.count(transformedColumnName).as(transformedTargetName);
+    } else if (columnFunction == ColumnFunction.MEAN) {
+      this.selectionQuery.mean(transformedColumnName).as(transformedTargetName);
+    } else if (columnFunction == ColumnFunction.MIN) {
+      this.selectionQuery.min(transformedColumnName).as(transformedTargetName);
+    } else if (columnFunction == ColumnFunction.MAX) {
+      this.selectionQuery.max(transformedColumnName).as(transformedTargetName);
+    }
+
+    // TODO implement all column functions
+
+    return this;
+  }
+
+  public DataLakeQueryBuilder withStartTime(long startTime) {
+    this.whereClauses.add(new SimpleClause("time", ">=", startTime * 1000000));
+    return this;
+  }
+
+
+  public DataLakeQueryBuilder withEndTime(long endTime) {
+    this.whereClauses.add(new SimpleClause("time", "<=", endTime * 1000000));
+    return this;
+  }
+
+  public DataLakeQueryBuilder withTimeBoundary(long startTime,
+                                               long endTime) {
+    this.withStartTime(startTime);
+    this.withEndTime(endTime);
+
+    return this;
+  }
+
+  public DataLakeQueryBuilder withFilter(String field,
+                                         String operator,
+                                         Object value) {
+    this.whereClauses.add(new SimpleClause(field, operator, value));
+    return this;
+  }
+
+  public DataLakeQueryBuilder withExclusiveFilter(String field,
+                                                  String operator,
+                                                  List<?> values) {
+    List<ConjunctionClause> or = new ArrayList<>();
+    values.forEach(value -> {
+      or.add(new OrConjunction(new SimpleClause(transform(field), operator, value)));
+    });
+
+    NestedClause nestedClause = new NestedClause(or);
+    this.whereClauses.add(nestedClause);
+
+    return this;
+  }
+
+  public DataLakeQueryBuilder withGroupByTime(String timeInterval) {
+
+    this.groupByClauses.add(new RawTextClause("time(" + timeInterval + ")"));
+
+    return this;
+  }
+
+  private String transform(String column) {
+    return column.toLowerCase();
+  }
+
+  public Query build() {
+    var selectQuery = this.selectionQuery.from(BackendConfig.INSTANCE.getInfluxDatabaseName(), measurementId);
+    this.whereClauses.forEach(selectQuery::where);
+    this.groupByClauses.forEach(selectQuery::groupBy);
+
+    return selectQuery;
+  }
+
+  public static void main(String[] args) {
+    Query query = DataLakeQueryBuilder.create("abc")
+      .withSimpleColumn("test")
+      .withTimeBoundary(1, 2)
+      .withExclusiveFilter("text", "!=", Arrays.asList("a", "b"))
+      .withGroupByTime("1h")
+      .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
new file mode 100644
index 000000000..e37389bce
--- /dev/null
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/sdk/DataLakeQueryConstants.java
@@ -0,0 +1,29 @@
+/*
+ * 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.sdk;
+
+public class DataLakeQueryConstants {
+
+  public static final String GE = ">=";
+  public static final String LE = "<=";
+  public static final String LT = "<";
+  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/v4/params/WhereStatementParams.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/params/WhereStatementParams.java
index e3dbd8497..a0af420b1 100644
--- a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/params/WhereStatementParams.java
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/params/WhereStatementParams.java
@@ -103,6 +103,8 @@ public class WhereStatementParams extends QueryParamsV4 {
   private String returnCondition(String inputCondition) {
     if (NumberUtils.isCreatable(inputCondition) || Boolean.parseBoolean(inputCondition)) {
       return inputCondition;
+    } else if (inputCondition.equals("\"\"")) {
+      return inputCondition;
     } else {
       return "'" + inputCondition + "'";
     }
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 c1a512169..973a6ae1b 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
@@ -44,6 +44,10 @@ public class DataExplorerQueryV4 {
 
     protected int maximumAmountOfEvents;
 
+    public DataExplorerQueryV4() {
+
+    }
+
     public DataExplorerQueryV4(Map<String, QueryParamsV4> params) {
         this.params = params;
         this.maximumAmountOfEvents = -1;
@@ -84,6 +88,15 @@ public class DataExplorerQueryV4 {
         return dataResult;
     }
 
+    public SpQueryResult executeQuery(Query query) {
+        InfluxDB influxDB = DataExplorerUtils.getInfluxDBClient();
+        QueryResult result = influxDB.query(query);
+        SpQueryResult dataResult = postQuery(result);
+        influxDB.close();
+
+        return dataResult;
+    }
+
     private double getAmountOfResults(QueryResult countQueryResult) {
         if (countQueryResult.getResults().get(0).getSeries() != null &&
                 countQueryResult.getResults().get(0).getSeries().get(0).getValues() != null) {