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/11/09 15:54:38 UTC
[incubator-streampipes] 01/03: [STREAMPIPES-623] Change name timestamp field for data export
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch STREAMPIPES-623
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
commit 53f14a30da50afc4ad60f9868d763503f14b1ad7
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Wed Nov 9 16:22:46 2022 +0100
[STREAMPIPES-623] Change name timestamp field for data export
---
.../dataexplorer/DataLakeManagementV4.java | 31 +++-
.../model/datalake/DataLakeMeasure.java | 168 ++++++++++++---------
.../model/datalake/DataLakeMeasureTest.java | 59 ++++++++
.../fixtures/dataDownloadDialog/testCsvComma.csv | 2 +-
.../dataDownloadDialog/testCsvSemicolon.csv | 2 +-
.../fixtures/dataDownloadDialog/testJson.json | 2 +-
.../testRemoveLinesWithMissingValues.csv | 2 +-
7 files changed, 186 insertions(+), 80 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 1823d32ab..9ee04ff03 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
@@ -67,7 +67,11 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
-import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.*;
+import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_AUTO_AGGREGATE;
+import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_CSV_DELIMITER;
+import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_LIMIT;
+import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_MAXIMUM_AMOUNT_OF_EVENTS;
+import static org.apache.streampipes.dataexplorer.v4.SupportedDataLakeQueryParameters.QP_PAGE;
public class DataLakeManagementV4 {
@@ -87,6 +91,13 @@ public class DataLakeManagementV4 {
return getDataLakeStorage().findOne(measureId);
}
+ private Optional<DataLakeMeasure> findByMeasurementName(String measurementName) {
+ return getAllMeasurements()
+ .stream()
+ .filter(measurement -> measurement.getMeasureName().equals(measurementName))
+ .findFirst();
+ }
+
public SpQueryResult getData(ProvidedQueryParams queryParams, boolean ignoreMissingData) throws IllegalArgumentException {
if (queryParams.has(QP_AUTO_AGGREGATE)) {
queryParams = new AutoAggregationHandler(queryParams).makeAutoAggregationQueryParams();
@@ -114,6 +125,8 @@ public class DataLakeManagementV4 {
params.update(QP_LIMIT, 500000);
}
+ var measurement = findByMeasurementName(params.getMeasurementId()).get();
+
SpQueryResult dataResult;
//JSON
if (format.equals("json")) {
@@ -131,7 +144,10 @@ public class DataLakeManagementV4 {
params.update(SupportedDataLakeQueryParameters.QP_PAGE, String.valueOf(i));
dataResult = getData(params, ignoreMissingValues);
+
if (dataResult.getTotal() > 0) {
+ changeTimestampHeader(measurement, dataResult);
+
for (List<Object> row : dataResult.getAllDataSeries().get(0).getRows()) {
if (!isFirstDataObject) {
outputStream.write(toBytes(","));
@@ -179,8 +195,12 @@ public class DataLakeManagementV4 {
do {
params.update(SupportedDataLakeQueryParameters.QP_PAGE, String.valueOf(i));
dataResult = getData(params, ignoreMissingValues);
+
+
//Send first header
if (dataResult.getTotal() > 0) {
+ changeTimestampHeader(measurement, dataResult);
+
if (isFirstDataObject) {
boolean isFirst = true;
for (int i1 = 0; i1 < dataResult.getHeaders().size(); i1++) {
@@ -221,6 +241,15 @@ public class DataLakeManagementV4 {
}
}
+ /**
+ * Replaces the field 'time' of the data result with the actual timestamp field name of the measurement
+ * @param measurement contains the actual timestamp name value
+ * @param dataResult the query result of the database with 'time' as timestamp field name
+ */
+ private void changeTimestampHeader(DataLakeMeasure measurement, SpQueryResult dataResult) {
+ dataResult.getHeaders().set(0, measurement.getTimestampFieldName());
+ }
+
public boolean removeAllMeasurements() {
List<DataLakeMeasure> allMeasurements = getAllMeasurements();
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/datalake/DataLakeMeasure.java b/streampipes-model/src/main/java/org/apache/streampipes/model/datalake/DataLakeMeasure.java
index 5b90fd955..fbc2ef863 100644
--- a/streampipes-model/src/main/java/org/apache/streampipes/model/datalake/DataLakeMeasure.java
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/datalake/DataLakeMeasure.java
@@ -18,113 +18,131 @@
package org.apache.streampipes.model.datalake;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import org.apache.streampipes.model.base.UnnamedStreamPipesEntity;
import org.apache.streampipes.model.schema.EventSchema;
+import org.apache.streampipes.model.shared.annotation.TsIgnore;
import org.apache.streampipes.model.shared.annotation.TsModel;
@TsModel
public class DataLakeMeasure extends UnnamedStreamPipesEntity {
- public final static String CURRENT_SCHEMA_VERSION = "1.1";
+ public static final String CURRENT_SCHEMA_VERSION = "1.1";
- @JsonProperty("_rev")
- private @SerializedName("_rev") String rev;
+ private static final String STREAM_PREFIX_DELIMITER = "::";
- private String measureName;
+ public static final String ASSERTION_ERROR_MESSAGE = "timestamp field requires a stream prefix (e.g. s0::timestamp)";
- private String timestampField;
- private EventSchema eventSchema;
- private String pipelineId;
- private String pipelineName;
- private boolean pipelineIsRunning;
+ @JsonProperty("_rev")
+ private @SerializedName("_rev") String rev;
- private String schemaVersion;
+ private String measureName;
- public DataLakeMeasure() {
- super();
- }
+ private String timestampField;
+ private EventSchema eventSchema;
+ private String pipelineId;
+ private String pipelineName;
+ private boolean pipelineIsRunning;
- public DataLakeMeasure(DataLakeMeasure other) {
- super(other);
- this.measureName = other.getMeasureName();
- this.eventSchema = new EventSchema(other.getEventSchema());
+ private String schemaVersion;
- }
+ public DataLakeMeasure() {
+ super();
+ }
- public DataLakeMeasure(String measureName, EventSchema eventSchema) {
- this.measureName = measureName;
- this.eventSchema = eventSchema;
- }
+ public DataLakeMeasure(DataLakeMeasure other) {
+ super(other);
+ this.measureName = other.getMeasureName();
+ this.eventSchema = new EventSchema(other.getEventSchema());
- public DataLakeMeasure(String measureName, String timestampField, EventSchema eventSchema) {
- this.measureName = measureName;
- this.eventSchema = eventSchema;
- this.timestampField = timestampField;
- }
+ }
- public String getMeasureName() {
- return measureName;
- }
+ public DataLakeMeasure(String measureName, EventSchema eventSchema) {
+ this.measureName = measureName;
+ this.eventSchema = eventSchema;
+ }
- public void setMeasureName(String measureName) {
- this.measureName = measureName;
- }
+ public DataLakeMeasure(String measureName, String timestampField, EventSchema eventSchema) {
+ this.measureName = measureName;
+ this.eventSchema = eventSchema;
+ this.timestampField = timestampField;
+ }
- public EventSchema getEventSchema() {
- return eventSchema;
- }
+ public String getMeasureName() {
+ return measureName;
+ }
- public void setEventSchema(EventSchema eventSchema) {
- this.eventSchema = eventSchema;
- }
+ public void setMeasureName(String measureName) {
+ this.measureName = measureName;
+ }
- public String getPipelineId() {
- return pipelineId;
- }
+ public EventSchema getEventSchema() {
+ return eventSchema;
+ }
- public void setPipelineId(String pipelineId) {
- this.pipelineId = pipelineId;
- }
+ public void setEventSchema(EventSchema eventSchema) {
+ this.eventSchema = eventSchema;
+ }
- public String getPipelineName() {
- return pipelineName;
- }
+ public String getPipelineId() {
+ return pipelineId;
+ }
- public void setPipelineName(String pipelineName) {
- this.pipelineName = pipelineName;
- }
+ public void setPipelineId(String pipelineId) {
+ this.pipelineId = pipelineId;
+ }
- public boolean isPipelineIsRunning() {
- return pipelineIsRunning;
- }
+ public String getPipelineName() {
+ return pipelineName;
+ }
- public void setPipelineIsRunning(boolean pipelineIsRunning) {
- this.pipelineIsRunning = pipelineIsRunning;
- }
+ public void setPipelineName(String pipelineName) {
+ this.pipelineName = pipelineName;
+ }
- public String getSchemaVersion() {
- return schemaVersion;
- }
+ public boolean isPipelineIsRunning() {
+ return pipelineIsRunning;
+ }
- public void setSchemaVersion(String schemaVersion) {
- this.schemaVersion = schemaVersion;
- }
+ public void setPipelineIsRunning(boolean pipelineIsRunning) {
+ this.pipelineIsRunning = pipelineIsRunning;
+ }
- public String getTimestampField() {
- return timestampField;
- }
+ public String getSchemaVersion() {
+ return schemaVersion;
+ }
- public void setTimestampField(String timestampField) {
- this.timestampField = timestampField;
- }
+ public void setSchemaVersion(String schemaVersion) {
+ this.schemaVersion = schemaVersion;
+ }
- public String getRev() {
- return rev;
- }
+ public String getTimestampField() {
+ return timestampField;
+ }
- public void setRev(String rev) {
- this.rev = rev;
- }
+
+ /**
+ * This can be used to get the name of the timestamp property without the stream prefix
+ * @return the name of the timestamp property
+ */
+ @TsIgnore
+ @JsonIgnore
+ public String getTimestampFieldName() {
+ return timestampField.split(STREAM_PREFIX_DELIMITER)[1];
+ }
+
+ public void setTimestampField(String timestampField) {
+ assert timestampField.split(STREAM_PREFIX_DELIMITER).length == 2 : ASSERTION_ERROR_MESSAGE;
+ this.timestampField = timestampField;
+ }
+
+ public String getRev() {
+ return rev;
+ }
+
+ public void setRev(String rev) {
+ this.rev = rev;
+ }
}
diff --git a/streampipes-model/src/test/java/org/apache/streampipes/model/datalake/DataLakeMeasureTest.java b/streampipes-model/src/test/java/org/apache/streampipes/model/datalake/DataLakeMeasureTest.java
new file mode 100644
index 000000000..8a6f79f54
--- /dev/null
+++ b/streampipes-model/src/test/java/org/apache/streampipes/model/datalake/DataLakeMeasureTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.model.datalake;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class DataLakeMeasureTest {
+
+ private static final String TIMESTAMP_FIELD = "testTimestamp";
+ private static final String STREAM_PREFIX = "s0::";
+ private static final String TIMESTAMP_FIELD_NAME = STREAM_PREFIX + TIMESTAMP_FIELD;
+
+ private DataLakeMeasure dataLakeMeasure = new DataLakeMeasure();
+ @Test
+ public void setTimestampFieldSuccess() {
+ dataLakeMeasure.setTimestampField(TIMESTAMP_FIELD_NAME);
+
+ var result = dataLakeMeasure.getTimestampField();
+
+ assertEquals(TIMESTAMP_FIELD_NAME, result);
+ }
+
+ @Test
+ public void setTimestampFieldAssertionError() {
+ try {
+ dataLakeMeasure.setTimestampField(TIMESTAMP_FIELD);
+ } catch (AssertionError assertionError) {
+ assertEquals(DataLakeMeasure.ASSERTION_ERROR_MESSAGE, assertionError.getMessage());
+ }
+ }
+
+ @Test
+ public void getTimestampFieldName() {
+ dataLakeMeasure.setTimestampField(TIMESTAMP_FIELD_NAME);
+
+ var result = dataLakeMeasure.getTimestampFieldName();
+
+ assertEquals(TIMESTAMP_FIELD, result);
+ }
+
+}
\ No newline at end of file
diff --git a/ui/cypress/fixtures/dataDownloadDialog/testCsvComma.csv b/ui/cypress/fixtures/dataDownloadDialog/testCsvComma.csv
index 474a7fd3d..fdc110a3e 100644
--- a/ui/cypress/fixtures/dataDownloadDialog/testCsvComma.csv
+++ b/ui/cypress/fixtures/dataDownloadDialog/testCsvComma.csv
@@ -1,4 +1,4 @@
-time,v1,v2,v3,v4
+timestamp,v1,v2,v3,v4
1623871499055,4.099999904632568,abc,true,1.0
1623871500059,4.199999809265137,abc,false,2.0
1623871507091,4.300000190734863,,,3.0
diff --git a/ui/cypress/fixtures/dataDownloadDialog/testCsvSemicolon.csv b/ui/cypress/fixtures/dataDownloadDialog/testCsvSemicolon.csv
index f1ed0928e..f4ce709b9 100644
--- a/ui/cypress/fixtures/dataDownloadDialog/testCsvSemicolon.csv
+++ b/ui/cypress/fixtures/dataDownloadDialog/testCsvSemicolon.csv
@@ -1,4 +1,4 @@
-time;v1;v2;v3;v4
+timestamp;v1;v2;v3;v4
1623871499055;4.099999904632568;abc;true;1.0
1623871500059;4.199999809265137;abc;false;2.0
1623871507091;4.300000190734863;;;3.0
diff --git a/ui/cypress/fixtures/dataDownloadDialog/testJson.json b/ui/cypress/fixtures/dataDownloadDialog/testJson.json
index d26278677..756056b24 100644
--- a/ui/cypress/fixtures/dataDownloadDialog/testJson.json
+++ b/ui/cypress/fixtures/dataDownloadDialog/testJson.json
@@ -1 +1 @@
-[{"time": 1623871499055,"v1": 4.099999904632568,"v2": "abc","v3": true,"v4": 1.0},{"time": 1623871500059,"v1": 4.199999809265137,"v2": "abc","v3": false,"v4": 2.0},{"time": 1623871507091,"v1": 4.300000190734863,"v2": null,"v3": null,"v4": 3.0},{"time": 1623871508093,"v1": 4.400000095367432,"v2": "abc","v3": true,"v4": 4.0},{"time": 1623871508095,"v1": 4.5,"v2": null,"v3": null,"v4": 5.0}]
+[{"timestamp": 1623871499055,"v1": 4.099999904632568,"v2": "abc","v3": true,"v4": 1.0},{"timestamp": 1623871500059,"v1": 4.199999809265137,"v2": "abc","v3": false,"v4": 2.0},{"timestamp": 1623871507091,"v1": 4.300000190734863,"v2": null,"v3": null,"v4": 3.0},{"timestamp": 1623871508093,"v1": 4.400000095367432,"v2": "abc","v3": true,"v4": 4.0},{"timestamp": 1623871508095,"v1": 4.5,"v2": null,"v3": null,"v4": 5.0}]
diff --git a/ui/cypress/fixtures/dataDownloadDialog/testRemoveLinesWithMissingValues.csv b/ui/cypress/fixtures/dataDownloadDialog/testRemoveLinesWithMissingValues.csv
index a7902e7ec..0d0dd2888 100644
--- a/ui/cypress/fixtures/dataDownloadDialog/testRemoveLinesWithMissingValues.csv
+++ b/ui/cypress/fixtures/dataDownloadDialog/testRemoveLinesWithMissingValues.csv
@@ -1,4 +1,4 @@
-time;v1;v2;v3;v4
+timestamp;v1;v2;v3;v4
1623871499055;4.099999904632568;abc;true;1.0
1623871500059;4.199999809265137;abc;false;2.0
1623871508093;4.400000095367432;abc;true;4.0