Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tanya Gupta <[email protected]>
  • Loading branch information
Tanya Gupta committed Feb 5, 2025
1 parent 447272f commit 1c93737
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 220 deletions.
21 changes: 11 additions & 10 deletions contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,24 +591,25 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr)
}
case T_Var:
{
Var *var = (Var *) expr;
Var *var = (Var *) expr;
Plan *outerplan = NULL;
TargetEntry *tle;
if (plan)
outerplan = outerPlan(plan);

/* 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) ||
IsA(plan, GatherMerge)))
if (plan) outerplan = outerPlan(plan);

/* If we are in parallel mode or have a Sort node then
* find the original target list entry from the outer plan
*/
if (plan && outerplan && (
(IsA(plan, Agg) && IsA(outerplan, Gather)) ||
IsA(plan, Gather) ||
IsA(plan, Sort) ||
IsA(plan, GatherMerge)))
{
Assert(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:
Expand Down
13 changes: 9 additions & 4 deletions test/JDBC/expected/BABEL-NUMERIC_EXPR-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
CREATE TABLE BABEL_5454_T1(COL1_T1 nvarchar(3) NOT NULL, COL2_T1 nvarchar(2) NULL, COL3_T1 decimal (2,1));
GO

CREATE TABLE BABEL_5454_T2(COL1_T2 nvarchar(3) NOT NULL, COL2_T2 numeric(5, 2) NOT NULL, COL3_T2 decimal(9,6));
CREATE TABLE BABEL_5454_T2(COL1_T2 nvarchar(3) NOT NULL, COL2_T2 numeric(5, 2) NOT NULL, COL3_T2 decimal(9,8));
GO

INSERT INTO BABEL_5454_T1 (COL1_T1, COL2_T1,COL3_T1) VALUES ('USD', 'US',2.1), ('EUR', 'Eu',1.1), ('GBP', 'Br',3.1), ('JPY', 'Ja',4.1), ('CAD', 'Ca',5.1);
INSERT INTO BABEL_5454_T1 (COL1_T1, COL2_T1,COL3_T1)
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 BABEL_5454_T2 (COL1_T2, COL2_T2, COL3_T2) VALUES ('EUR', 0.12, 1.12345678), ('GBP', 23.87, 2.123456), ('JPY', 110.50, 3.123456), ('CAD', 1.25, 4.123456), ('USD', 1.00 , 5.123456);
INSERT INTO BABEL_5454_T2 (COL1_T2, COL2_T2, COL3_T2)
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~~

Expand All @@ -26,7 +28,7 @@ CREATE TABLE TestTypes (
);
GO

INSERT INTO TestTypes VALUES
INSERT INTO TestTypes VALUES
(100, 100.5, 10, 100.12345, 100.1234),
(200, 200.5, 20, 200.12345, 200.1234);
GO
Expand All @@ -35,12 +37,15 @@ GO

CREATE TABLE BABEL_5454_T3 (id INT IDENTITY(1,1) PRIMARY KEY, in4 DECIMAL(20,6), in5 DECIMAL(20,6));
GO

CREATE TABLE BABEL_5454_T4 (id INT IDENTITY(1,1) PRIMARY KEY, a DECIMAL(20,6));
GO

INSERT INTO BABEL_5454_T3 (in4, in5) VALUES (99999999999999.111111, 11111111111111.999999);
GO
~~ROW COUNT: 1~~


INSERT INTO BABEL_5454_T4 (a) VALUES (99999999999999.111111);
GO
~~ROW COUNT: 1~~
Expand Down
Loading

0 comments on commit 1c93737

Please sign in to comment.