You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "starocean999 (via GitHub)" <gi...@apache.org> on 2026/04/15 09:35:10 UTC
[PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
starocean999 opened a new pull request, #62524:
URL: https://github.com/apache/doris/pull/62524
PR fixes two bugs:
(1) user/session variable integer typing was wrong when converted to Nereids literals;
(2) variable replacement timing could leave a Variable node present during early type-coercion (causing type errors).
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg: https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4285834515
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4265064561
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4417479119
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4411083131
<details>
<summary>TPC-DS: <b>Total hot run time: 170961 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 393f25681ab7f37db8ec4e10f8c7ec9d8117165c, data reload: false
query5 4322 651 504 504
query6 330 230 218 218
query7 4230 561 327 327
query8 340 245 228 228
query9 8842 4028 4045 4028
query10 463 357 308 308
query11 6049 2424 2198 2198
query12 194 134 131 131
query13 1311 614 440 440
query14 6709 5360 5085 5085
query14_1 4403 4400 4366 4366
query15 210 201 189 189
query16 1002 464 454 454
query17 1168 805 608 608
query18 2726 466 353 353
query19 214 193 161 161
query20 143 132 127 127
query21 216 135 113 113
query22 13669 13638 13439 13439
query23 17255 16273 16552 16273
query23_1 16374 16325 16305 16305
query24 7674 1837 1388 1388
query24_1 1405 1389 1410 1389
query25 553 531 450 450
query26 1358 335 175 175
query27 2915 642 382 382
query28 4459 1997 1964 1964
query29 1037 649 510 510
query30 295 234 194 194
query31 1124 1048 937 937
query32 87 71 71 71
query33 524 343 308 308
query34 1160 1150 636 636
query35 756 785 659 659
query36 1312 1330 1185 1185
query37 148 98 92 92
query38 3201 3103 3047 3047
query39 920 929 889 889
query39_1 867 862 862 862
query40 233 152 134 134
query41 64 61 59 59
query42 109 106 105 105
query43 314 331 289 289
query44
query45 237 207 194 194
query46 1015 1218 732 732
query47 2351 2278 2226 2226
query48 405 380 305 305
query49 639 534 422 422
query50 700 289 216 216
query51 4316 4270 4180 4180
query52 109 113 91 91
query53 253 281 203 203
query54 303 273 270 270
query55 93 87 82 82
query56 298 310 303 303
query57 1405 1379 1293 1293
query58 303 275 272 272
query59 1601 1607 1448 1448
query60 349 356 313 313
query61 161 151 156 151
query62 669 621 558 558
query63 250 198 200 198
query64 2333 816 681 681
query65
query66 1679 528 388 388
query67 30082 29968 29854 29854
query68
query69 475 342 304 304
query70 1062 1012 991 991
query71 325 288 275 275
query72 3054 2936 2638 2638
query73 833 759 445 445
query74 5145 4901 4744 4744
query75 2808 2683 2370 2370
query76 2287 1129 776 776
query77 435 428 364 364
query78 12862 13066 12449 12449
query79 1495 1042 696 696
query80 1451 568 502 502
query81 522 279 244 244
query82 1124 156 124 124
query83 356 274 248 248
query84 259 139 115 115
query85 922 518 460 460
query86 456 348 304 304
query87 3428 3368 3203 3203
query88 3525 2686 2683 2683
query89 437 382 340 340
query90 1892 189 180 180
query91 179 169 135 135
query92 80 79 72 72
query93 996 957 573 573
query94 709 360 291 291
query95 684 452 343 343
query96 992 742 371 371
query97 2727 2659 2596 2596
query98 242 234 249 234
query99 1096 1110 994 994
Total cold run time: 256047 ms
Total hot run time: 170961 ms
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4411057441
<details>
<summary>TPC-H: <b>Total hot run time: 29503 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 393f25681ab7f37db8ec4e10f8c7ec9d8117165c, data reload: false
------ Round 1 ----------------------------------
orders Doris NULL NULL 0 0 0 NULL 0 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 17693 3947 3874 3874
q2 q3 10723 868 594 594
q4 4663 456 338 338
q5 7436 1305 1121 1121
q6 179 165 139 139
q7 903 943 755 755
q8 9300 1396 1256 1256
q9 5598 5382 5338 5338
q10 6307 2065 1801 1801
q11 476 269 256 256
q12 694 421 299 299
q13 18202 3666 2766 2766
q14 292 285 263 263
q15 q16 894 863 791 791
q17 989 1014 741 741
q18 6350 5603 5628 5603
q19 1180 1246 1122 1122
q20 504 396 268 268
q21 4521 2297 1879 1879
q22 415 355 299 299
Total cold run time: 97319 ms
Total hot run time: 29503 ms
----- Round 2, with runtime_filter_mode=off -----
orders Doris NULL NULL 150000000 42 6422171781 NULL 22778155 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 4161 4073 4063 4063
q2 q3 4633 4732 4166 4166
q4 2086 2195 1361 1361
q5 4928 4964 5213 4964
q6 190 164 134 134
q7 2025 1740 1713 1713
q8 3528 3231 3167 3167
q9 8484 8470 8354 8354
q10 4472 4493 4232 4232
q11 626 429 408 408
q12 715 769 520 520
q13 3221 3610 2945 2945
q14 319 314 281 281
q15 q16 792 816 690 690
q17 1345 1297 1269 1269
q18 8273 7204 7112 7112
q19 1133 1146 1183 1146
q20 2241 2236 1927 1927
q21 6108 5447 4995 4995
q22 537 507 414 414
Total cold run time: 59817 ms
Total hot run time: 53861 ms
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4287090708
# FE UT Coverage Report
Increment line coverage ` 29.41% (40/136)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/62524_813996e80f30ffc937609ec065cf764ea5d18ffd/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/62524_813996e80f30ffc937609ec065cf764ea5d18ffd/fe_report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4294643861
# FE Regression Coverage Report
Increment line coverage ` 17.22% (94/546)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/62524_4b89fd42c8e8f167f1ac5ae01757e917e09b62e9_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/62524_4b89fd42c8e8f167f1ac5ae01757e917e09b62e9_merge_fe/report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3097768823
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -219,7 +219,18 @@ public Expression visit(Expression expr, ExpressionRewriteContext context) {
* ******************************************************************************************** */
@Override
public Expression visitUnboundVariable(UnboundVariable unboundVariable, ExpressionRewriteContext context) {
- return resolveUnboundVariable(unboundVariable);
+ Variable variable = resolveUnboundVariable(unboundVariable);
+ // Record used variable for SQL cache when context is available.
+ // Defensive null-check: some callers may invoke analysis without a full
+ // ExpressionRewriteContext (e.g. in isolated tests), so guard access.
+ if (context != null && context.cascadesContext != null) {
+ Optional<SqlCacheContext> sqlCacheContext = context.cascadesContext.getStatementContext()
+ .getSqlCacheContext();
+ if (sqlCacheContext.isPresent()) {
+ sqlCacheContext.get().addUsedVariable(variable);
+ }
+ }
+ return variable.getRealExpression();
Review Comment:
Returning the literal here changes the analyzed tree too early. `VariableToLiteral` already replaces variables later in analysis, but callers like `CreateTableInfo.generatedColumnCheck()` analyze first and only then reject `expr instanceof Variable` (`fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java:1187-1261`). With this change, a generated-column expression containing `@x` is accepted and the current session value gets baked into the persisted expression instead of being rejected.
```suggestion
return variable;
```
##########
fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java:
##########
@@ -88,6 +89,7 @@
import org.xnio.StreamConnection;
import java.io.IOException;
+import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
Review Comment:
This still widens `TINYINT`/`SMALLINT` user variables to `INTEGER`, so exact-width signatures remain broken. `SET @p = 3` stores a `TINYINT` via `LogicalPlanBuilder.visitIntegerLiteral()` and `TinyIntLiteral.toLegacyLiteral()`, but this branch still returns `Literal.of((int) ...)`, so `SELECT CURTIME(@p)` is analyzed as `current_time(INT)` and fails against the existing `current_time(TINYINT)` signature in `CurrentTime`. If the goal is to preserve the original integer type, the `TINYINT` and `SMALLINT` cases need explicit `byte`/`short` handling too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4386288553
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4265449123
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4394116079
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4251369225
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3127952896
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Uniform.java:
##########
@@ -60,10 +60,10 @@ private Uniform(ScalarFunctionParams functionParams) {
@Override
public void checkLegalityBeforeTypeCoercion() {
- if (!child(0).isLiteral()) {
+ if (!getArgument(0).isLiteral()) {
Review Comment:
This change fixes variable backed literals that should be accepted for `min` and `max`, but it also makes the inverse case reachable for `gen`. During binding, `checkLegalityBeforeTypeCoercion()` now unwraps `@min` and `@max` via `getArgument()`, then immediately calls `checkLegalityAfterRewrite()`, which still inspects raw `child(2)`. That means `SET @seed = 1; SELECT uniform(@lo, @hi, @seed)` now passes bind time validation even though the third parameter is logically literal. After the later `VariableToLiteral` pass the expression becomes `uniform(lit, lit, lit)`, and with `enable_fold_constant_by_be=true` the normalization phase can fold the whole call before `CheckLegalityAfterRewrite` runs, so the query succeeds instead of raising `The third parameter (gen) of uniform function must not be literal`. Please validate the third argument against the resolved argument too, or stop calling `checkLegalityAfterRewrite()` from the pre coercion path.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/AGENTS.md:
##########
@@ -0,0 +1,5 @@
+# Nereids expressions — Review Guide
Review Comment:
This new `AGENTS.md` file is unrelated to the user variable fix, and the repo guidance explicitly says `AGENTS.md` files should not be committed as part of a normal bugfix change. Please drop it from this PR so the change stays focused on the actual FE and test fixes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4286542770
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4287714313
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4310285837
PR approved by at least one committer and no changes requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4250926127
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4273026926
# FE Regression Coverage Report
Increment line coverage ` 60.00% (18/30)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/62524_45f8e3816329d8b1dad5baf01cdfff62a20314d6_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/62524_45f8e3816329d8b1dad5baf01cdfff62a20314d6_merge_fe/report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3115050448
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Random.java:
##########
@@ -97,7 +97,7 @@ private Random(UniqueFunctionParams functionParams) {
public void checkLegalityBeforeTypeCoercion() {
// align with original planner behavior, refer to:
// org/apache/doris/analysis/Expr.getBuiltinFunction()
- for (Expression child : children()) {
+ for (Expression child : getArguments()) {
Review Comment:
This still leaves `rand(@v)` / `random(@v)` broken. `BuiltinFunctionBuilder` instantiates the public `Random(Expression arg)` constructor before `processBoundFunction()` reaches this method, and that constructor still enforces `arg instanceof Literal`. So a variable-backed literal still fails on the raw `Variable` object before this new `getArguments()` path ever runs. The constructor path needs the same resolved-argument handling, or the literal check needs to move out of the constructor entirely.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StructElement.java:
##########
@@ -58,11 +58,13 @@ private StructElement(ScalarFunctionParams functionParams) {
@Override
public void checkLegalityBeforeTypeCoercion() {
- if (!(child(0).getDataType() instanceof StructType
- || child(0).getDataType() instanceof NullType)) {
+ Expression structArgument = getArgument(0);
+ Expression fieldArgument = getArgument(1);
+ if (!(structArgument.getDataType() instanceof StructType
+ || structArgument.getDataType() instanceof NullType)) {
SearchSignature.throwCanNotFoundFunctionException(this.getName(), this.getArguments());
}
- if (!(child(1) instanceof StringLikeLiteral || child(1) instanceof IntegerLikeLiteral)) {
+ if (!(fieldArgument instanceof StringLikeLiteral || fieldArgument instanceof IntegerLikeLiteral)) {
Review Comment:
This only fixes the early legality check. `getSignatures()` below still dispatches on raw `child(1)` and computes the return type from that raw node, while `BoundFunction.getSignature()` is invoked immediately after `checkLegalityBeforeTypeCoercion()` in `processBoundFunction()`, before `VariableToLiteral` runs. So `struct_element(..., @field_name)` and `struct_element(..., @idx)` still fall into the final `AnalysisException` path instead of using the variable real literal. The return-type/signature path needs to use `getArgument(...)` consistently too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4310589997
# FE UT Coverage Report
Increment line coverage ` 24.41% (31/127)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/62524_19a78b8e2e99903c6a93ea93534a0b74ac9ed4e8/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/62524_19a78b8e2e99903c6a93ea93534a0b74ac9ed4e8/fe_report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4250926079
Thank you for your contribution to Apache Doris.
Don't know what should be done next? See [How to process your PR](https://cwiki.apache.org/confluence/display/DORIS/How+to+process+your+PR).
Please clearly describe your PR:
1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
3. What features were added. Why was this function added?
4. Which code was refactored and why was this part of the code refactored?
5. Which functions were optimized and what is the difference before and after the optimization?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4410992492
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4286421159
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4310830824
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3085902295
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -219,7 +219,18 @@ public Expression visit(Expression expr, ExpressionRewriteContext context) {
* ******************************************************************************************** */
@Override
public Expression visitUnboundVariable(UnboundVariable unboundVariable, ExpressionRewriteContext context) {
- return resolveUnboundVariable(unboundVariable);
+ Variable variable = resolveUnboundVariable(unboundVariable);
+ // Record used variable for SQL cache when context is available.
+ // Defensive null-check: some callers may invoke analysis without a full
+ // ExpressionRewriteContext (e.g. in isolated tests), so guard access.
+ if (context != null && context.cascadesContext != null) {
+ Optional<SqlCacheContext> sqlCacheContext = context.cascadesContext.getStatementContext()
+ .getSqlCacheContext();
+ if (sqlCacheContext.isPresent()) {
+ sqlCacheContext.get().addUsedVariable(variable);
+ }
+ }
Review Comment:
This changes `UnboundVariable` analysis from producing a `Variable` node to producing its literal value immediately. That fixes the early type-coercion problem, but it also removes `Variable` from every analyzed tree, which breaks downstream semantic checks that intentionally inspect analyzed expressions for `Variable`. One concrete case is generated columns: `CreateTableInfo` analyzes the expression first and only then rejects `instanceof Variable` (`checkExpressionInGeneratedColumn()`), so after this change a generated column like `c AS (@x + 1)` can slip through as a plain literal expression instead of being rejected. The old flow kept the `Variable` until the later `VariableToLiteral` rule, so that check still worked. Please either preserve `Variable` until those validations finish, or move the generated-column variable rejection earlier and add coverage for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4386088209
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4386430550
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 merged PR #62524:
URL: https://github.com/apache/doris/pull/62524
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4417481716
PR approved by at least one committer and no changes requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3098528650
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java:
##########
@@ -46,23 +47,58 @@ default void checkLegalityBeforeTypeCoercion() {}
@Developing
default void checkLegalityAfterRewrite() {}
+ /**
+ * getArguments.
+ */
default List<Expression> getArguments() {
- return children();
Review Comment:
Unwrapping `Variable` here only fixes callers that already use `getArgument*()` / `getArguments*()`. A lot of function legality/signature code still reads raw `child()` nodes before the later `VariableToLiteral` analyzer rule runs, so the same user-variable bug is still present there. Concrete example: `SELECT UTC_TIMESTAMP(@p)` with `@p = 3` still fails, because `visitUnboundVariable()` returns `Variable(realExpression=literal)`, `visitUnboundFunction()` builds `UtcTimestamp(Variable)`, and then `TypeCoercionUtils.processBoundFunction()` immediately calls `UtcTimestamp.checkLegalityBeforeTypeCoercion()`, which rejects `!child(0).isLiteral()`. The same pattern exists in `utc_time`, `uniform`, `width_bucket`, etc. I think this needs to be fixed earlier in the bind/type-check path, or those raw-child checks need to be updated as well; otherwise this patch only fixes the `window_funnel`-style subset of functions.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java:
##########
@@ -587,10 +589,23 @@ public void setUserVar(String name, LiteralExpr value) {
LiteralExpr literalExpr = userVars.get(varName);
if (literalExpr instanceof BoolLiteral) {
return Literal.of(((BoolLiteral) literalExpr).getValue());
- } else if (literalExpr instanceof IntLiteral) {
+ } else if (literalExpr instanceof IntLiteral || literalExpr instanceof LargeIntLiteral) {
// the value in the IntLiteral should be int, but now is long in old planner literalExpr
// so type coercion to generate right new planner int Literal
Review Comment:
This fix still misses the forwarded-FE path. `getLiteralForUserVar()` now relies on the stored legacy literal keeping its original primitive type, but `FEOpExecutor.getForwardUserVariables()` serializes all of `TINYINT/SMALLINT/INT/BIGINT` as `INT_LITERAL`, and `ConnectProcessor.getLiteralExprFromThrift()` reconstructs that as `new IntLiteral(value)` while ignoring `node.type`. So `SET @v = CAST(1 AS BIGINT)` executed through an observer/follower still degrades to a TINYINT before this method runs. `ExprToThriftVisitor` already sends `msg.type`, so the real fix needs to preserve that type when rebuilding the legacy `IntLiteral`; otherwise the integer-typing bug remains on forwarded queries.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4272582896
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4272787361
# FE UT Coverage Report
Increment line coverage ` 90.00% (27/30)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/62524_45f8e3816329d8b1dad5baf01cdfff62a20314d6/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/62524_45f8e3816329d8b1dad5baf01cdfff62a20314d6/fe_report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3115612427
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java:
##########
@@ -46,23 +47,58 @@ default void checkLegalityBeforeTypeCoercion() {}
@Developing
default void checkLegalityAfterRewrite() {}
+ /**
+ * getArguments.
+ */
default List<Expression> getArguments() {
- return children();
Review Comment:
Unwrapping `Variable.realExpression` here only fixes callers that already go through `getArgument*()` / `getArguments*()`. The analyzer still binds functions before the later `VariableToLiteral` pass (`Analyzer` runs `BindExpression` first), and there are still reachable bind-time checks that inspect raw `child()` nodes for literal-ness. A concrete example at current head is `SET @p = 3; SELECT utc_timestamp(@p)`: `visitUnboundVariable()` returns `Variable(realExpression=literal)`, `visitUnboundFunction()` immediately calls `TypeCoercionUtils.processBoundFunction()`, and `UtcTimestamp.checkLegalityAfterRewrite()` still rejects `!child(0).isLiteral()`. So this patch fixes helper-based paths like `window_funnel`, but not the general Variable->literal timing problem described in the PR.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java:
##########
@@ -587,10 +589,23 @@ public void setUserVar(String name, LiteralExpr value) {
LiteralExpr literalExpr = userVars.get(varName);
if (literalExpr instanceof BoolLiteral) {
return Literal.of(((BoolLiteral) literalExpr).getValue());
- } else if (literalExpr instanceof IntLiteral) {
+ } else if (literalExpr instanceof IntLiteral || literalExpr instanceof LargeIntLiteral) {
// the value in the IntLiteral should be int, but now is long in old planner literalExpr
// so type coercion to generate right new planner int Literal
Review Comment:
This still leaves the forwarded-FE path inconsistent. `getLiteralForUserVar()` now relies on the stored legacy literal preserving its original primitive subtype, but `FEOpExecutor.getForwardUserVariables()` serializes user vars through `ExprToThriftVisitor.treeToThrift()`, and `ConnectProcessor.getLiteralExprFromThrift()` still reconstructs every `INT_LITERAL` as `new IntLiteral(node.int_literal.value)` while ignoring `node.type`. So a query forwarded through an observer/follower can still turn `CAST(1 AS BIGINT)` or a typed `SMALLINT`/`TINYINT` user var back into the narrowest inferred legacy `IntLiteral` before this switch runs, which reintroduces the original bug on that path. Please preserve `node.type` when rebuilding forwarded integer literals.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4288529834
# FE Regression Coverage Report
Increment line coverage ` 69.12% (94/136)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/62524_4b89fd42c8e8f167f1ac5ae01757e917e09b62e9_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/62524_4b89fd42c8e8f167f1ac5ae01757e917e09b62e9_merge_fe/report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3135163213
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java:
##########
@@ -46,23 +47,58 @@ default void checkLegalityBeforeTypeCoercion() {}
@Developing
default void checkLegalityAfterRewrite() {}
+ /**
+ * getArguments.
+ */
default List<Expression> getArguments() {
- return children();
+ ImmutableList.Builder<Expression> arguments = ImmutableList.builder();
+ for (Expression arg : children()) {
+ if (arg instanceof Variable && ((Variable) arg).getRealExpression() != null) {
+ arguments.add(((Variable) arg).getRealExpression());
+ } else {
+ arguments.add(arg);
+ }
+ }
+ return arguments.build();
}
+ /**
+ * getArgument.
+ */
default Expression getArgument(int index) {
- return child(index);
+ Expression arg = child(index);
+ if (arg instanceof Variable && ((Variable) arg).getRealExpression() != null) {
+ return ((Variable) arg).getRealExpression();
+ } else {
+ return arg;
+ }
}
+ /**
+ * getArgumentsTypes.
+ */
default List<DataType> getArgumentsTypes() {
Review Comment:
this `function` and `getArgumentType(int index)` should not require any modification
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java:
##########
@@ -46,23 +47,58 @@ default void checkLegalityBeforeTypeCoercion() {}
@Developing
default void checkLegalityAfterRewrite() {}
+ /**
+ * getArguments.
+ */
default List<Expression> getArguments() {
- return children();
+ ImmutableList.Builder<Expression> arguments = ImmutableList.builder();
+ for (Expression arg : children()) {
Review Comment:
If the variable does not exist, then do not return a new list object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3098155696
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/UserVariableAnalysisTest.java:
##########
@@ -0,0 +1,109 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.analysis;
+
+import org.apache.doris.analysis.IntLiteral;
+import org.apache.doris.analysis.LargeIntLiteral;
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.analyzer.UnboundVariable;
+import org.apache.doris.nereids.analyzer.UnboundVariable.VariableType;
+import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
+import org.apache.doris.nereids.trees.expressions.ComparisonPredicate;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Variable;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.LargeIntType;
+import org.apache.doris.nereids.util.MemoTestUtils;
+import org.apache.doris.qe.ConnectContext;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+/** Tests for user variable handling in expression analysis. */
+public class UserVariableAnalysisTest {
+
+ @Test
+ public void testUserVarIntegerTypeSmall() {
+ ConnectContext ctx = MemoTestUtils.createConnectContext();
+ // set user var @a = 1 (small int)
+ ctx.setUserVar("a", new IntLiteral(1L));
+
+ // get nereids literal via ConnectContext helper
+ Literal l = ConnectContext.get().getLiteralForUserVar("a");
+ Assertions.assertNotNull(l);
+ Assertions.assertEquals(IntegerType.INSTANCE, l.getDataType());
Review Comment:
`new IntLiteral(1L)` is a legacy `TINYINT`, not an `INT` (`IntLiteral.init()` picks the smallest fitting width). With the new `ConnectContext` logic this now becomes a `TinyIntLiteral`, so this assertion is expecting the pre-fix behavior and will fail once FE UTs are run. If the intent is to verify `INT`, construct the legacy literal with `Type.INT`; otherwise assert `TinyIntType`.
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/UserVariableAnalysisTest.java:
##########
@@ -0,0 +1,109 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.analysis;
+
+import org.apache.doris.analysis.IntLiteral;
+import org.apache.doris.analysis.LargeIntLiteral;
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.analyzer.UnboundVariable;
+import org.apache.doris.nereids.analyzer.UnboundVariable.VariableType;
+import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
+import org.apache.doris.nereids.trees.expressions.ComparisonPredicate;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Variable;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.LargeIntType;
+import org.apache.doris.nereids.util.MemoTestUtils;
+import org.apache.doris.qe.ConnectContext;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+/** Tests for user variable handling in expression analysis. */
+public class UserVariableAnalysisTest {
+
+ @Test
+ public void testUserVarIntegerTypeSmall() {
+ ConnectContext ctx = MemoTestUtils.createConnectContext();
+ // set user var @a = 1 (small int)
+ ctx.setUserVar("a", new IntLiteral(1L));
+
+ // get nereids literal via ConnectContext helper
+ Literal l = ConnectContext.get().getLiteralForUserVar("a");
+ Assertions.assertNotNull(l);
+ Assertions.assertEquals(IntegerType.INSTANCE, l.getDataType());
+ }
+
+ @Test
+ public void testUserVarIntegerTypeBig() {
+ ConnectContext ctx = MemoTestUtils.createConnectContext();
+ // set user var @b = Long.MAX_VALUE (bigint)
+ ctx.setUserVar("b", new IntLiteral(Long.MAX_VALUE));
+
+ Literal l = ConnectContext.get().getLiteralForUserVar("b");
+ Assertions.assertNotNull(l);
+ Assertions.assertEquals(BigIntType.INSTANCE, l.getDataType());
+ }
+
+ @Test
+ public void testUserVarIntegerTypeLarge() {
+ ConnectContext ctx = MemoTestUtils.createConnectContext();
+ // set user var @b = Long.MAX_VALUE (bigint)
+ ctx.setUserVar("c", new LargeIntLiteral(LargeIntLiteral.LARGE_INT_MAX));
+
+ Literal l = ConnectContext.get().getLiteralForUserVar("c");
+ Assertions.assertNotNull(l);
+ Assertions.assertEquals(LargeIntType.INSTANCE, l.getDataType());
+ }
+
+ @Test
+ public void testVariableRecordedAndTypeCoercion() {
+ // create context and cascades context (sql cache enabled by default in test utils)
+ ConnectContext ctx = MemoTestUtils.createConnectContext();
+ ctx.setUserVar("uvar", new IntLiteral(42L));
+
+ // create a comparison using an unbound user variable: @uvar = 1
+ UnboundVariable unboundVar = new UnboundVariable(
+ "uvar", VariableType.USER);
+ IntegerLiteral right = new IntegerLiteral(1);
+ ComparisonPredicate cmp = new EqualTo(unboundVar, right);
+
+ // prepare analyzer with cascades context so sql cache context exists
+ CascadesContext cascadesContext = MemoTestUtils.createCascadesContext(ctx, "select 1");
+ ExpressionAnalyzer analyzer = new ExpressionAnalyzer(null,
+ new org.apache.doris.nereids.analyzer.Scope(java.util.Collections.emptyList()),
+ cascadesContext, false, false);
+ ExpressionRewriteContext rewriteContext = new ExpressionRewriteContext(cascadesContext);
+
+ // analyze should not throw and should handle type coercion
+ Expression analyzed = analyzer.analyze(cmp, rewriteContext);
+ Assertions.assertNotNull(analyzed);
+
+ // sql cache context should have recorded the used variable
+ List<Variable> used = cascadesContext.getStatementContext().getSqlCacheContext().get().getUsedVariables();
Review Comment:
This test no longer matches the final implementation. The patch removed SQL-cache recording from `ExpressionAnalyzer.visitUnboundVariable()` and only `ReplaceVariableByLiteral` calls `sqlCacheContext.addUsedVariable(...)`. `ExpressionAnalyzer.analyze(cmp, rewriteContext)` never runs that rewrite, so `usedVariables` stays empty here. To test SQL-cache recording you need to run the analyzer job / `VariableToLiteral` pass, or explicitly rewrite `analyzed` with `ReplaceVariableByLiteral` before asserting.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java:
##########
@@ -46,23 +47,58 @@ default void checkLegalityBeforeTypeCoercion() {}
@Developing
default void checkLegalityAfterRewrite() {}
+ /**
+ * getArguments.
+ */
default List<Expression> getArguments() {
- return children();
+ ImmutableList.Builder<Expression> arguments = ImmutableList.builder();
+ for (Expression arg : children()) {
+ if (arg instanceof Variable && ((Variable) arg).getRealExpression() != null) {
Review Comment:
This only fixes callers that go through `getArguments*()`, but `BindExpression` still binds functions before the later `VariableToLiteral` analyzer pass runs. That means any function that validates raw `child()` nodes still hits the same timing bug. A concrete reachable example is `SET @p = 3; SELECT utc_time(@p)` (also `utc_timestamp(@p)` and `char(@cs, 65)`): `ExpressionAnalyzer.visitUnboundFunction()` immediately calls `TypeCoercionUtils.processBoundFunction()`, and those implementations still check `child(0).isLiteral()` / `instanceof StringLikeLiteral`, so they reject the `Variable` wrapper before this helper is ever consulted. So this fixes helper-based callers like `window_funnel`, but not the general Variable->literal timing issue described in the PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4266025151
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prevent Variable->literal timing issue in expression analysis [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62524:
URL: https://github.com/apache/doris/pull/62524#discussion_r3085516907
##########
fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java:
##########
@@ -88,6 +88,7 @@
import org.xnio.StreamConnection;
import java.io.IOException;
+import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
Review Comment:
Blocking: this `LARGEINT` arm is unreachable in the actual user-variable flow. `SetUserDefinedVarOp.run()` stores values via `value.toLegacyLiteral()`, and a Nereids `LargeIntLiteral` becomes `org.apache.doris.analysis.LargeIntLiteral`, not `IntLiteral`. That means `SET @v = 9223372036854775808` still falls through to the final `else` here and is converted to a string literal instead of a Nereids `LargeIntLiteral`. Please handle legacy `LargeIntLiteral` explicitly (or reuse `Literal.fromLegacyLiteral(literalExpr, literalExpr.getType())` for the numeric branches).`
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/UserVariableAnalysisTest.java:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.analysis;
+
+import org.apache.doris.analysis.IntLiteral;
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.analyzer.UnboundVariable;
+import org.apache.doris.nereids.analyzer.UnboundVariable.VariableType;
+import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
+import org.apache.doris.nereids.trees.expressions.ComparisonPredicate;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Variable;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.util.MemoTestUtils;
+import org.apache.doris.qe.ConnectContext;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+/** Tests for user variable handling in expression analysis. */
+public class UserVariableAnalysisTest {
+
+ @Test
+ public void testUserVarIntegerTypeSmall() {
+ ConnectContext ctx = MemoTestUtils.createConnectContext();
+ // set user var @a = 1 (small int)
+ ctx.setUserVar("a", new IntLiteral(1L));
+
+ // get nereids literal via ConnectContext helper
+ Literal l = ConnectContext.get().getLiteralForUserVar("a");
+ Assertions.assertNotNull(l);
+ Assertions.assertEquals(IntegerType.INSTANCE, l.getDataType());
+ }
+
+ @Test
+ public void testUserVarIntegerTypeBig() {
Review Comment:
`Long.MAX_VALUE` is still a legacy `IntLiteral` with `BIGINT` type, so this test never exercises the newly added `LARGEINT` path. Please add a case using a real legacy `org.apache.doris.analysis.LargeIntLiteral` (for example `"9223372036854775808"`), otherwise the remaining bug in `getLiteralForUserVar()` will not be caught.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4310345919
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4310872290
# FE Regression Coverage Report
Increment line coverage ` 67.42% (89/132)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/62524_19a78b8e2e99903c6a93ea93534a0b74ac9ed4e8_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/62524_19a78b8e2e99903c6a93ea93534a0b74ac9ed4e8_merge_fe/report/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4394116079
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4301177235
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [fix](user_var)fix integer typing and prefer Variable.realExpression for argument/type resolution [doris]
Posted by "starocean999 (via GitHub)" <gi...@apache.org>.
starocean999 commented on PR #62524:
URL: https://github.com/apache/doris/pull/62524#issuecomment-4285829765
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org