From ec89f1b82104cf844fe59d3a16581142a3a7c66c Mon Sep 17 00:00:00 2001 From: Tanya Gupta Date: Wed, 5 Feb 2025 05:22:19 +0000 Subject: [PATCH] updating test Signed-off-by: Tanya Gupta --- .../src/backend/tds/tdsresponse.c | 121 +-- contrib/babelfishpg_tsql/src/pltsql_coerce.c | 2 - .../expected/BABEL-NUMERIC_EXPR-vu-verify.out | 274 +++---- test/JDBC/expected/babel-5454.out | 773 ------------------ test/JDBC/upgrade/latest/schedule | 1 + 5 files changed, 140 insertions(+), 1031 deletions(-) delete mode 100644 test/JDBC/expected/babel-5454.out diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c index 8427146f7e0..20d4f56b629 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c @@ -427,112 +427,6 @@ PrintTupPrepareInfo(DR_printtup *myState, TupleDesc typeinfo, int numAttrs) } } -static int32 -resolve_numeric_typmod_from_append_or_mergeappend(Plan *plan, AttrNumber attno) -{ - ListCell *lc; - int32 max_precision = 0, - max_scale = 0, - precision = 0, - scale = 0, - integralDigitCount = 0, - typmod = -1, - result_typmod = -1; - List *planlist = NIL; - if (IsA(plan, Append)) - { - planlist = ((Append *) plan)->appendplans; - } - else if(IsA(plan, MergeAppend)) - { - planlist = ((MergeAppend *) plan)->mergeplans; - } - - Assert(planlist != NIL); - foreach(lc, planlist) - { - TargetEntry *tle; - Plan *outerplan = (Plan *) lfirst(lc); - - /* if outerplan is SubqueryScan then use actual subplan */ - if (IsA(outerplan, SubqueryScan)) - outerplan = ((SubqueryScan *)outerplan)->subplan; - - tle = get_tle_by_resno(outerplan->targetlist, attno); - if (IsA(tle->expr, Var)) - { - Var *var = (Var *)tle->expr; - if (var->varno == OUTER_VAR) - { - typmod = resolve_numeric_typmod_outer_var(outerplan, var->varattno); - } - else - { - typmod = resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); - } - } - else - { - typmod = resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); - } - if (typmod == -1) - continue; - scale = (typmod - VARHDRSZ) & 0xffff; - precision = ((typmod - VARHDRSZ) >> 16) & 0xffff; - integralDigitCount = Max(precision - scale, max_precision - max_scale); - max_scale = Max(max_scale, scale); - max_precision = integralDigitCount + max_scale; - /* - * If max_precision is more than TDS_MAX_NUM_PRECISION then adjust precision - * to TDS_MAX_NUM_PRECISION at the cost of scale. - */ - if (max_precision > TDS_MAX_NUM_PRECISION) - { - max_scale = Max(0, max_scale - (max_precision - TDS_MAX_NUM_PRECISION)); - max_precision = TDS_MAX_NUM_PRECISION; - } - result_typmod = ((max_precision << 16) | max_scale) + VARHDRSZ; - } - /* If max_precision is still default then use tds specific defaults */ - if (result_typmod == -1) - { - result_typmod = ((tds_default_numeric_precision << 16) | tds_default_numeric_scale) + VARHDRSZ; - } - return result_typmod; -} - -static int32 -resolve_numeric_typmod_outer_var(Plan *plan, AttrNumber attno) -{ - TargetEntry *tle; - Plan *outerplan = NULL; - - if (IsA(plan, Append) || IsA(plan, MergeAppend)) - return resolve_numeric_typmod_from_append_or_mergeappend(plan, attno); - else - outerplan = outerPlan(plan); - // outerplan = outerPlan(plan); - // tle = get_tle_by_resno(outerplan->targetlist, attno); - // return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); - - /* if outerplan is SubqueryScan then use actual subplan */ - if (IsA(outerplan, SubqueryScan)) - outerplan = ((SubqueryScan *)outerplan)->subplan; - - /* outerplan must not be NULL */ - Assert(outerplan); - tle = get_tle_by_resno(outerplan->targetlist, attno); - if (IsA(tle->expr, Var)) - { - Var *var = (Var *)tle->expr; - if (var->varno == OUTER_VAR) - { - return resolve_numeric_typmod_outer_var(outerplan, var->varattno); - } - } - return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); -} - static Oid LookupCastFuncName(Oid castsource, Oid casttarget) { @@ -704,8 +598,7 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr) if (plan) outerplan = outerPlan(plan); - /* If this var referes to tuple returned by its outer plan then find the original tle from it */ - // if (plan && outerplan && !(IsA(plan, Result)) && var->varno == OUTER_VAR) + /* If we are in parallel mode or have sort node then from its outer plan then find the original tle from it */ if (plan && outerplan && ((IsA(plan,Agg) && IsA(outerplan, Gather)) || IsA(plan, Gather) || IsA(plan, Sort))) { Assert(plan); @@ -713,17 +606,7 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr) tle = get_tle_by_resno(outerplan->targetlist, var->varattno); return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); } - - /* If this var referes to tuple returned by its outer plan then find the original tle from it */ - // if (plan && var->varno == OUTER_VAR) - // { - // Assert(plan); - // return (resolve_numeric_typmod_outer_var(plan, var->varattno)); - // } // if gather node then - // outerplan = outerPlan(plan); - // Assert(outerplan); - // tle = get_tle_by_resno(outerplan->targetlist, var->varattno); - // return resolve_numeric_typmod_from_exp(outerplan, (Node *)tle->expr); + return var->vartypmod; } case T_OpExpr: diff --git a/contrib/babelfishpg_tsql/src/pltsql_coerce.c b/contrib/babelfishpg_tsql/src/pltsql_coerce.c index 3c88ce35ef8..e79183e9787 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_coerce.c +++ b/contrib/babelfishpg_tsql/src/pltsql_coerce.c @@ -2179,8 +2179,6 @@ tsql_select_common_typmod_hook(ParseState *pstate, List *exprs, Oid common_type) return numeric_result_typmod; return max_typmods; - - } /* diff --git a/test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-verify.out b/test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-verify.out index 167de96eb4b..1e35ba1f663 100644 --- a/test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-verify.out +++ b/test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-verify.out @@ -17,11 +17,11 @@ select COL2_T2 + COL3_T2 from BABEL_5454_T2 order by COL2_T2 go ~~START~~ numeric -1.24345700 -6.12345600 -5.37345600 -25.99345600 -113.62345600 +1.243457 +6.123456 +5.373456 +25.993456 +113.623456 ~~END~~ -- test 3 : subquery @@ -63,16 +63,16 @@ ORDER BY sum_num; GO ~~START~~ nvarchar#!#numeric -Eu#!#1.24345700 -Eu#!#2.10000000 -US#!#3.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#5.37345600 -Ca#!#6.10000000 -US#!#6.12345600 -Br#!#25.99345600 -Ja#!#113.62345600 +Eu#!#1.243457 +Eu#!#2.100000 +US#!#3.100000 +Br#!#4.100000 +Ja#!#5.100000 +Ca#!#5.373456 +Ca#!#6.100000 +US#!#6.123456 +Br#!#25.993456 +Ja#!#113.623456 ~~END~~ @@ -102,16 +102,16 @@ ORDER BY val; GO ~~START~~ numeric -2.10000000 -2.22345700 -3.10000000 -4.10000000 -5.10000000 -5.22345600 -6.10000000 -7.22345600 -7.22345600 -9.22345600 +2.100000 +2.223457 +3.100000 +4.100000 +5.100000 +5.223456 +6.100000 +7.223456 +7.223456 +9.223456 ~~END~~ @@ -141,16 +141,16 @@ ORDER BY val; GO ~~START~~ numeric -2.10000000 -2.36691400 -3.10000000 -4.10000000 -5.10000000 -6.10000000 -9.49691200 -11.24691200 -28.11691200 -116.74691200 +2.100000 +2.366914 +3.100000 +4.100000 +5.100000 +6.100000 +9.496912 +11.246912 +28.116912 +116.746912 ~~END~~ @@ -213,16 +213,16 @@ order by ex1 GO ~~START~~ int#!#nvarchar#!#numeric -1#!#Eu#!#1.24345700 -1#!#Eu#!#2.20000000 -1#!#US#!#4.20000000 -1#!#Ca#!#5.37345600 -1#!#US#!#6.12345600 -1#!#Br#!#6.20000000 -1#!#Ja#!#8.20000000 -1#!#Ca#!#10.20000000 -1#!#Br#!#25.99345600 -1#!#Ja#!#113.62345600 +1#!#Eu#!#1.243457 +1#!#Eu#!#2.200000 +1#!#US#!#4.200000 +1#!#Ca#!#5.373456 +1#!#US#!#6.123456 +1#!#Br#!#6.200000 +1#!#Ja#!#8.200000 +1#!#Ca#!#10.200000 +1#!#Br#!#25.993456 +1#!#Ja#!#113.623456 ~~END~~ @@ -276,11 +276,11 @@ ORDER BY ex; GO ~~START~~ numeric#!#nvarchar#!#nvarchar +1.000000#!#Ca#!#Ca 1.000000#!#US#!#US 1.000000#!#Eu#!#Eu 1.000000#!#Br#!#Br 1.000000#!#Ja#!#Ja -1.000000#!#Ca#!#Ca 1.243457#!#Eu#!#Eu 5.373456#!#Ca#!#Ca 6.123456#!#US#!#US @@ -304,16 +304,16 @@ FROM ( GO ~~START~~ nvarchar#!#numeric -US#!#3.100000 -Eu#!#2.100000 -Br#!#4.100000 -Ja#!#5.100000 -Ca#!#6.100000 Eu#!#1.243457 Br#!#25.993456 Ja#!#113.623456 Ca#!#5.373456 US#!#6.123456 +US#!#3.100000 +Eu#!#2.100000 +Br#!#4.100000 +Ja#!#5.100000 +Ca#!#6.100000 ~~END~~ @@ -333,8 +333,8 @@ WHERE cr1 = 'US'; GO ~~START~~ nvarchar#!#numeric -US#!#3.100000 US#!#6.123456 +US#!#3.100000 ~~END~~ @@ -353,16 +353,16 @@ FROM ( GO ~~START~~ nvarchar#!#numeric -US#!#3.100000 -Eu#!#2.100000 -Br#!#4.100000 -Ja#!#5.100000 -Ca#!#6.100000 Eu#!#1.243457 Br#!#25.993456 Ja#!#113.623456 Ca#!#5.373456 US#!#6.123456 +US#!#3.100000 +Eu#!#2.100000 +Br#!#4.100000 +Ja#!#5.100000 +Ca#!#6.100000 ~~END~~ @@ -381,16 +381,16 @@ FROM ( GO ~~START~~ nvarchar#!#numeric -US#!#3.100000 -Eu#!#2.100000 -Br#!#4.100000 -Ja#!#5.100000 -Ca#!#6.100000 Eu#!#1.243457 Br#!#25.993456 Ja#!#113.623456 Ca#!#5.373456 US#!#6.123456 +US#!#3.100000 +Eu#!#2.100000 +Br#!#4.100000 +Ja#!#5.100000 +Ca#!#6.100000 ~~END~~ @@ -413,16 +413,16 @@ ORDER BY test1; GO ~~START~~ nvarchar#!#numeric -Eu#!#1.24345700 -Eu#!#2.10000000 -US#!#3.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#5.37345600 -Ca#!#6.10000000 -US#!#6.12345600 -Br#!#25.99345600 -Ja#!#113.62345600 +Eu#!#1.243457 +Eu#!#2.100000 +US#!#3.100000 +Br#!#4.100000 +Ja#!#5.100000 +Ca#!#5.373456 +Ca#!#6.100000 +US#!#6.123456 +Br#!#25.993456 +Ja#!#113.623456 ~~END~~ @@ -445,16 +445,16 @@ ORDER BY test1; GO ~~START~~ nvarchar#!#numeric -Eu#!#1.24345700 -Eu#!#2.20000000 -US#!#4.20000000 -Ca#!#5.37345600 -US#!#6.12345600 -Br#!#6.20000000 -Ja#!#8.20000000 -Ca#!#10.20000000 -Br#!#25.99345600 -Ja#!#113.62345600 +Eu#!#1.243457 +Eu#!#2.200000 +US#!#4.200000 +Ca#!#5.373456 +US#!#6.123456 +Br#!#6.200000 +Ja#!#8.200000 +Ca#!#10.200000 +Br#!#25.993456 +Ja#!#113.623456 ~~END~~ @@ -477,16 +477,16 @@ ORDER BY test1; GO ~~START~~ nvarchar#!#numeric -Eu#!#1.24345700 -Eu#!#2.00000000 -Br#!#2.00000000 -Ja#!#2.00000000 -Ca#!#2.00000000 -US#!#2.00000000 -Ca#!#5.37345600 -US#!#6.12345600 -Br#!#25.99345600 -Ja#!#113.62345600 +Eu#!#1.243457 +Ca#!#2.000000 +US#!#2.000000 +Eu#!#2.000000 +Br#!#2.000000 +Ja#!#2.000000 +Ca#!#5.373456 +US#!#6.123456 +Br#!#25.993456 +Ja#!#113.623456 ~~END~~ @@ -505,16 +505,16 @@ FROM ( GO ~~START~~ nvarchar#!#numeric -US#!#4.2 Eu#!#2.2 Br#!#6.2 Ja#!#8.2 Ca#!#10.2 +US#!#4.2 +US#!#4.2 Eu#!#2.2 Br#!#6.2 Ja#!#8.2 Ca#!#10.2 -US#!#4.2 ~~END~~ @@ -533,16 +533,16 @@ FROM ( GO ~~START~~ nvarchar#!#numeric -US#!#7.3 Eu#!#6.3 Br#!#8.3 Ja#!#9.3 Ca#!#10.3 +US#!#7.3 +US#!#7.3 Eu#!#6.3 Br#!#8.3 Ja#!#9.3 Ca#!#10.3 -US#!#7.3 ~~END~~ @@ -565,16 +565,16 @@ ORDER BY result; GO ~~START~~ nvarchar#!#numeric -Eu#!#4.40000000 -Eu#!#4.40000000 -US#!#8.40000000 -US#!#8.40000000 -Br#!#12.40000000 -Br#!#12.40000000 -Ja#!#16.40000000 -Ja#!#16.40000000 -Ca#!#20.40000000 -Ca#!#20.40000000 +Eu#!#4.4 +Eu#!#4.4 +US#!#8.4 +US#!#8.4 +Br#!#12.4 +Br#!#12.4 +Ja#!#16.4 +Ja#!#16.4 +Ca#!#20.4 +Ca#!#20.4 ~~END~~ @@ -596,16 +596,16 @@ ORDER BY result; GO ~~START~~ numeric -2.48691400 -4.20000000 -6.20000000 -8.20000000 -10.20000000 -10.74691200 -12.20000000 -12.24691200 -51.98691200 -227.24691200 +2.486914 +4.200000 +6.200000 +8.200000 +10.200000 +10.746912 +12.200000 +12.246912 +51.986912 +227.246912 ~~END~~ @@ -625,12 +625,12 @@ order by sum_result GO ~~START~~ numeric -2.24000000 -2.24691400 -4.24691200 -6.24691200 -8.24691200 -10.24691200 +2.240000 +2.246914 +4.246912 +6.246912 +8.246912 +10.246912 ~~END~~ @@ -659,21 +659,21 @@ order by ex_result GO ~~START~~ numeric -0.24000000 -2.00000000 -2.48691400 -2.50000000 -4.40000000 -8.40000000 -10.74691200 -12.24691200 -12.40000000 -16.40000000 -20.40000000 -47.74000000 -51.98691200 -221.00000000 -227.24691200 +0.240000 +2.000000 +2.486914 +2.500000 +4.400000 +8.400000 +10.746912 +12.246912 +12.400000 +16.400000 +20.400000 +47.740000 +51.986912 +221.000000 +227.246912 ~~END~~ diff --git a/test/JDBC/expected/babel-5454.out b/test/JDBC/expected/babel-5454.out deleted file mode 100644 index 21a9b8fc7ea..00000000000 --- a/test/JDBC/expected/babel-5454.out +++ /dev/null @@ -1,773 +0,0 @@ --- Create simplified tables -CREATE TABLE Currency (Code nvarchar(3), Name nvarchar(2), Num decimal(2,1)); -CREATE TABLE Exchange (Code nvarchar(3), Rate decimal(5,2), Value decimal(9,8)); -GO - --- Insert minimal test data -INSERT INTO Currency VALUES ('USD', 'US', 2.1), ('EUR', 'EU', 1.1); -INSERT INTO Exchange VALUES ('USD', 1.00, 5.12345678), ('EUR', 0.12, 1.12345678); -GO -~~ROW COUNT: 2~~ - -~~ROW COUNT: 2~~ - - --- The query that demonstrates the issue, works without my chnage -SELECT e.Name AS description, e.Rate + e.Value AS sum_num -FROM -( - SELECT Currency.Code, Currency.Name, Exchange.Rate, Exchange.Value - FROM Currency - JOIN Exchange ON Currency.Code = Exchange.Code - UNION ALL - SELECT Code, Name, 1 AS Rate, Num AS Value - FROM Currency -) AS e; -GO -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -EU#!#1.24345678 -US#!#3.10000000 -EU#!#2.10000000 -~~END~~ - - - -CREATE TABLE Currency2(CurrencyCode nvarchar(3) NOT NULL, CurrencyName nvarchar(2) NULL, curr_num decimal (2,1)); -GO - -CREATE TABLE ExchangeRate2(ToCurrencyCode nvarchar(3) NOT NULL, ExchangeRate decimal(5, 2) NOT NULL, Hello decimal(9,8)); -GO - -INSERT INTO Currency2 (CurrencyCode, CurrencyName,curr_num) VALUES ('USD', 'US',2.1), ('EUR', 'Eu',1.1), ('GBP', 'Br',3.1), ('JPY', 'Ja',4.1), ('CAD', 'Ca',5.1); -GO -~~ROW COUNT: 5~~ - - -INSERT INTO ExchangeRate2 (ToCurrencyCode, ExchangeRate, Hello) VALUES ('EUR', 0.12, 1.12345678), ('GBP', 23.87, 2.12345678), ('JPY', 110.50, 3.12345678), ('CAD', 1.25, 4.12345678), ('USD', 1.00 , 5.12345678); -GO -~~ROW COUNT: 5~~ - - - - --- formatted -SELECT - cr1 AS description, - ex + Hello AS sum_num -FROM ( - SELECT - ExchangeRate AS ex, - CurrencyName AS cr1, - CurrencyName, - Hello - FROM currency2 - INNER JOIN ExchangeRate2 - ON ToCurrencyCode = CurrencyCode - UNION ALL - SELECT - 1 AS aw, - CurrencyName AS cr, - CurrencyName, - curr_num AS aw1 - FROM currency2 -) a; -GO -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#3.10000000 -Eu#!#2.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#6.10000000 -~~END~~ - - --- should notb work withoit my changes -SELECT cr1 description, ex + Hello sum_num FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a; -GO -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#3.10000000 -Eu#!#2.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#6.10000000 -~~END~~ - - -select ExchangeRate + Hello from ExchangeRate2 -go -~~START~~ -numeric -1.24345678 -25.99345678 -113.62345678 -5.37345678 -6.12345678 -~~END~~ - -select ExchangeRate + Hello from ExchangeRate2 order by ExchangeRate -go -~~START~~ -numeric -1.24345678 -6.12345678 -5.37345678 -25.99345678 -113.62345678 -~~END~~ - -select abc from (select ExchangeRate + Hello as abc from ExchangeRate2) -go -~~START~~ -numeric -1.24345678 -25.99345678 -113.62345678 -5.37345678 -6.12345678 -~~END~~ - - -select curr_num + Hello from (SELECT curr_num, ExchangeRate + Hello,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 as aw, 1 AS aw1,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a; -go -~~START~~ -numeric -7.22345678 -2.22345678 -5.22345678 -7.22345678 -9.22345678 -3.10000000 -2.10000000 -4.10000000 -5.10000000 -6.10000000 -~~END~~ - - -select sum + Hello from (SELECT curr_num, ExchangeRate + Hello as sum,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 as aw, 1 AS aw1,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a; -go -~~START~~ -numeric -11.24691356 -2.36691356 -28.11691356 -116.74691356 -9.49691356 -3.10000000 -2.10000000 -4.10000000 -5.10000000 -6.10000000 -~~END~~ - - -select avg(sum_num) from (select sum + Hello as sum_num from (SELECT curr_num, ExchangeRate + Hello as sum,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 as aw, 1 AS aw1,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2)) a; -GO -~~START~~ -numeric -18.84745678 -~~END~~ - - --- 1.1 THIS QUERY DOES WORK when union with decimal, so not an issue of position? - 5,2 and 9,8 , went to NUMERIC_SUB_OID, final 12,8 -SELECT cr1 description, ex + Hello ex1 FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT curr_num AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a; -GO -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#4.20000000 -Eu#!#2.20000000 -Br#!#6.20000000 -Ja#!#8.20000000 -Ca#!#10.20000000 -~~END~~ - - -SELECT 1,cr1 description, ex + Hello ex1 FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT curr_num AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a; -GO -~~START~~ -int#!#nvarchar#!#numeric -1#!#US#!#6.12345678 -1#!#Eu#!#1.24345678 -1#!#Br#!#25.99345678 -1#!#Ja#!#113.62345678 -1#!#Ca#!#5.37345678 -1#!#US#!#4.20000000 -1#!#Eu#!#2.20000000 -1#!#Br#!#6.20000000 -1#!#Ja#!#8.20000000 -1#!#Ca#!#10.20000000 -~~END~~ - - - - - --- inner query -> works without my change -SELECT ExchangeRate + hello ex,CurrencyName cr1, CurrencyName FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT curr_num AS aw,CurrencyName as cr, CurrencyName FROM currency2 ; --- inner query -> works without my change -SELECT ExchangeRate + hello ex,CurrencyName cr1, CurrencyName FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName FROM currency2 ; --- works oder of hello and ex - doing this -SELECT cr1 description, ex+ Hello sum_num FROM (SELECT Hello,CurrencyName cr1, CurrencyName ,ExchangeRate ex FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2); --- SELECT cr1 description, ex+ Hello sum_num FROM (SELECT Hello,CurrencyName cr1 (this is var why?), CurrencyName (this is const why??) ,ExchangeRate ex FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a; -GO -~~START~~ -numeric#!#nvarchar#!#nvarchar -6.12345678#!#US#!#US -1.24345678#!#Eu#!#Eu -25.99345678#!#Br#!#Br -113.62345678#!#Ja#!#Ja -5.37345678#!#Ca#!#Ca -2.10000000#!#US#!#US -1.10000000#!#Eu#!#Eu -3.10000000#!#Br#!#Br -4.10000000#!#Ja#!#Ja -5.10000000#!#Ca#!#Ca -~~END~~ - -~~START~~ -numeric#!#nvarchar#!#nvarchar -6.12345678#!#US#!#US -1.24345678#!#Eu#!#Eu -25.99345678#!#Br#!#Br -113.62345678#!#Ja#!#Ja -5.37345678#!#Ca#!#Ca -1.00000000#!#US#!#US -1.00000000#!#Eu#!#Eu -1.00000000#!#Br#!#Br -1.00000000#!#Ja#!#Ja -1.00000000#!#Ca#!#Ca -~~END~~ - -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#3.10000000 -Eu#!#2.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#6.10000000 -~~END~~ - - --- works -SELECT cr1 description, ex+ Hello sum_num FROM (SELECT Hello,CurrencyName cr1, CurrencyName ,ExchangeRate ex FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a where cr1 = 'US'; -go -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -US#!#3.10000000 -~~END~~ - - -SELECT cr1 description, ex+ Hello sum_num FROM (SELECT Hello,CurrencyName cr1, CurrencyName ,ExchangeRate ex FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2); -go -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#3.10000000 -Eu#!#2.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#6.10000000 -~~END~~ - - - --- from second union --- SELECT cr1 description, curr_num+ curr_num sum_num FROM (SELECT Hello,CurrencyName cr1, CurrencyName ,ExchangeRate ex FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2); --- go --- 2 works without my fix, correct answer also, 5,2 and 9.8 -> final 12,8 -SELECT cr1 description, ex + Hello sum_numeric FROM (SELECT CurrencyName cr1,ExchangeRate ex, Hello,CurrencyName FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT CurrencyName as cr,1 AS aw,curr_num as aw1, CurrencyName FROM currency2) a; -go -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#3.10000000 -Eu#!#2.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#6.10000000 -~~END~~ - --- 3 works without my fix, correct answer also ,so not an issue of position -- for this we got 5,2 and 9,8 , went to NUMERIC_SUB_OID, final 12,8 as expected by tsql also --- but here also we have numeric and decimal in union result --- T_RelabelType and T_Var -SELECT cr1 description, ex + Hello sum_numeric FROM (SELECT Hello,CurrencyName cr1,CurrencyName,CurrencyName cr2,ExchangeRate ex FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,CurrencyName cr3,curr_num as aw1 FROM currency2) a; -go -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#3.10000000 -Eu#!#2.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#6.10000000 -~~END~~ - - --- 5 alias issue ??? -- SEEEE THISSS , does not work before my fix, numeric and decimal -- works after fix --- in union select 1 -SELECT description d1, ex2+h2 test1 from (SELECT CurrencyName description, ex ex2, h1 h2 FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello h1 FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a) -go -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#3.10000000 -Eu#!#2.10000000 -Br#!#4.10000000 -Ja#!#5.10000000 -Ca#!#6.10000000 -~~END~~ - - --- 6 this works - union decimal and decimal -SELECT description d1, ex2+h2 test1 from (SELECT CurrencyName description, ex ex2, h1 h2 FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello h1 FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT curr_num AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a) -go -~~START~~ -nvarchar#!#numeric -US#!#6.12345678 -Eu#!#1.24345678 -Br#!#25.99345678 -Ja#!#113.62345678 -Ca#!#5.37345678 -US#!#4.20000000 -Eu#!#2.20000000 -Br#!#6.20000000 -Ja#!#8.20000000 -Ca#!#10.20000000 -~~END~~ - - - --- does not work, in union select 1 and 1, after my fix works --- SELECT description d1, ex2+h2 test1 from (SELECT CurrencyName description, ex ex2, h1 h2 FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello h1 FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,1 as aw1 FROM currency2) a) --- go --- from second union, we choose colname based on first query only in union all. so our approach will work in all cases. -SELECT cr1 description, curr_num+ curr_num sum_num FROM (SELECT Hello,CurrencyName cr1, CurrencyName ,ExchangeRate ex,curr_num FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1, curr_num FROM currency2); -go -~~START~~ -nvarchar#!#numeric -US#!#4.2 -Eu#!#2.2 -Br#!#6.2 -Ja#!#8.2 -Ca#!#10.2 -US#!#4.2 -Eu#!#2.2 -Br#!#6.2 -Ja#!#8.2 -Ca#!#10.2 -~~END~~ - -SELECT cr1 description, curr_num+ 5.2 sum_num FROM (SELECT Hello,CurrencyName cr1, CurrencyName ,ExchangeRate ex,curr_num FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1, curr_num FROM currency2); -go -~~START~~ -nvarchar#!#numeric -US#!#7.3 -Eu#!#6.3 -Br#!#8.3 -Ja#!#9.3 -Ca#!#10.3 -US#!#7.3 -Eu#!#6.3 -Br#!#8.3 -Ja#!#9.3 -Ca#!#10.3 -~~END~~ - --- works -select description, sum_num + sum_num from (SELECT cr1 description, curr_num+ curr_num sum_num FROM (SELECT Hello,CurrencyName cr1, CurrencyName ,ExchangeRate ex,curr_num FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1, curr_num FROM currency2)) -go -~~START~~ -nvarchar#!#numeric -US#!#8.4 -Eu#!#4.4 -Br#!#12.4 -Ja#!#16.4 -Ca#!#20.4 -US#!#8.4 -Eu#!#4.4 -Br#!#12.4 -Ja#!#16.4 -Ca#!#20.4 -~~END~~ - --- works -select sum_num+sum_num from (SELECT cr1 description, ex + Hello sum_num FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT 1 AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a) -go -~~START~~ -numeric -12.24691356 -2.48691356 -51.98691356 -227.24691356 -10.74691356 -6.20000000 -4.20000000 -8.20000000 -10.20000000 -12.20000000 -~~END~~ - - - -Select result+result as sum_result from (select case 1 when 1 then cast(1.12343 as decimal(5,2)) end as result Union all select Hello from ExchangeRate2) as derived_table -go -~~START~~ -numeric -2.24000000 -2.24691356 -4.24691356 -6.24691356 -8.24691356 -10.24691356 -~~END~~ - - --- multiple union all -select ex5 + ex5 ex_result from (select ToCurrencyCode, exchangerate ex5 from ExchangeRate2 union all (SELECT cr1 description, ex + Hello ex1 FROM (SELECT ExchangeRate ex,CurrencyName cr1, CurrencyName ,Hello FROM currency2 INNER JOIN ExchangeRate2 ON ToCurrencyCode = CurrencyCode UNION ALL SELECT curr_num AS aw,CurrencyName as cr, CurrencyName,curr_num as aw1 FROM currency2) a)) -go -~~START~~ -numeric -0.24000000 -47.74000000 -221.00000000 -2.50000000 -2.00000000 -12.24691356 -2.48691356 -51.98691356 -227.24691356 -10.74691356 -8.40000000 -4.40000000 -12.40000000 -16.40000000 -20.40000000 -~~END~~ - - - --- Setup: Create a UDT and additional test tables -CREATE TYPE TestUDT FROM decimal(10,4); -GO - -CREATE TABLE TestTypes ( - IntCol int, - FloatCol float, - SmallIntCol smallint, - NumericCol numeric(10,5), - UDTCol TestUDT -); -GO - -INSERT INTO TestTypes VALUES -(100, 100.5, 10, 100.12345, 100.1234), -(200, 200.5, 20, 200.12345, 200.1234); -GO -~~ROW COUNT: 2~~ - - --- Test Case 1: Multiple UNION ALLs with different combinations -SELECT - CASE WHEN IntCol > 150 THEN FloatCol ELSE SmallIntCol END AS result, - NumericCol + UDTCol AS sum_result -FROM TestTypes -UNION ALL -SELECT - CAST(NumericCol AS float) AS result, - IntCol + FloatCol AS sum_result -FROM TestTypes -UNION ALL -SELECT - COALESCE(SmallIntCol, 0) AS result, - CAST(UDTCol AS numeric(12,6)) + NumericCol AS sum_result -FROM TestTypes; -GO -~~START~~ -float#!#float -10.0#!#200.24685 -200.5#!#400.24685 -100.12345#!#200.5 -200.12345#!#400.5 -10.0#!#200.24685 -20.0#!#400.24685 -~~END~~ - --- Test Case 2: Nested queries with decimal and numeric operations -SELECT outer_result + inner_result AS final_result -FROM ( - SELECT - (SELECT AVG(NumericCol) FROM TestTypes) AS outer_result, - ( - SELECT TOP 1 UDTCol + FloatCol - FROM TestTypes - ORDER BY IntCol DESC - ) AS inner_result -) AS nested_query; -GO -~~START~~ -float -550.74685 -~~END~~ - --- Test Case 3: Decimal + Numeric with different scales and precisions -SELECT - CAST(12345.6789 AS decimal(10,4)) + NumericCol AS dec_num_sum, - CAST(12345.6789 AS decimal(10,4)) * NumericCol AS dec_num_product -FROM TestTypes -UNION ALL -SELECT - CAST(9876.54321 AS numeric(12,8)) + UDTCol, - CAST(9876.54321 AS numeric(12,8)) * UDTCol -FROM TestTypes; -GO -~~START~~ -numeric#!#numeric -12445.80235000#!#1236091.9640602050000000 -12545.80235000#!#2470659.8540602050000000 -9976.66661000#!#988873.0864321140000000 -10076.66661000#!#1976527.4074321140000000 -~~END~~ - --- Test Case 4: UDT operations -SELECT - UDTCol + IntCol AS udt_int_sum, - UDTCol * FloatCol AS udt_float_product, - UDTCol / NULLIF(SmallIntCol, 0) AS udt_smallint_div -FROM TestTypes; -GO -~~START~~ -numeric#!#float#!#numeric -200.12340000#!#10062.4017#!#10.01234000 -400.12340000#!#40124.7417#!#10.00617000 -~~END~~ - --- Test Case 5: Mixed type operations with CAST -SELECT - CAST(IntCol AS decimal(10,2)) + FloatCol AS int_float_sum, - CAST(SmallIntCol AS numeric(8,4)) * NumericCol AS smallint_numeric_product, - CAST(UDTCol AS float) / NULLIF(IntCol, 0) AS udt_int_div -FROM TestTypes -UNION ALL -SELECT - CAST(12.34 AS decimal(5,2)) + CAST(56.78 AS numeric(6,3)), - CAST(100 AS smallint) * CAST(2.5 AS float), - CAST(1000 AS numeric(10,4)) / NULLIF(CAST(3 AS int), 0) -FROM TestTypes; -GO -~~START~~ -float#!#float#!#float -200.5#!#1001.2345#!#1.001234 -400.5#!#4002.469#!#1.000617 -69.12#!#250.0#!#333.3333333333333 -69.12#!#250.0#!#333.3333333333333 -~~END~~ - --- Test Case 6: All possible operations -SELECT - IntCol + FloatCol AS addition, - NumericCol - UDTCol AS subtraction, - SmallIntCol * FloatCol AS multiplication, - CAST(NumericCol AS float) / NULLIF(IntCol, 0) AS division, - POWER(FloatCol, 2) AS exponentiation, - IntCol % 3 AS modulo -FROM TestTypes; -GO -~~START~~ -float#!#numeric#!#float#!#float#!#float#!#int -200.5#!#0.00005#!#1005.0#!#1.0012345#!#10100.25#!#1 -400.5#!#0.00005#!#4010.0#!#1.00061725#!#40200.25#!#2 -~~END~~ - --- Test Case 7: UNION with different scales and precisions -SELECT CAST(IntCol AS decimal(10,2)) AS result -FROM TestTypes -UNION -SELECT CAST(FloatCol AS decimal(12,4)) -FROM TestTypes -UNION -SELECT NumericCol -FROM TestTypes -UNION -SELECT UDTCol -FROM TestTypes; -GO -~~START~~ -numeric -200.50000 -100.12340 -200.00000 -200.12340 -200.12345 -100.00000 -100.50000 -100.12345 -~~END~~ - - -DROP TABLE TestTypes; -GO -DROP TABLE Currency2; -GO -DROP TABLE ExchangeRate2; -GO -DROP TABLE Currency; -GO -DROP TABLE Exchange; -GO -DROP TYPE TestUDT; -GO - - - - -CREATE TABLE testdecimal_vu_prepare_tab21 (id INT IDENTITY(1,1) PRIMARY KEY,in4 DECIMAL(10,2),in5 DECIMAL(10,2)); -CREATE TABLE tab2 (id INT IDENTITY(1,1) PRIMARY KEY, a DECIMAL(10,2)); -INSERT INTO testdecimal_vu_prepare_tab21 (in4, in5) VALUES (10.50, 2.00), (25.75, 4.00), (100.00, 0.50), (7.25, 3.00), (50.00, 1.50); -go -~~ROW COUNT: 5~~ - - - -INSERT INTO tab2 (a) VALUES (30.00), (45.50), (75.25), (12.75), (60.00); -select result1+result1 as result2 , a from (SELECT a , a AS result1 FROM tab2 union all SELECT in4, in4 + in5 AS result FROM testdecimal_vu_prepare_tab21) -go -~~ROW COUNT: 5~~ - -~~START~~ -numeric#!#numeric -60.00#!#30.00 -91.00#!#45.50 -150.50#!#75.25 -25.50#!#12.75 -120.00#!#60.00 -25.00#!#10.50 -59.50#!#25.75 -201.00#!#100.00 -20.50#!#7.25 -103.00#!#50.00 -~~END~~ - - - - - - - - - --- getting --- result2 a --- ---------------------------------------- ------------ --- 25.00000000 10.50 --- 59.50000000 25.75 --- 201.00000000 100.00 --- 20.50000000 7.25 --- 103.00000000 50.00 --- 60.00000000 30.00 --- 91.00000000 45.50 --- 150.50000000 75.25 --- 25.50000000 12.75 --- 120.00000000 60.00 --- expected --- result2 a --- -------------- ------------ --- 25.00 10.50 --- 59.50 25.75 --- 201.00 100.00 --- 20.50 7.25 --- 103.00 50.00 --- 60.00 30.00 --- 91.00 45.50 --- 150.50 75.25 --- 25.50 12.75 --- 120.00 60.00 --- with my change and without parallel query --- result2 a --- -------------- ------------ --- 60.00 30.00 --- 91.00 45.50 --- 150.50 75.25 --- 25.50 12.75 --- 120.00 60.00 --- 25.00 10.50 --- 59.50 25.75 --- 201.00 100.00 --- 20.50 7.25 --- 103.00 50.00 --- with return -> with my changes 9n parallel --- 2> go --- result2 a --- -------------- ------------ --- 25.00 10.50 --- 59.50 25.75 --- 201.00 100.00 --- 20.50 7.25 --- 103.00 50.00 --- 60.00 30.00 --- 91.00 45.50 --- 150.50 75.25 --- 25.50 12.75 --- 120.00 60.00 -CREATE TABLE testdecimal_vu_prepare_tab2 (id INT IDENTITY(1,1) PRIMARY KEY, in4 DECIMAL(20,6), in5 DECIMAL(20,6)); -CREATE TABLE tab21 (id INT IDENTITY(1,1) PRIMARY KEY, a DECIMAL(20,6)); -INSERT INTO testdecimal_vu_prepare_tab2 (in4, in5) VALUES (99999999999999.111111, 11111111111111.999999); -INSERT INTO tab21 (a) VALUES (99999999999999.111111); --- correct -select result1+result1 as result2 , a from (SELECT a , a AS result1 FROM tab21 union all SELECT in4, in4 + in5 AS result FROM testdecimal_vu_prepare_tab2) --- Drop tables -DROP TABLE testdecimal_vu_prepare_tab21; -DROP TABLE tab2; -DROP TABLE testdecimal_vu_prepare_tab2; -DROP TABLE tab21; -GO -~~ROW COUNT: 1~~ - -~~ROW COUNT: 1~~ - -~~START~~ -numeric#!#numeric -199999999999998.222222#!#99999999999999.111111 -222222222222222.222220#!#99999999999999.111111 -~~END~~ - diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 0af86de3cbf..8b3235c30ce 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -596,4 +596,5 @@ db_owner BABEL-2961 test_conv_money_to_varchar fixeddecimal_modulo +BABEL-NUMERIC_EXPR test_conv_float_to_varchar_char