Commit 47a44bf
authored
[analytics-engine] PPL date/time/timestamp fixes β format, overloads, span types, invalid literals (#22045)
* datetime stringify uses space, time has no epoch prefix
- ArrowValues: scalar + list temporal cells use space separator; time renders
as HH:mm:ss[.frac] (no 1970-01-01 prefix); nanos preserved.
- ArrowValues: post-process ISO-T VarChar cells from native CAST -> space.
- CastToVarcharRewriter (new): boolean -> varchar emits TRUE/FALSE.
- ListAggregateMultiTypeIT: assertions updated for new format.
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* PPL date function gap fixes: week modes, format tokens, tz NULL, cast TIME
- week() / week_of_year() default to mode 0 (Sunday-start) instead of ISO.
- str_to_date %b parses Jan/Feb/.../Dec to month number.
- date_format adds %c (month), %U %u %V %v (week numbers), %P (lowercase AM/PM).
- unix_timestamp accepts numeric YYYYMMDDhhmmss literal.
- convert_tz returns NULL on out-of-range tz instead of throwing.
- cast(<datetime-string> AS TIME) strips date prefix and keeps the time portion.
Adds os_week and os_strftime Rust UDFs (rust/src/udf/) wired through
OsWeekAdapter and the existing format / parse paths.
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* PPL invalid date literals reject with typed format-hint message
Pre-isthmus CastTemporalLiteralValidator and per-adapter validation surface
malformed string literals as IllegalArgumentException with the typed message
"<type>:<value> in unsupported format, please use '<pattern>'", replacing the
opaque Arrow Parser error / StreamException at HTTP 500.
Covers:
- CAST(<lit> AS DATE/TIME/TIMESTAMP) and TIMESTAMPADD/DIFF string args
(CastTemporalLiteralValidator RexShuttle).
- DATE / TIME / DATE_FORMAT / TIME_FORMAT / DATE_PART unit-aware operands
(per-adapter validation).
- HOUR(<bad-time>) and STR_TO_DATE with out-of-range month/day (was silent
HTTP 200 with wrong row).
DATETIME(<invalid>) folds to NULL TIMESTAMP at plan time per legacy SQL
DATETIME-of-invalid semantics.
Shared parsing routes through DatetimeLiteralValidator so accept-set and
format-hint message stay in one place.
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* Add missing PPL date function overloads
Adds the substrait-bind paths for ten function overloads that previously
failed isthmus lowering with "Unable to convert call <fn>(<sig>)":
- DATETIME(string, tz): plan-time fold for all-literal input (NULL on bad
value/tz); column-input rewrites to convert_tz with the source offset
stripped. tz bounds tightened to MySQL DATETIME range [-13:59, +14:00].
- now(fsp) / sysdate(fsp): drop FSP arg before mapping to DataFusion's
niladic now().
- DATE_ADD / DATE_SUB(TIME, interval) and TIMESTAMPADD(unit, n, TIME):
anchor TIME to today UTC, then DATETIME_PLUS with the unit interval.
- TIMESTAMPADD standalone: new adapter lowering to DATETIME_PLUS so the
call binds without a substrait sig for TIMESTAMPADD itself.
- TIMESTAMPDIFF standalone: (to_unixtime(t2) - to_unixtime(t1)) scaled by
the out-unit factor; MONTH/QUARTER/YEAR use 30/90/365-day approximations
matching legacy SQL plugin.
- DATE_PART(unit, TIME) and DATE_PART(unit, bare-time-string): today-UTC
anchor so the (string, precision_timestamp<P>) sig binds.
- FROM_UNIXTIME(epoch, format): compose date_format around the 1-arg UDF.
- SPAN(timestamp, N, 'M'|'q'|'y'): rewrite calendar-unit spans to
date_bin with a fixed 1970-01-01 origin.
- CONVERT_TZ invalid timestamp literal: plan-time fold to typed NULL.
- microsecond(): single CAST to TIMESTAMP(6) so the Β΅s fraction survives
date_part (no intermediate TIMESTAMP cast that would clip to ms).
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* PPL span(date) and span(time) preserve column type
OpenSearchSchemaBuilder reads each date / date_nanos field's `format` mapping
and routes date-only formats to DateOnlyType, time-only formats to TimeOnlyType
(new UDT markers). Format detection in DateFormatClassifier mirrors the SQL
plugin's OpenSearchDateType (named-format allow-lists + custom-pattern symbol
scan).
The UDT markers are TIMESTAMP-backed BasicSqlType subclasses β substrait wire
stays Timestamp(ms) so DateParquetField is unchanged. Only the user-visible
schema label flips.
Result:
- span(<date-typed>, β¦) returns a date column (not widened to timestamp).
- span(<time-typed>, β¦) returns a time column.
- Bucket values render as YYYY-MM-DD / HH:mm:ss (no 00:00:00 suffix, no
1970-01-01 prefix).
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* PPL TIMESTAMP(date, time) combine and HOUR-of-TIME-literal fold
Lifted from fix/ai-substrait-call-unlowerable (PR 22014):
- TIMESTAMP(<date col>, <time col>): 2-arg combine via
from_unixtime(to_unixtime(date) + to_unixtime(time)).
- HOUR / MINUTE / SECOND / MICROSECOND on a TIME literal: fold to BIGINT at
plan time so the call doesn't need a precision_time substrait sig.
PR 22014's other capabilities are already covered (or superseded) by the
preceding clusters: TimestampAddAdapter and DatetimeAdapter 2-arg fold by B,
TimestampDiffAdapter literal fold by B, FromUnixtimeAdapter 2-arg by B,
ConvertTzAdapter all-literal fold by F (cleaner reconciliation).
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* test(sandbox): backfill CAST(time-string AS DATE) rejection test
Adds testTimeLiteralCastToDateRejected to CastTemporalLiteralValidatorTests.
The rejection path itself was added in cluster C; this is the missing direct
test for the time-string-to-DATE case.
The two capabilities originally scoped under "cluster G" are landed elsewhere:
- CAST cross-type permissiveness β already covered by cluster C's plan-time
validators; only this test was missing.
- span() over date_add-derived expr β landed as a sql/api fix on the
fix/ai/cluster-g2-datetime-udt-normalize branch (DatetimeUdtNormalizeRule
re-aligns RexInputRefs after child UDT normalization).
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* test(sandbox): add DatetimeCoverageIT for cluster-all regression gate
End-to-end IT covering query shapes fixed by the cluster-all branch:
clusters D, F, C, B, A, plus the cherry-pick from PR 22014.
Shapes sourced from tests/parquet/a-date-time-failed/ and
tests/parquet/assertion-error-deep-dive/ topic folders. Each test method
exercises one shape that was failing pre-fix and passes post-fix.
Out of scope (deferred):
- Timechart depth-15 planner guard
- @timestamp:string schema regression in bin/auto-date-histogram
- list() time-only stringification (sandbox-side fix needed)
- chart timestamp-format and percentile algorithm shapes
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* test(sandbox): @AwaitsFix on tests that require sql cluster A/D
These tests pass when sql/fix/ai/cluster-all (commits 3a172a743 cluster A
and 2eebeddc cluster D) is installed; without those commits they fail with
substrait schema mismatches or unbound function-call lowerings.
Marking @AwaitsFix so the sandbox PR can merge before sql. Once sql PR is
merged, this commit should be reverted.
- DatetimeCoverageIT: 14 methods (cluster A span tests, cluster B/E/F
two-arg DATETIME, microsecond preservation, format token spec, etc.)
- DateTimeScalarFunctionsIT.testDateAddMillisecondIntervalOnTimestampColumn
- TimestampFunctionIT.testShapeCTimeLiteralFoldsWithTodayUtc
- TimestampFunctionIT.testTimeEqualsDateDoesNotCrash
- TwoShardCommandIT.testReduceCorrectnessAcrossTwoShards
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* PR comments
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
* DateOnly/TimeOnly UDTs carry source-type precision (dateβ3, date_nanosβ9)
The UDT branch in OpenSearchSchemaBuilder.buildLeafType bypassed the precision
switch added by #22049, so a date_nanos field with a date-only or time-only
mapping format produced TIMESTAMP(0). The schema/parquet-read mismatch surfaced
on multi-shard sort as RowConverter "Timestamp(ms) got Timestamp(ns)".
Thread the source-type precision through DateOnlyType / TimeOnlyType
constructors and append it to the digest so canonicalization keeps
date-precision-3 and date_nanos-precision-9 distinct (without the digest
change, type-factory caching collapses them).
Tests: 5 unit assertions in OpenSearchSchemaBuilderTests pinning the precision
contract for plain TIMESTAMP, DateOnlyType, and TimeOnlyType paths over both
date and date_nanos sources, plus DateNanosUDTPrecisionIT exercising the
2-shard sort regression end-to-end.
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
---------
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>1 parent 80bddcb commit 47a44bf
51 files changed
Lines changed: 3997 additions & 762 deletions
File tree
- sandbox
- libs/analytics-api/src/main/java/org/opensearch/analytics/schema
- plugins
- analytics-backend-datafusion
- rust/src/udf
- src
- main
- java/org/opensearch/be/datafusion
- resources
- test/java/org/opensearch/be/datafusion
- analytics-engine/src
- main/java/org/opensearch/analytics/exec
- test/java/org/opensearch/analytics
- engine
- exec
- qa
- analytics-engine-coordinator/src/internalClusterTest/java/org/opensearch/be/datafusion
- analytics-engine-rest/src/test/java/org/opensearch/analytics/qa
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 200 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
243 | 248 | | |
244 | 249 | | |
245 | 250 | | |
| |||
249 | 254 | | |
250 | 255 | | |
251 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
252 | 268 | | |
253 | 269 | | |
254 | 270 | | |
| |||
311 | 327 | | |
312 | 328 | | |
313 | 329 | | |
314 | | - | |
| 330 | + | |
| 331 | + | |
315 | 332 | | |
316 | 333 | | |
317 | 334 | | |
| |||
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| |||
0 commit comments