Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b1f3a60
Added the changes of sp_xml_preparedocument and sp_xml_removedocument…
Jun 10, 2025
9deec91
Add the changes of stored procedures
Jun 10, 2025
793f7c3
Fixed the upgrade file to add the changes of stored procedures
Jun 10, 2025
adcabd0
Add support for openxml
Jun 10, 2025
5823430
fixing the failures
Jun 10, 2025
a3d44d1
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into BABEL_3635
harshdubey166 Jun 11, 2025
b3fd2ae
Fixed the files to add the same changes of stored procedures
Jun 11, 2025
b543c5d
Added the function name in output file of expected dependency & corre…
Jun 13, 2025
3c1714a
Fixed the output file of expected create
Jun 15, 2025
eed4015
Merge branch 'BABEL_5_X_DEV' into BABEL_3635
Jun 15, 2025
1dcd1a4
Fixed the output file of expected_create
Jun 16, 2025
a6a63fd
New approach for openxml
Jun 19, 2025
5bb932d
Fixed new approach of openxxml
Jun 19, 2025
691ee2c
Added the changes of stored procedures
Jun 20, 2025
307e378
Fixed the indentations
Jun 20, 2025
4aecbff
Merge branch 'BABEL_5_X_DEV' into BABEL_3635
Jun 20, 2025
803ab57
Merge branch 'BABEL_5_X_DEV' into BABEL_3635
Jun 20, 2025
0b3ae28
Retrigger workflows
Jun 20, 2025
56e4616
Added the cases of flag value more than 3
Jun 22, 2025
4d61056
Retrigger workflows
Jun 23, 2025
40144de
Added some more testcases of openxml with clause
Jun 24, 2025
4c1a102
Added testcases of cross/outer apply
Jun 25, 2025
00e1918
fixed not null constraint in the test plan
Jun 25, 2025
c2bc355
Fixed the expected file of openxml tests
Jun 25, 2025
ec85e81
Retrigger workflows
Jun 25, 2025
89bb834
Merge remote-tracking branch 'upstream/BABEL_5_X_DEV' into BABEL_3635
Sep 11, 2025
bfcecef
Merge remote-tracking branch 'upstream/BABEL_5_X_DEV' into BABEL_3635
Sep 15, 2025
6f73ae6
Merge remote-tracking branch 'upstream/BABEL_5_X_DEV' into BABEL_3635
Sep 15, 2025
04226b4
Adding the changes of prepare and remove doc
Sep 15, 2025
0b692fe
Rerun workflows
Sep 16, 2025
5a93636
Added changes in latest upgrade script
Sep 16, 2025
ff99413
Refactor code
Sep 16, 2025
dbd2fde
Assigned doc_id to rtf->docexpr node
Sep 16, 2025
e35b187
Updated the schedule files
Sep 17, 2025
ad68fa3
Adding namespaces support in openxml with clause
Sep 17, 2025
4d75cc7
Refactored code
Sep 17, 2025
ce0e16d
Merge remote-tracking branch 'upstream/BABEL_5_X_DEV' into BABEL_3635
Sep 22, 2025
6f1376b
Added some changes for openxml with clause
Sep 22, 2025
8d1f939
Deprecated old openxml function
Sep 22, 2025
64e9c1f
Rerun workflows
Sep 22, 2025
1f67d96
Rerun workflows
Sep 22, 2025
6b33409
Refactor code
Sep 22, 2025
4a4a045
Merge remote-tracking branch 'upstream/BABEL_5_X_DEV' into BABEL_3635
Sep 22, 2025
3562c0c
Added tests for openxml functions
Sep 23, 2025
463243a
Fixing failures
Sep 23, 2025
2076c4f
Added the openxml before 17_7 files
Sep 23, 2025
eb0a5aa
Fixing failures
Sep 24, 2025
40060c0
Defined the functions as extern in pltsql.h
Sep 24, 2025
2c43eb0
Mark the headers of functions as extern
Sep 24, 2025
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
10 changes: 10 additions & 0 deletions contrib/babelfishpg_tsql/sql/sys_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3998,6 +3998,16 @@ CREATE OR REPLACE FUNCTION sys.openjson_with(json_string text, path text, VARIAD
RETURNS SETOF RECORD
AS 'babelfishpg_tsql', 'tsql_openjson_with' LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

CREATE OR REPLACE FUNCTION sys.tsql_openxml_get_xmldoc(int)
RETURNS xml
AS 'babelfishpg_tsql', 'tsql_openxml_get_xmldoc'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

CREATE OR REPLACE FUNCTION sys.tsql_openxml_get_colpattern(text,int)
RETURNS sys.nvarchar
AS 'babelfishpg_tsql', 'tsql_openxml_get_colpattern'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

CREATE OR REPLACE FUNCTION sys.sp_datatype_info_helper(
IN odbcVer smallint,
IN is_100 bool,
Expand Down
17 changes: 17 additions & 0 deletions contrib/babelfishpg_tsql/sql/sys_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,20 @@ GRANT EXECUTE on PROCEDURE sys.sp_enum_oledb_providers() TO PUBLIC;
CREATE OR REPLACE PROCEDURE sys.sp_reset_connection()
AS 'babelfishpg_tsql', 'sp_reset_connection_internal' LANGUAGE C;
GRANT EXECUTE ON PROCEDURE sys.sp_reset_connection() TO PUBLIC;

CREATE OR REPLACE PROCEDURE sys.sp_xml_preparedocument( INOUT "@hdoc" INTEGER,
IN "@xmltext" sys.VARCHAR DEFAULT NULL,
IN "@xpath_namespaces" sys.VARCHAR DEFAULT NULL )
AS 'babelfishpg_tsql', 'sp_xml_preparedocument'
LANGUAGE C;

GRANT EXECUTE ON PROCEDURE sys.sp_xml_preparedocument( INOUT "@hdoc" INTEGER,
IN "@xmltext" sys.VARCHAR ,
IN "@xpath_namespaces" sys.VARCHAR )
TO PUBLIC;

CREATE OR REPLACE PROCEDURE sys.sp_xml_removedocument( IN "@hdoc" INTEGER )
AS 'babelfishpg_tsql', 'sp_xml_removedocument'
LANGUAGE C;

GRANT EXECUTE ON PROCEDURE sys.sp_xml_removedocument( IN INTEGER ) TO PUBLIC;
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,36 @@ WHERE sch.nspname = t.typnamespace::regnamespace::name
-- Please have this be one of the last statements executed in this upgrade script.
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar);

CREATE OR REPLACE PROCEDURE sys.sp_xml_preparedocument(
INOUT "@hdoc" INTEGER,
IN "@xmltext" sys.VARCHAR DEFAULT NULL,
IN "@xpath_namespaces" sys.VARCHAR DEFAULT NULL
)
AS 'babelfishpg_tsql', 'sp_xml_preparedocument'
LANGUAGE C;
GRANT EXECUTE ON PROCEDURE sys.sp_xml_preparedocument(
INOUT INTEGER, IN sys.varchar, IN sys.varchar
) TO PUBLIC;

CREATE OR REPLACE PROCEDURE sys.sp_xml_removedocument(
IN "@hdoc" INTEGER
)
AS 'babelfishpg_tsql', 'sp_xml_removedocument'
LANGUAGE C;
GRANT EXECUTE ON PROCEDURE sys.sp_xml_removedocument(
IN INTEGER
) TO PUBLIC;

CREATE OR REPLACE FUNCTION sys.tsql_openxml_get_xmldoc(int)
RETURNS xml
AS 'babelfishpg_tsql', 'tsql_openxml_get_xmldoc'
LANGUAGE C STRICT;

CREATE OR REPLACE FUNCTION sys.tsql_openxml_get_colpattern(text,int)
RETURNS sys.nvarchar
AS 'babelfishpg_tsql', 'tsql_openxml_get_colpattern'
LANGUAGE C STRICT;

-- After upgrade, always run analyze for all babelfish catalogs.
CALL sys.analyze_babelfish_catalogs();
-- Reset search_path to not affect any subsequent scripts
Expand Down
7 changes: 5 additions & 2 deletions contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-decl.y
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
%type <list> openjson_col_defs
%type <str> optional_path
%type <boolean> optional_asJson
%type <node> openxml_expr
%type <list> openxml_column_list
%type <node> openxml_column_el

%type <node> tsql_opt_arg_dflt
%type <node> tsql_opt_null_keyword
Expand Down Expand Up @@ -117,7 +120,7 @@
TSQL_NOCHECK TSQL_NOLOCK TSQL_READUNCOMMITTED TSQL_UPDLOCK TSQL_REPEATABLEREAD
TSQL_READCOMMITTED TSQL_TABLOCK TSQL_TABLOCKX TSQL_PAGLOCK TSQL_ROWLOCK
TSQL_TOP TSQL_PERCENT
TSQL_AUTO TSQL_EXPLICIT TSQL_RAW TSQL_PATH TSQL_FOR TSQL_BASE64 TSQL_ROOT TSQL_READPAST TSQL_XLOCK TSQL_NOEXPAND OPENJSON JSON_MODIFY
TSQL_AUTO TSQL_EXPLICIT TSQL_RAW TSQL_PATH TSQL_FOR TSQL_BASE64 TSQL_ROOT TSQL_READPAST TSQL_XLOCK TSQL_NOEXPAND OPENJSON OPENXML JSON_MODIFY
TSQL_JSON TSQL_INCLUDE_NULL_VALUES TSQL_WITHOUT_ARRAY_WRAPPER
TSQL_MEMBER TSQL_SERVER
TSQL_WINDOWS TSQL_CERTIFICATE TSQL_DEFAULT_DATABASE TSQL_DEFAULT_LANGUAGE TSQL_HASHED
Expand All @@ -134,6 +137,6 @@
* otherwise the parser cannot tell between 'WITH' and 'WITH (' and thus
* lead to a shift/reduce conflict.
*/
%token WITH_paren TSQL_HINT_START_BRACKET UPDATE_paren
%token WITH_paren TSQL_HINT_START_BRACKET UPDATE_paren WITH_table

%left TSQL_CROSS TSQL_OUTER TSQL_UNPIVOT
116 changes: 116 additions & 0 deletions contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y
Original file line number Diff line number Diff line change
Expand Up @@ -1779,13 +1779,129 @@ table_ref: relation_expr tsql_table_hint_expr
*/
$$ = (Node *) $1;
}
| TSQL_APPLY openxml_expr
{
/*
* This case handles openxml cross/outer apply
*/
$$ = (Node *) $2;
}
| openxml_expr
{
/*
* Standard openxml case
*/
$$ = (Node *) $1;
}
| table_ref TSQL_UNPIVOT tsql_unpivot_clause alias_clause
{
List *unpivot_info = list_make3($1, (List *)$3, $4);
$$ = tsql_unpivot_transformation(unpivot_info, @1);
}
;

openxml_expr: OPENXML '(' a_expr ',' a_expr ')' opt_alias_clause
{
Openxml_expr *n = makeNode(Openxml_expr);
n->tsql_docid = $3;
n->rowexpr = $5;
n->alias = $7;
n->columns = NIL;
n->location = @1;
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ',' a_expr ')' opt_alias_clause
{
Openxml_expr *n = makeNode(Openxml_expr);
n->tsql_docid = $3;
n->rowexpr = $5;
n->tsql_flag = $7;
n->columns = NIL;
n->alias = $9;
n->location = @1;
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ')' WITH_table TABLE qualified_name opt_alias_clause
{
Openxml_expr *n = makeNode(Openxml_expr);
n->tsql_docid = $3;
n->rowexpr = $5;
n->table_ref = $9;
n->alias = $10;
n->location = @1;
/* Default flag is 0 when not specified */
n->tsql_flag = makeIntConst(0, -1);
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ',' a_expr ')' WITH_table TABLE qualified_name opt_alias_clause
{
Openxml_expr *n = makeNode(Openxml_expr);
n->tsql_docid = $3;
n->rowexpr = $5;
n->tsql_flag = $7;
n->table_ref = $11;
n->alias = $12;
n->location = @1;
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ')' WITH_paren '(' openxml_column_list ')' opt_alias_clause
{
Openxml_expr *n = makeNode(Openxml_expr);
n->tsql_docid = $3;
n->rowexpr = $5;
n->columns = $9;
n->alias = $11;
n->table_ref = NULL;
n->location = @1;
/* Default flag is 0 when not specified */
n->tsql_flag = makeIntConst(0, -1);
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ',' a_expr ')' WITH_paren '(' openxml_column_list ')' opt_alias_clause
{
Openxml_expr *n = makeNode(Openxml_expr);
n->tsql_docid = $3;
n->rowexpr = $5;
n->tsql_flag = $7;
n->columns = $11;
n->alias = $13;
n->table_ref = NULL;
n->location = @1;
$$ = (Node *) n;
}
;

openxml_column_list: openxml_column_el { $$ = list_make1($1); }
| openxml_column_list ',' openxml_column_el { $$ = lappend($1, $3); }
;

openxml_column_el:
ColId Typename
{
RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);

fc->colname = $1;
fc->typeName = $2;
/* Set a default XPath expression based on column name */
/* fc->colexpr = (Node *) makeStringConst(psprintf("@%s", $1), @1); */
/* fc->colexpr = makeStringConst($1, @1); */
fc->colexpr = NULL;
fc->location = @1;

$$ = (Node *) fc;
}
| ColId Typename Sconst
{
RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
fc->colname = $1;
fc->typeName = $2;
fc->colexpr = (Node *) makeStringConst($3, @1);
fc->location = @1;

$$ = (Node *) fc;
}
;

openjson_expr: OPENJSON '(' a_expr ')' opt_alias_clause
{
RangeFunction *n = makeNode(RangeFunction);
Expand Down
1 change: 1 addition & 0 deletions contrib/babelfishpg_tsql/src/backend_parser/kwlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ PG_KEYWORD("old_password", TSQL_OLD_PASSWORD, UNRESERVED_KEYWORD)
PG_KEYWORD("on", ON, RESERVED_KEYWORD)
PG_KEYWORD("only", ONLY, RESERVED_KEYWORD)
PG_KEYWORD("openjson", OPENJSON, COL_NAME_KEYWORD)
PG_KEYWORD("openxml", OPENXML, COL_NAME_KEYWORD)
PG_KEYWORD("operator", OPERATOR, UNRESERVED_KEYWORD)
PG_KEYWORD("option", OPTION, RESERVED_KEYWORD)
PG_KEYWORD("options", OPTIONS, UNRESERVED_KEYWORD)
Expand Down
2 changes: 2 additions & 0 deletions contrib/babelfishpg_tsql/src/backend_parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ pgtsql_base_yylex(YYSTYPE *lvalp, YYLTYPE * llocp, core_yyscan_t yyscanner)
case '(':
cur_token = WITH_paren;
break;
case TABLE:
cur_token = WITH_table;
}
break;
case '(':
Expand Down
Loading
Loading