Skip to content

Commit dc35fa9

Browse files
committed
Add datemath test
1 parent edb02b6 commit dc35fa9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterLookupJoinIT.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import org.elasticsearch.xpack.esql.core.type.DataType;
1818

1919
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;
2024
import java.util.List;
2125
import java.util.Map;
2226

@@ -139,6 +143,35 @@ public void testLookupJoinWithAliases() throws IOException {
139143
}
140144
}
141145

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+
142175
public void testLookupJoinMissingRemoteIndex() throws IOException {
143176
setupClusters(2);
144177
populateLookupIndex(LOCAL_CLUSTER, "values_lookup", 10);

0 commit comments

Comments
 (0)