tenthe commented on code in PR #3945: URL: https://github.com/apache/streampipes/pull/3945#discussion_r2559882586
########## streampipes-data-export/src/main/java/org/apache/streampipes/export/DataLakeExportManager.java: ########## @@ -0,0 +1,226 @@ +/* + * 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.export; + +import org.apache.streampipes.dataexplorer.api.IDataExplorerQueryManagement; +import org.apache.streampipes.dataexplorer.api.IDataExplorerSchemaManagement; +import org.apache.streampipes.dataexplorer.export.ObjectStorge.ExportProviderFactory; +import org.apache.streampipes.dataexplorer.export.ObjectStorge.IObjectStorage; +import org.apache.streampipes.dataexplorer.export.OutputFormat; +import org.apache.streampipes.dataexplorer.management.DataExplorerDispatcher; +import org.apache.streampipes.model.configuration.ExportProviderSettings; +import org.apache.streampipes.model.configuration.ProviderType; +import org.apache.streampipes.model.datalake.DataLakeMeasure; +import org.apache.streampipes.model.datalake.RetentionAction; +import org.apache.streampipes.model.datalake.RetentionLog; +import org.apache.streampipes.model.datalake.param.ProvidedRestQueryParams; +import org.apache.streampipes.storage.management.StorageDispatcher; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; + +import java.io.IOException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DataLakeExportManager { + + private static final Logger LOG = LoggerFactory.getLogger(DataLakeExportManager.class); + + private final IDataExplorerSchemaManagement dataExplorerSchemaManagement = new DataExplorerDispatcher() + .getDataExplorerManager() + .getSchemaManagement(); + + private final IDataExplorerQueryManagement dataExplorerQueryManagement = new DataExplorerDispatcher() + .getDataExplorerManager() + .getQueryManagement(this.dataExplorerSchemaManagement); + + private String savePath = ""; + + private void exportMeasurement(DataLakeMeasure dataLakeMeasure, Instant now, long endDate) throws Exception { + + if (System.getenv("SP_RETENTION_LOCAL_DIR") == null || System.getenv("SP_RETENTION_LOCAL_DIR").isEmpty()) { + LOG.error("For Local Retention Storage, please configure the environment variable SP_RETENTION_LOCAL_DIR"); + } + + var outputFormat = OutputFormat + .fromString(dataLakeMeasure.getRetentionTime().getRetentionExportConfig().getExportConfig().format()); + + Map<String, String> params = new HashMap<>(); + + params.put("delimiter", + dataLakeMeasure.getRetentionTime().getRetentionExportConfig().getExportConfig().csvDelimiter()); + params.put("format", dataLakeMeasure.getRetentionTime().getRetentionExportConfig().getExportConfig().format()); + params.put("headerColumnName", + dataLakeMeasure.getRetentionTime().getRetentionExportConfig().getExportConfig().headerColumnName()); + params.put("missingValueBehaviour", + dataLakeMeasure.getRetentionTime().getRetentionExportConfig().getExportConfig() + .missingValueBehaviour()); + params.put("endDate", Long.toString(endDate)); + + ProvidedRestQueryParams sanitizedParams = new ProvidedRestQueryParams(dataLakeMeasure.getMeasureName(), params); + StreamingResponseBody streamingOutput = output -> dataExplorerQueryManagement.getDataAsStream( + sanitizedParams, + outputFormat, + "ignore".equals( + dataLakeMeasure.getRetentionTime().getRetentionExportConfig().getExportConfig() + .missingValueBehaviour()), + output); + + String exportProviderId = dataLakeMeasure.getRetentionTime().getRetentionExportConfig() + .getExportProviderId(); + + // FInd Item in Document Review Comment: ```suggestion // Find Item in Document ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
