This is an automated email from the ASF dual-hosted git repository. dominikriemer pushed a commit to branch improve-influx-query-builder in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 450fb6a0a5c3c2512c9512e2a3724210bc9c377c Author: Dominik Riemer <[email protected]> AuthorDate: Sun Jun 14 14:59:22 2026 +0200 fix: Properly escape field names in select clause --- .../influx/DataLakeInfluxQueryBuilder.java | 13 +++++++++-- .../influx/DataLakeQueryBuilderTest.java | 25 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/streampipes-data-explorer-influx/src/main/java/org/apache/streampipes/dataexplorer/influx/DataLakeInfluxQueryBuilder.java b/streampipes-data-explorer-influx/src/main/java/org/apache/streampipes/dataexplorer/influx/DataLakeInfluxQueryBuilder.java index 74ffa2428a..30111765d4 100644 --- a/streampipes-data-explorer-influx/src/main/java/org/apache/streampipes/dataexplorer/influx/DataLakeInfluxQueryBuilder.java +++ b/streampipes-data-explorer-influx/src/main/java/org/apache/streampipes/dataexplorer/influx/DataLakeInfluxQueryBuilder.java @@ -99,14 +99,15 @@ public class DataLakeInfluxQueryBuilder implements IDataLakeQueryBuilder<Query> AggregationFunction aggregationFunction, String aliasName) { - this.selectionQuery.function(aggregationFunction.toDbName(), columnName).as(aliasName); + this.selectionQuery.function(aggregationFunction.toDbName(), escapeIdentifier(columnName)) + .as(escapeIdentifier(aliasName)); return this; } @Override public IDataLakeQueryBuilder<Query> withAggregatedColumn(String columnName, AggregationFunction aggregationFunction) { - this.selectionQuery.function(aggregationFunction.toDbName(), columnName); + this.selectionQuery.function(aggregationFunction.toDbName(), escapeIdentifier(columnName)); return this; } @@ -320,4 +321,12 @@ public class DataLakeInfluxQueryBuilder implements IDataLakeQueryBuilder<Query> private String escapeIndex(String index) { return "\"" + index + "\""; } + + private String escapeIdentifier(String identifier) { + if (identifier.matches("[A-Za-z0-9_]+")) { + return identifier; + } + + return "\"" + identifier.replace("\"", "\\\"") + "\""; + } } diff --git a/streampipes-data-explorer-influx/src/test/java/org/apache/streampipes/dataexplorer/influx/DataLakeQueryBuilderTest.java b/streampipes-data-explorer-influx/src/test/java/org/apache/streampipes/dataexplorer/influx/DataLakeQueryBuilderTest.java index 48caeaa516..524e12c2fa 100644 --- a/streampipes-data-explorer-influx/src/test/java/org/apache/streampipes/dataexplorer/influx/DataLakeQueryBuilderTest.java +++ b/streampipes-data-explorer-influx/src/test/java/org/apache/streampipes/dataexplorer/influx/DataLakeQueryBuilderTest.java @@ -18,6 +18,8 @@ package org.apache.streampipes.dataexplorer.influx; +import org.apache.streampipes.model.datalake.AggregationFunction; + import org.junit.jupiter.api.Test; import java.util.List; @@ -37,4 +39,27 @@ public class DataLakeQueryBuilderTest { var expected = String.format("SELECT one,two FROM \"%s\";", MEASUREMENT); assertEquals(expected , result.getCommand()); } + + @Test + public void withAggregatedColumnEscapesDottedFieldAndAliasTest() { + var result = DataLakeInfluxQueryBuilder + .create(MEASUREMENT) + .withAggregatedColumn("temperature.a", AggregationFunction.MEAN, "temperature.a") + .build(); + + var expected = String.format("SELECT MEAN(\"temperature.a\") AS \"temperature.a\" FROM \"%s\";", MEASUREMENT); + assertEquals(expected, result.getCommand()); + } + + @Test + public void withGroupByEscapesDottedFieldTest() { + var result = DataLakeInfluxQueryBuilder + .create(MEASUREMENT) + .withSimpleColumn("value") + .withGroupBy("temperature.a") + .build(); + + var expected = String.format("SELECT value FROM \"%s\" GROUP BY \"temperature.a\";", MEASUREMENT); + assertEquals(expected, result.getCommand()); + } }
