Skip to content

Case insensitivity of column names in UNPIVOT result #3709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: BABEL_5_X_DEV
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-decl.y
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@

%type <list> tsql_stmtmulti
%type <list> columnListWithOptAscDesc
%type <list> columnDefList
%type <node> columnDefElem


%type <boolean> tsql_cluster tsql_opt_cluster

Expand Down
13 changes: 12 additions & 1 deletion contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y
Original file line number Diff line number Diff line change
Expand Up @@ -1904,8 +1904,19 @@ joined_table:
}
;

columnDefList:
columnDefElem { $$ = list_make1($1); }
| columnDefList ',' columnDefElem { $$ = lappend($1, $3); }
;

columnDefElem: ColIdDef
{
$$ = (Node *) makeString($1);
}
;

tsql_unpivot_clause:
'(' columnref FOR columnref IN_P '(' columnList ')' ')'
'(' columnref FOR columnref IN_P '(' columnDefList ')' ')'
{
$$ = (Node *)list_make3($2, $4, $7);
}
Expand Down
2 changes: 2 additions & 0 deletions test/JDBC/expected/unpivot-vu-cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ DROP TABLE [Sales$Data@2024];
GO
DROP TABLE [Global_データ_Sales];
GO
DROP TABLE Test_Case_Sensitivity;
GO

-- Drop temporary tables (if they still exist)
IF OBJECT_ID('tempdb..#temp_sales') IS NOT NULL
Expand Down
9 changes: 9 additions & 0 deletions test/JDBC/expected/unpivot-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,12 @@ INSERT INTO [Global_データ_Sales] VALUES (1,2,3,4,5);
GO
~~ROW COUNT: 1~~


CREATE TABLE Test_Case_Sensitivity (
IDENT INT PRIMARY KEY,
[Order Number] NVARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
OrderStatus NVARCHAR(20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[shipping-address] NVARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
TOTAL_AMOUNT DECIMAL(15,2)
);
GO
49 changes: 33 additions & 16 deletions test/JDBC/expected/unpivot-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,39 @@ int#!#numeric#!#nvarchar
~~END~~


-- BABEL-5761 Case insensitivity of column names in UNPIVOT result
-- Uppercase column names in unpivot source list
SELECT [ID_番号], [Amount_金額], [Quarter_四半期]
FROM [Global_データ_Sales]
UNPIVOT (
[Amount_金額] FOR [Quarter_四半期] IN (
[Q1_売上],
[Q2_売上]
)
) AS [Global_分析];
GO
~~START~~
int#!#numeric#!#nvarchar
1#!#4.00#!#Q1_売上
1#!#5.00#!#Q2_売上
~~END~~


SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Test_Case_Sensitivity'
AND TABLE_SCHEMA = 'dbo'
ORDER BY ORDINAL_POSITION;
GO
~~START~~
nvarchar
IDENT
Order Number
OrderStatus
shipping-address
TOTAL_AMOUNT
~~END~~


-- KNOWN ISSUES
-- BABEL-5677 - Support more variations of UNPIVOT Syntax
Expand Down Expand Up @@ -1565,21 +1598,5 @@ int#!#varchar#!#char#!#int#!#int#!#int#!#int#!#int#!#nvarchar
2#!#Cust B#!#P#!#150#!#250#!#200#!#<NULL>#!#150#!#q1
2#!#Cust B#!#P#!#150#!#250#!#200#!#<NULL>#!#250#!#q2
2#!#Cust B#!#P#!#150#!#250#!#200#!#<NULL>#!#200#!#q3
~~END~~

-- Uppercase column names in unpivot source list
SELECT [ID_番号], [Amount_金額], [Quarter_四半期]
FROM [Global_データ_Sales]
UNPIVOT (
[Amount_金額] FOR [Quarter_四半期] IN (
[Q1_売上],
[Q2_売上]
)
) AS [Global_分析];
GO
~~START~~
int#!#numeric#!#nvarchar
1#!#4.00#!#q1_売上
1#!#5.00#!#q2_売上
~~END~~

2 changes: 2 additions & 0 deletions test/JDBC/input/unpivot-vu-cleanup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ DROP TABLE [Sales$Data@2024];
GO
DROP TABLE [Global_データ_Sales];
GO
DROP TABLE Test_Case_Sensitivity;
GO

-- Drop temporary tables (if they still exist)
IF OBJECT_ID('tempdb..#temp_sales') IS NOT NULL
Expand Down
9 changes: 9 additions & 0 deletions test/JDBC/input/unpivot-vu-prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,13 @@ CREATE TABLE [Global_データ_Sales] (
GO

INSERT INTO [Global_データ_Sales] VALUES (1,2,3,4,5);
GO

CREATE TABLE Test_Case_Sensitivity (
IDENT INT PRIMARY KEY,
[Order Number] NVARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
OrderStatus NVARCHAR(20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[shipping-address] NVARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
TOTAL_AMOUNT DECIMAL(15,2)
);
GO
28 changes: 18 additions & 10 deletions test/JDBC/input/unpivot-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,24 @@ UNPIVOT (
) AS [Global_分析];
GO

-- BABEL-5761 Case insensitivity of column names in UNPIVOT result
-- Uppercase column names in unpivot source list
SELECT [ID_番号], [Amount_金額], [Quarter_四半期]
FROM [Global_データ_Sales]
UNPIVOT (
[Amount_金額] FOR [Quarter_四半期] IN (
[Q1_売上],
[Q2_売上]
)
) AS [Global_分析];
GO

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Test_Case_Sensitivity'
AND TABLE_SCHEMA = 'dbo'
ORDER BY ORDINAL_POSITION;
GO

-- KNOWN ISSUES
-- BABEL-5677 - Support more variations of UNPIVOT Syntax
Expand All @@ -853,14 +871,4 @@ GO
-- Extra columns in result set when `SELECT alias.*`
SELECT unpvt.* FROM customer_turnover c
UNPIVOT (turnover FOR quarter IN (q1, q2, q3, q4)) AS unpvt;
GO
-- Uppercase column names in unpivot source list
SELECT [ID_番号], [Amount_金額], [Quarter_四半期]
FROM [Global_データ_Sales]
UNPIVOT (
[Amount_金額] FOR [Quarter_四半期] IN (
[Q1_売上],
[Q2_売上]
)
) AS [Global_分析];
GO
Loading