Fix "empty range" exception when querying InfluxDB2 (#14627)

Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
J-N-K 2023-03-18 13:31:41 +01:00 committed by GitHub
parent 979ecb0f98
commit 0f5dfa5088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -54,10 +54,12 @@ public class InfluxDB2FilterCriteriaQueryCreatorImpl implements FilterCriteriaQu
if (criteria.getBeginDate() != null) {
range.withStart(criteria.getBeginDate().toInstant());
} else {
range = flux.range(-100L, ChronoUnit.YEARS); // Flux needs a mandatory start range
range.withStart(-100L, ChronoUnit.YEARS); // Flux needs a mandatory start range
}
if (criteria.getEndDate() != null) {
range.withStop(criteria.getEndDate().toInstant());
} else {
range.withStop(100L, ChronoUnit.YEARS);
}
flux = range;

View File

@ -82,7 +82,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("""
from(bucket:"origin")
\t|> range(start:-100y)
\t|> range(start:-100y, stop:100y)
\t|> filter(fn: (r) => r["_measurement"] == "sampleItem")
\t|> keep(columns:["_measurement", "_time", "_value"])"""));
}
@ -96,7 +96,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
assertThat(queryV1, equalTo("SELECT \"value\"::field,\"item\"::tag FROM \"origin\"./.*/;"));
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("from(bucket:\"origin\")\n\t" + "|> range(start:-100y)"));
assertThat(queryV2, equalTo("from(bucket:\"origin\")\n\t" + "|> range(start:-100y, stop:100y)"));
}
@Test
@ -136,7 +136,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("""
from(bucket:"origin")
\t|> range(start:-100y)
\t|> range(start:-100y, stop:100y)
\t|> filter(fn: (r) => r["_measurement"] == "sampleItem")
\t|> keep(columns:["_measurement", "_time", "_value"])
\t|> filter(fn: (r) => (r["_field"] == "value" and r["_value"] <= 90))"""));
@ -155,7 +155,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("""
from(bucket:"origin")
\t|> range(start:-100y)
\t|> range(start:-100y, stop:100y)
\t|> filter(fn: (r) => r["_measurement"] == "sampleItem")
\t|> keep(columns:["_measurement", "_time", "_value"])
\t|> limit(n:10, offset:20)"""));
@ -173,7 +173,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("""
from(bucket:"origin")
\t|> range(start:-100y)
\t|> range(start:-100y, stop:100y)
\t|> filter(fn: (r) => r["_measurement"] == "sampleItem")
\t|> keep(columns:["_measurement", "_time", "_value"])
\t|> sort(desc:false, columns:["_time"])"""));
@ -187,7 +187,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("""
from(bucket:"origin")
\t|> range(start:-100y)
\t|> range(start:-100y, stop:100y)
\t|> filter(fn: (r) => r["_measurement"] == "sampleItem")
\t|> keep(columns:["_measurement", "_time", "_value"])
\t|> last()"""));
@ -215,7 +215,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("""
from(bucket:"origin")
\t|> range(start:-100y)
\t|> range(start:-100y, stop:100y)
\t|> filter(fn: (r) => r["_measurement"] == "measurementName")
\t|> filter(fn: (r) => r["item"] == "sampleItem")
\t|> keep(columns:["_measurement", "_time", "_value", "item"])"""));
@ -228,7 +228,7 @@ public class InfluxFilterCriteriaQueryCreatorImplTest {
queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("""
from(bucket:"origin")
\t|> range(start:-100y)
\t|> range(start:-100y, stop:100y)
\t|> filter(fn: (r) => r["_measurement"] == "sampleItem")
\t|> keep(columns:["_measurement", "_time", "_value"])"""));
}