This is an automated email from the ASF dual-hosted git repository.
pjain1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 6eb42e8d5a5 fix extraction of timeseries results from result level
cache (#16895)
6eb42e8d5a5 is described below
commit 6eb42e8d5a550b562445ce677d6fb83ee52f7103
Author: Parag Jain <[email protected]>
AuthorDate: Sun Sep 1 00:25:55 2024 +0530
fix extraction of timeseries results from result level cache (#16895)
* fix extraction of timeseries results from result level cache
* remove unneded import
* add test
---
.../timeseries/TimeseriesQueryQueryToolChest.java | 7 ++++
.../TimeseriesQueryQueryToolChestTest.java | 4 ++-
.../druid/sql/calcite/CalciteSelectQueryTest.java | 41 ++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git
a/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java
b/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java
index 05b25d05c21..18bcc713dec 100644
---
a/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java
+++
b/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java
@@ -383,6 +383,13 @@ public class TimeseriesQueryQueryToolChest extends
QueryToolChest<Result<Timeser
timestamp =
granularity.toDateTime(Preconditions.checkNotNull(timestampNumber,
"timestamp").longValue());
}
+ // If "timestampResultField" is set, we must include a copy of the
timestamp in the result.
+ // This is used by the SQL layer when it generates a Timeseries
query for a group-by-time-floor SQL query.
+ // The SQL layer expects the result of the time-floor to have a
specific name that is not going to be "__time".
+ if (StringUtils.isNotEmpty(query.getTimestampResultField()) &&
timestamp != null) {
+ retVal.put(query.getTimestampResultField(),
timestamp.getMillis());
+ }
+
CacheStrategy.fetchAggregatorsFromCache(
aggs,
resultIter,
diff --git
a/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java
b/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java
index f1afabe9c75..8d9166d2746 100644
---
a/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java
+++
b/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java
@@ -97,7 +97,7 @@ public class TimeseriesQueryQueryToolChestTest
),
ImmutableList.of(new ConstantPostAggregator("post", 10)),
0,
- null
+ ImmutableMap.of(TimeseriesQuery.CTX_TIMESTAMP_RESULT_FIELD,
"ts_field")
)
);
@@ -106,6 +106,7 @@ public class TimeseriesQueryQueryToolChestTest
DateTimes.utc(123L),
new TimeseriesResultValue(
ImmutableMap.of(
+ "ts_field", 123L,
"metric1", 2,
"metric0", 3,
"complexMetric", new SerializablePairLongString(123L, "val1")
@@ -130,6 +131,7 @@ public class TimeseriesQueryQueryToolChestTest
DateTimes.utc(123L),
new TimeseriesResultValue(
ImmutableMap.of(
+ "ts_field", 123L,
"metric1", 2,
"metric0", 3,
"complexMetric", "val1",
diff --git
a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java
b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java
index 6e06c5d4b5d..973b1eb4df1 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java
@@ -2118,6 +2118,47 @@ public class CalciteSelectQueryTest extends
BaseCalciteQueryTest
.run();
}
+ @SqlTestFrameworkConfig.ResultCache(ResultCacheMode.ENABLED)
+ @Test
+ public void testTimseriesResultCachePullConsistency()
+ {
+ skipVectorize();
+
+ String query = "SELECT \n"
+ + " (t1.\"__time\") AS \"__time\", \n"
+ + " (ANY_VALUE(t1.\"added\")) AS \"added\" \n"
+ + "FROM \n"
+ + " (\n"
+ + " SELECT \n"
+ + " (time_floor(\"__time\", 'PT1H')) AS \"__time\", \n"
+ + " (SUM(added)) AS \"added\" \n"
+ + " FROM \"wikipedia\" \n"
+ + " GROUP BY 1 \n"
+ + " ORDER BY \"__time\" \n"
+ + " LIMIT 1\n"
+ + " ) t1 \n"
+ + "GROUP BY 1 \n"
+ + "ORDER BY \"__time\"";
+
+ testBuilder()
+ .sql(query)
+ .expectedResults(
+ ImmutableList.of(
+ new Object[]{1442016000000L, 32251L}
+ )
+ )
+ .run();
+
+ testBuilder()
+ .sql(query)
+ .expectedResults(
+ ImmutableList.of(
+ new Object[]{1442016000000L, 32251L}
+ )
+ )
+ .run();
+ }
+
@Test
public void testSqlToRelInConversion()
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]