Commit d17aa3b
committed
Decouple PPL logical plans from UDT temporal types
Logical RelNode/RexNode trees now use standard Calcite DATE/TIME(9)/
TIMESTAMP(9) types for date columns. A new TemporalUdtRewriteShuttle
runs at the prepare-statement boundary (OpenSearchCalcitePreparingStmt
.implement and OpenSearchRelRunners.run) and rewrites the standard
temporal types back to UDTs (ExprDateType/ExprTimeType/ExprTimeStampType)
just before physical execution, so Linq4j keeps receiving the
VARCHAR-backed representation.
This commit folds in the prior "Decouple Calcite PPL planning from
ExprType" change as well: Calcite-side PPL planning (RelNode/RexNode
code, coercion, type checking, and UDF implementations) operates on
RelDataType throughout instead of bouncing through ExprType.
Type system:
- OpenSearchTypeFactory.convertExprTypeToRelDataType returns standard
TIMESTAMP(9)/DATE/TIME(9) for the corresponding ExprCoreType. IP and
BINARY remain UDT.
- New helper isStandardTemporalType.
- PPLOperandTypes constants renamed DATE_UDT/TIME_UDT/TIMESTAMP_UDT to
DATE_T/TIME_T/TIMESTAMP_T.
- UserDefinedFunctionUtils NULLABLE_*_UDT renamed to NULLABLE_*_T and
repointed to standard temporal RelDataTypes (IP and BINARY constants
unchanged).
- UDTs are recognised via instanceof rather than getExprType(); cloneWith
preserves UDT identity through createTypeWithNullability.
Cast emission and pushdown:
- CalciteRexNodeVisitor.visitCast emits standard temporal types for
AST DATE/TIME/TIMESTAMP cast targets.
- ExtendedRexBuilder.makeCast routes IP separately; standard temporal
targets dispatch to PPLBuiltinOperators.DATE/TIME/TIMESTAMP with the
standard target type so the call's RelDataType stays standard.
- PredicateAnalyzer.isTimestamp/isDate accept both standard SqlTypeName
and UDT, and read literal values via getValueAs(String.class) so
TimestampString/DateString round-trip without ClassCastException.
Coercion + type-checker:
- RelDataType-typed common-type resolver with a CoercionTag widening DAG.
- CoercionUtils' DATE+TIME -> TIMESTAMP resolver emits standard
TIMESTAMP(9).
- PPLTypeChecker gains a temporalKind helper used in typesMatch and
isComparable so standard and UDT temporal pairs match across forms.
- getRelDataTypes(family) returns standard temporal types for
DATETIME/TIMESTAMP/DATE/TIME families (BINARY family stays UDT).
- UDF return-type inference (AddSubDate/Weekday/LastDay/TimestampDiff
/Format/TimestampAdd/Extract/Span/WidthBucket) recognise both
standard and UDT temporal operand types.
Shuttle implementation:
- Atomic rebuild path for Project/Filter/Calc/Aggregate/Values nodes
(Calcite's default copy-then-validate path doesn't work because each
half of the rewrite would briefly violate row-type consistency).
- Filter rebuild preserves variablesSet so correlated subqueries keep
their CorrelationId binding.
- TemporalSchemaRewritable marker interface lets OpenSearch table
scans rewrite their schema in place rather than wrap in a
LogicalProject(CAST), so Calcite Linq4j codegen reads String values
matching what OpenSearchExprValueFactory delivers at runtime.
Other:
- DatetimeUdtNormalizeRule (api/datetime extension) recognises both
UDT and standard temporal RexCalls and forces precision to MAX so
unified-API consumers see TIMESTAMP(9).
- Calcite IT golden files updated to reflect logical plans now showing
TIMESTAMP(9) instead of EXPR_TIMESTAMP VARCHAR (physical plans still
show UDT post-shuttle).
Tests:
- New unit: TemporalUdtRewriteShuttleTest, CalcitePPLLogicalPlanStandardTemporalTest.
- Updated CoercionUtilsTest, OpenSearchTypeFactoryTest. All module unit
tests pass. Full Calcite IT suite (including ExplainIT) green.
Signed-off-by: Peng Huo <penghuo@gmail.com>1 parent 89d1040 commit d17aa3b
51 files changed
Lines changed: 1815 additions & 627 deletions
File tree
- api/src
- main/java/org/opensearch/sql/api/spec/datetime
- test/java/org/opensearch/sql/api
- core/src
- main/java/org/opensearch/sql
- calcite
- plan/rel
- type
- utils
- expression/function
- udf
- binning
- datetime
- ip
- test/java/org/opensearch/sql
- calcite
- plan/rel
- utils
- expression/function
- integ-test/src/test/resources/expectedOutput
- calcite_no_pushdown
- calcite
- opensearch/src
- main/java/org/opensearch/sql/opensearch
- functions
- request
- storage/scan
- test/java/org/opensearch/sql/opensearch/storage/serde
- ppl/src/test/java/org/opensearch/sql/ppl/calcite
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 13 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
Lines changed: 14 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
53 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
| |||
Lines changed: 0 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | 150 | | |
165 | 151 | | |
166 | 152 | | |
| |||
Lines changed: 24 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
819 | 820 | | |
820 | 821 | | |
821 | 822 | | |
822 | | - | |
823 | | - | |
824 | 823 | | |
825 | | - | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
826 | 847 | | |
827 | 848 | | |
828 | 849 | | |
| |||
Lines changed: 31 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
26 | 24 | | |
27 | | - | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
| |||
146 | 143 | | |
147 | 144 | | |
148 | 145 | | |
149 | | - | |
| 146 | + | |
150 | 147 | | |
151 | 148 | | |
152 | 149 | | |
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 | | - | |
| 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 | + | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| |||
Lines changed: 32 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 | + | |
0 commit comments