|
17 | 17 | import org.elasticsearch.xpack.esql.core.type.DataType; |
18 | 18 |
|
19 | 19 | import java.io.IOException; |
| 20 | +import java.time.Duration; |
| 21 | +import java.time.ZoneOffset; |
| 22 | +import java.time.ZonedDateTime; |
| 23 | +import java.time.format.DateTimeFormatter; |
20 | 24 | import java.util.List; |
21 | 25 | import java.util.Map; |
22 | 26 |
|
@@ -139,6 +143,35 @@ public void testLookupJoinWithAliases() throws IOException { |
139 | 143 | } |
140 | 144 | } |
141 | 145 |
|
| 146 | + public void testLookupJoinWithDatemath() throws IOException { |
| 147 | + setupClusters(2); |
| 148 | + |
| 149 | + ZonedDateTime nowUtc = ZonedDateTime.now(ZoneOffset.UTC); |
| 150 | + ZonedDateTime nextMidnight = nowUtc.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0); |
| 151 | + // If we're too close to midnight, we could create index with one day and query with another, and it'd fail. |
| 152 | + assumeTrue("Skip if too close to midnight", Duration.between(nowUtc, nextMidnight).toMinutes() >= 5); |
| 153 | + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd"); |
| 154 | + String lookupIndexName = "values_lookup_" + nowUtc.format(formatter); |
| 155 | + |
| 156 | + populateLookupIndex(LOCAL_CLUSTER, lookupIndexName, 10); |
| 157 | + populateLookupIndex(REMOTE_CLUSTER_1, lookupIndexName, 10); |
| 158 | + |
| 159 | + try ( |
| 160 | + EsqlQueryResponse resp = runQuery( |
| 161 | + "FROM logs-*,c*:logs-* | EVAL lookup_key = v | LOOKUP JOIN \"<values_lookup_{now/d}>\" ON lookup_key", |
| 162 | + randomBoolean() |
| 163 | + ) |
| 164 | + ) { |
| 165 | + var columns = resp.columns().stream().map(ColumnInfoImpl::name).toList(); |
| 166 | + assertThat(columns, hasItems("lookup_key", "lookup_name", "lookup_tag", "v", "tag")); |
| 167 | + |
| 168 | + List<List<Object>> values = getValuesList(resp); |
| 169 | + assertThat(values, hasSize(20)); |
| 170 | + EsqlExecutionInfo executionInfo = resp.getExecutionInfo(); |
| 171 | + assertCCSExecutionInfoDetails(executionInfo); |
| 172 | + } |
| 173 | + } |
| 174 | + |
142 | 175 | public void testLookupJoinMissingRemoteIndex() throws IOException { |
143 | 176 | setupClusters(2); |
144 | 177 | populateLookupIndex(LOCAL_CLUSTER, "values_lookup", 10); |
|
0 commit comments