Skip to content

Commit 632e681

Browse files
mihailotim-dbcloud-fan
authored andcommitted
[SPARK-51820][SQL][FOLLOWUP] Fix origin for UnresolvedOrdinal
### What changes were proposed in this pull request? This is a followup to #50606 to fix the origin and context of newly created `UnresolvedOrdinal`. ### Why are the changes needed? Origin and context of `UnresolvedOrdinal` should be the same as for the original `Literal`. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? No Closes #50676 from mihailotim-db/mihailotim-db/fix_origin. Authored-by: Mihailo Timotic <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 920634a commit 632e681

File tree

8 files changed

+64
-63
lines changed

8 files changed

+64
-63
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6615,7 +6615,8 @@ class AstBuilder extends DataTypeAstBuilder
66156615
private def replaceIntegerLiteralWithOrdinal(
66166616
expression: Expression,
66176617
canReplaceWithOrdinal: Boolean = true) = expression match {
6618-
case Literal(value: Int, IntegerType) if canReplaceWithOrdinal => UnresolvedOrdinal(value)
6618+
case literal @ Literal(value: Int, IntegerType) if canReplaceWithOrdinal =>
6619+
CurrentOrigin.withOrigin(literal.origin) { UnresolvedOrdinal(value) }
66196620
case other => other
66206621
}
66216622

sql/core/src/test/resources/sql-tests/analyzer-results/group-by-ordinal.sql.out

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ org.apache.spark.sql.AnalysisException
120120
"queryContext" : [ {
121121
"objectType" : "",
122122
"objectName" : "",
123-
"startIndex" : 23,
123+
"startIndex" : 32,
124124
"stopIndex" : 33,
125-
"fragment" : "group by -1"
125+
"fragment" : "-1"
126126
} ]
127127
}
128128

@@ -141,9 +141,9 @@ org.apache.spark.sql.AnalysisException
141141
"queryContext" : [ {
142142
"objectType" : "",
143143
"objectName" : "",
144-
"startIndex" : 23,
144+
"startIndex" : 32,
145145
"stopIndex" : 32,
146-
"fragment" : "group by 0"
146+
"fragment" : "0"
147147
} ]
148148
}
149149

@@ -162,9 +162,9 @@ org.apache.spark.sql.AnalysisException
162162
"queryContext" : [ {
163163
"objectType" : "",
164164
"objectName" : "",
165-
"startIndex" : 23,
165+
"startIndex" : 32,
166166
"stopIndex" : 32,
167-
"fragment" : "group by 3"
167+
"fragment" : "3"
168168
} ]
169169
}
170170

@@ -183,9 +183,9 @@ org.apache.spark.sql.AnalysisException
183183
"queryContext" : [ {
184184
"objectType" : "",
185185
"objectName" : "",
186-
"startIndex" : 31,
186+
"startIndex" : 40,
187187
"stopIndex" : 40,
188-
"fragment" : "group by 3"
188+
"fragment" : "3"
189189
} ]
190190
}
191191

@@ -204,9 +204,9 @@ org.apache.spark.sql.AnalysisException
204204
"queryContext" : [ {
205205
"objectType" : "",
206206
"objectName" : "",
207-
"startIndex" : 35,
207+
"startIndex" : 44,
208208
"stopIndex" : 44,
209-
"fragment" : "group by 3"
209+
"fragment" : "3"
210210
} ]
211211
}
212212

@@ -401,9 +401,9 @@ org.apache.spark.sql.AnalysisException
401401
"queryContext" : [ {
402402
"objectType" : "",
403403
"objectName" : "",
404-
"startIndex" : 33,
404+
"startIndex" : 45,
405405
"stopIndex" : 46,
406-
"fragment" : "group by a, -1"
406+
"fragment" : "-1"
407407
} ]
408408
}
409409

@@ -422,9 +422,9 @@ org.apache.spark.sql.AnalysisException
422422
"queryContext" : [ {
423423
"objectType" : "",
424424
"objectName" : "",
425-
"startIndex" : 33,
425+
"startIndex" : 45,
426426
"stopIndex" : 45,
427-
"fragment" : "group by a, 3"
427+
"fragment" : "3"
428428
} ]
429429
}
430430

@@ -443,9 +443,9 @@ org.apache.spark.sql.AnalysisException
443443
"queryContext" : [ {
444444
"objectType" : "",
445445
"objectName" : "",
446-
"startIndex" : 33,
447-
"stopIndex" : 52,
448-
"fragment" : "group by cube(-1, 2)"
446+
"startIndex" : 47,
447+
"stopIndex" : 48,
448+
"fragment" : "-1"
449449
} ]
450450
}
451451

@@ -464,9 +464,9 @@ org.apache.spark.sql.AnalysisException
464464
"queryContext" : [ {
465465
"objectType" : "",
466466
"objectName" : "",
467-
"startIndex" : 33,
468-
"stopIndex" : 51,
469-
"fragment" : "group by cube(1, 3)"
467+
"startIndex" : 50,
468+
"stopIndex" : 50,
469+
"fragment" : "3"
470470
} ]
471471
}
472472

sql/core/src/test/resources/sql-tests/analyzer-results/postgreSQL/select_implicit.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ org.apache.spark.sql.AnalysisException
197197
"queryContext" : [ {
198198
"objectType" : "",
199199
"objectName" : "",
200-
"startIndex" : 45,
200+
"startIndex" : 54,
201201
"stopIndex" : 54,
202-
"fragment" : "GROUP BY 3"
202+
"fragment" : "3"
203203
} ]
204204
}
205205

sql/core/src/test/resources/sql-tests/analyzer-results/udf/postgreSQL/udf-select_implicit.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ org.apache.spark.sql.AnalysisException
200200
"queryContext" : [ {
201201
"objectType" : "",
202202
"objectName" : "",
203-
"startIndex" : 55,
203+
"startIndex" : 64,
204204
"stopIndex" : 64,
205-
"fragment" : "GROUP BY 3"
205+
"fragment" : "3"
206206
} ]
207207
}
208208

sql/core/src/test/resources/sql-tests/results/group-by-ordinal.sql.out

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ org.apache.spark.sql.AnalysisException
102102
"queryContext" : [ {
103103
"objectType" : "",
104104
"objectName" : "",
105-
"startIndex" : 23,
105+
"startIndex" : 32,
106106
"stopIndex" : 33,
107-
"fragment" : "group by -1"
107+
"fragment" : "-1"
108108
} ]
109109
}
110110

@@ -125,9 +125,9 @@ org.apache.spark.sql.AnalysisException
125125
"queryContext" : [ {
126126
"objectType" : "",
127127
"objectName" : "",
128-
"startIndex" : 23,
128+
"startIndex" : 32,
129129
"stopIndex" : 32,
130-
"fragment" : "group by 0"
130+
"fragment" : "0"
131131
} ]
132132
}
133133

@@ -148,9 +148,9 @@ org.apache.spark.sql.AnalysisException
148148
"queryContext" : [ {
149149
"objectType" : "",
150150
"objectName" : "",
151-
"startIndex" : 23,
151+
"startIndex" : 32,
152152
"stopIndex" : 32,
153-
"fragment" : "group by 3"
153+
"fragment" : "3"
154154
} ]
155155
}
156156

@@ -171,9 +171,9 @@ org.apache.spark.sql.AnalysisException
171171
"queryContext" : [ {
172172
"objectType" : "",
173173
"objectName" : "",
174-
"startIndex" : 31,
174+
"startIndex" : 40,
175175
"stopIndex" : 40,
176-
"fragment" : "group by 3"
176+
"fragment" : "3"
177177
} ]
178178
}
179179

@@ -194,9 +194,9 @@ org.apache.spark.sql.AnalysisException
194194
"queryContext" : [ {
195195
"objectType" : "",
196196
"objectName" : "",
197-
"startIndex" : 35,
197+
"startIndex" : 44,
198198
"stopIndex" : 44,
199-
"fragment" : "group by 3"
199+
"fragment" : "3"
200200
} ]
201201
}
202202

@@ -432,9 +432,9 @@ org.apache.spark.sql.AnalysisException
432432
"queryContext" : [ {
433433
"objectType" : "",
434434
"objectName" : "",
435-
"startIndex" : 33,
435+
"startIndex" : 45,
436436
"stopIndex" : 46,
437-
"fragment" : "group by a, -1"
437+
"fragment" : "-1"
438438
} ]
439439
}
440440

@@ -455,9 +455,9 @@ org.apache.spark.sql.AnalysisException
455455
"queryContext" : [ {
456456
"objectType" : "",
457457
"objectName" : "",
458-
"startIndex" : 33,
458+
"startIndex" : 45,
459459
"stopIndex" : 45,
460-
"fragment" : "group by a, 3"
460+
"fragment" : "3"
461461
} ]
462462
}
463463

@@ -478,9 +478,9 @@ org.apache.spark.sql.AnalysisException
478478
"queryContext" : [ {
479479
"objectType" : "",
480480
"objectName" : "",
481-
"startIndex" : 33,
482-
"stopIndex" : 52,
483-
"fragment" : "group by cube(-1, 2)"
481+
"startIndex" : 47,
482+
"stopIndex" : 48,
483+
"fragment" : "-1"
484484
} ]
485485
}
486486

@@ -501,9 +501,9 @@ org.apache.spark.sql.AnalysisException
501501
"queryContext" : [ {
502502
"objectType" : "",
503503
"objectName" : "",
504-
"startIndex" : 33,
505-
"stopIndex" : 51,
506-
"fragment" : "group by cube(1, 3)"
504+
"startIndex" : 50,
505+
"stopIndex" : 50,
506+
"fragment" : "3"
507507
} ]
508508
}
509509

sql/core/src/test/resources/sql-tests/results/postgreSQL/select_implicit.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ org.apache.spark.sql.AnalysisException
224224
"queryContext" : [ {
225225
"objectType" : "",
226226
"objectName" : "",
227-
"startIndex" : 45,
227+
"startIndex" : 54,
228228
"stopIndex" : 54,
229-
"fragment" : "GROUP BY 3"
229+
"fragment" : "3"
230230
} ]
231231
}
232232

sql/core/src/test/resources/sql-tests/results/udaf/udaf-group-by-ordinal.sql.out

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ org.apache.spark.sql.AnalysisException
102102
"queryContext" : [ {
103103
"objectType" : "",
104104
"objectName" : "",
105-
"startIndex" : 32,
105+
"startIndex" : 41,
106106
"stopIndex" : 41,
107-
"fragment" : "group by 3"
107+
"fragment" : "3"
108108
} ]
109109
}
110110

@@ -125,9 +125,9 @@ org.apache.spark.sql.AnalysisException
125125
"queryContext" : [ {
126126
"objectType" : "",
127127
"objectName" : "",
128-
"startIndex" : 36,
128+
"startIndex" : 45,
129129
"stopIndex" : 45,
130-
"fragment" : "group by 3"
130+
"fragment" : "3"
131131
} ]
132132
}
133133

@@ -351,9 +351,9 @@ org.apache.spark.sql.AnalysisException
351351
"queryContext" : [ {
352352
"objectType" : "",
353353
"objectName" : "",
354-
"startIndex" : 32,
354+
"startIndex" : 44,
355355
"stopIndex" : 45,
356-
"fragment" : "group by a, -1"
356+
"fragment" : "-1"
357357
} ]
358358
}
359359

@@ -374,9 +374,9 @@ org.apache.spark.sql.AnalysisException
374374
"queryContext" : [ {
375375
"objectType" : "",
376376
"objectName" : "",
377-
"startIndex" : 32,
377+
"startIndex" : 44,
378378
"stopIndex" : 44,
379-
"fragment" : "group by a, 3"
379+
"fragment" : "3"
380380
} ]
381381
}
382382

@@ -397,9 +397,9 @@ org.apache.spark.sql.AnalysisException
397397
"queryContext" : [ {
398398
"objectType" : "",
399399
"objectName" : "",
400-
"startIndex" : 32,
401-
"stopIndex" : 51,
402-
"fragment" : "group by cube(-1, 2)"
400+
"startIndex" : 46,
401+
"stopIndex" : 47,
402+
"fragment" : "-1"
403403
} ]
404404
}
405405

@@ -420,9 +420,9 @@ org.apache.spark.sql.AnalysisException
420420
"queryContext" : [ {
421421
"objectType" : "",
422422
"objectName" : "",
423-
"startIndex" : 32,
424-
"stopIndex" : 50,
425-
"fragment" : "group by cube(1, 3)"
423+
"startIndex" : 49,
424+
"stopIndex" : 49,
425+
"fragment" : "3"
426426
} ]
427427
}
428428

sql/core/src/test/resources/sql-tests/results/udf/postgreSQL/udf-select_implicit.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ org.apache.spark.sql.AnalysisException
227227
"queryContext" : [ {
228228
"objectType" : "",
229229
"objectName" : "",
230-
"startIndex" : 55,
230+
"startIndex" : 64,
231231
"stopIndex" : 64,
232-
"fragment" : "GROUP BY 3"
232+
"fragment" : "3"
233233
} ]
234234
}
235235

0 commit comments

Comments
 (0)