feat(esgen): Painless queries for field-to-field comparison and recurring() (LYT-391)#56
Draft
junichi-cstk wants to merge 2 commits into
Draft
feat(esgen): Painless queries for field-to-field comparison and recurring() (LYT-391)#56junichi-cstk wants to merge 2 commits into
junichi-cstk wants to merge 2 commits into
Conversation
Add script-query generation to the Elasticsearch generator, which previously
only supported comparisons of a field against a constant.
- ScriptFilter type emitting {"script":{"script":{source,lang,params}}}
- field-to-field comparison (a < b) for non-nested time/numeric fields
- recurring(date_field, period[, offsetDays]) -> script query for
yearly/monthly/weekly/daily and every-N-days anniversaries
Supports lytics/lio#36194 (compare two date fields) and lytics/lio#34919
(recurring anniversary targeting).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Compare calendar dates via toLocalDate().toEpochDay() instead of instants (toEpochMilli), so `a < b` between two date fields matches for the whole UTC day rather than a single instant. Matches the lio in-process compiled evaluator, keeping the two scan paths semantically in lockstep. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds Elasticsearch Painless script generation for two new segment filter capabilities, so they can run as ES-backed scans:
recurring(date_field, period[, offsetDays])— matches documents whose date field lands on a recurrence of itself relative to now.periodisyearly/monthly/weekly/dailyor a positive integer (every N days).offsetDaysshifts the recurrence (yearly + 182 ≈ half-birthday).a < b) — ES range queries only compare a field to a constant, so a field-to-field comparison is emitted as a Painless script.Behavior
recurring(bday, "yearly")getMonthValue() == params.month && getDayOfMonth() == params.dayrecurring(bday, "weekly")getDayOfWeek().getValue() == params.dow(ISO 1=Mon..7=Sun)recurring(bday, 90)(todayDay - epochDay - offset) % n == 0joined < signup(time)toLocalDate().toEpochDay()comparison — day-granularclicks >= score(numeric)doc[a].value >= doc[b].valueNotable semantics:
toLocalDate().toEpochDay()), not instants, soa < bmatches for the whole day. Floors toward the earlier day, so pre-1970 dates (older birthdates) bucket correctly.< <= > >=) are supported for field-to-field;== / !=and non-nested comparable types (time↔time, numeric↔numeric) only.Why
Backend half of the segment recurring/field-compare feature. The consuming lio changes (in-process compiled evaluator + VM builtin) are paired; the two evaluation paths were parity-audited to agree on the edge cases above.
Sequencing
This PR merges and tags first, then lio bumps its
go.modto the tag and drops a temporary localreplace. The lio PR is stacked on this.Tracked in Jira: LYT-391.
🤖 Generated with Claude Code