Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions contrib/babelfishpg_tsql/runtime/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ extern bool inited_ht_tsql_cast_info;
extern bool inited_ht_tsql_datatype_precedence_info;
extern PLtsql_execstate *get_outermost_tsql_estate(int *nestlevel);
extern char *replace_special_chars_fts_impl(char *input_str);
extern void get_xml_data_and_namespace_data(int document_id, xmltype **xml_data, xmltype **ns_data);

#ifdef USE_LIBXML
HTAB *ht_xmlNode2Id = NULL;
Expand Down Expand Up @@ -5183,7 +5182,7 @@ get_bbf_pivot_tuplestore(const char *sourcetext,
* The count of extracted namespaces is stored in ns_count. If no namespaces are found,
* ns_names and ns_uris are set to NULL and ns_count to 0.
*/
static void
void
extract_namespaces_from_xml(xmltype *ns_data, char ***ns_names, char ***ns_uris, int *ns_count)
{
xmlDocPtr doc;
Expand Down
26 changes: 0 additions & 26 deletions contrib/babelfishpg_tsql/sql/sys_function_helpers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3022,32 +3022,6 @@ $BODY$
LANGUAGE plpgsql
STABLE;

CREATE OR REPLACE FUNCTION sys.babelfish_openxml(IN DocHandle BIGINT)
RETURNS TABLE (XmlData XML)
AS
$BODY$
DECLARE
XmlDocument$data XML;
BEGIN

SELECT t.XmlData
INTO STRICT XmlDocument$data
FROM sys$openxml t
WHERE t.DocID = DocHandle;

RETURN QUERY SELECT XmlDocument$data;

EXCEPTION
WHEN SQLSTATE '42P01' OR SQLSTATE 'P0002' THEN
RAISE EXCEPTION '%','Could not find prepared statement with handle '||CASE
WHEN DocHandle IS NULL THEN 'null'
ELSE DocHandle::TEXT
END;
END;
$BODY$
LANGUAGE plpgsql
STABLE;

CREATE OR REPLACE FUNCTION sys.babelfish_parse_to_date(IN p_datestring TEXT,
IN p_culture TEXT DEFAULT '')
RETURNS DATE
Expand Down
12 changes: 12 additions & 0 deletions contrib/babelfishpg_tsql/sql/sys_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4152,6 +4152,18 @@ 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;

/* Function to retrieve XML doc from temp table using doc_id (for openxml) */
CREATE OR REPLACE FUNCTION sys.tsql_openxml_get_xmldoc(int)
RETURNS xml
AS 'babelfishpg_tsql', 'tsql_openxml_get_xmldoc'
LANGUAGE C STRICT;

/* This function generates XPath expressions for OPENXML columns */
CREATE OR REPLACE FUNCTION sys.tsql_openxml_get_colpattern(text,int)
RETURNS sys.nvarchar
AS 'babelfishpg_tsql', 'tsql_openxml_get_colpattern'
LANGUAGE C STRICT;

CREATE OR REPLACE FUNCTION sys.sp_datatype_info_helper(
IN odbcVer smallint,
IN is_100 bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ 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;

CREATE OR REPLACE FUNCTION sys.openxml_simple(document_id INT,
rowpattern TEXT,
flags INTEGER DEFAULT 0)
Expand Down Expand Up @@ -283,6 +293,20 @@ BEGIN
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;

DO $$
DECLARE
exception_message text;
BEGIN
ALTER FUNCTION sys.babelfish_openxml RENAME TO babelfish_openxml_deprecated_in_5_4_0;
EXCEPTION WHEN OTHERS THEN
GET STACKED DIAGNOSTICS
exception_message = MESSAGE_TEXT;
RAISE WARNING '%', exception_message;
END;
$$;

CALL sys.babelfish_drop_deprecated_object('function', 'sys', 'babelfish_openxml_deprecated_in_5_4_0');

-- Drops the temporary procedure used by the upgrade script.
-- Please have this be one of the last statements executed in this upgrade script.
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar);
Expand Down
4 changes: 3 additions & 1 deletion contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-decl.y
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
%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 @@ -137,6 +139,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
77 changes: 77 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 @@ -1836,6 +1836,83 @@ openxml_expr: OPENXML '(' a_expr ',' a_expr ')' opt_alias_clause
/* map to OPENXML_SIMPLE */
$$ = (Node*) n;
}
| OPENXML '(' a_expr ',' a_expr ')' WITH_table TABLE qualified_name opt_alias_clause
{
RangeTableFunc *n = makeNode(RangeTableFunc);
n->docexpr = $3;
n->rowexpr = $5;
n->location = @1;
/* Default flag is 0 when not specified */
n->namespaces = list_make1(makeIntConst(0, @1));
n->columns = list_make1($9);
n->alias = $10;
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ',' a_expr ')' WITH_table TABLE qualified_name opt_alias_clause
{
RangeTableFunc *n = makeNode(RangeTableFunc);
n->docexpr = $3;
n->rowexpr = $5;
n->location = @1;
n->namespaces = list_make1((Node *)$7);
n->columns = list_make1($11);
n->alias = $12;
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ')' WITH_paren '(' openxml_column_list ')' opt_alias_clause
{
RangeTableFunc *n = makeNode(RangeTableFunc);
n->docexpr = $3;
n->rowexpr = $5;
n->location = @1;
n->columns = $9;
/* Default flag is 0 when not specified */
n->namespaces = list_make1(makeIntConst(0, @1));
n->alias = $11;
$$ = (Node *) n;
}
| OPENXML '(' a_expr ',' a_expr ',' a_expr ')' WITH_paren '(' openxml_column_list ')' opt_alias_clause
{
RangeTableFunc *n = makeNode(RangeTableFunc);
n->docexpr = $3;
n->rowexpr = $5;
n->columns = $11;
n->location = @1;
n->namespaces = list_make1((Node *)$7);
n->alias = $13;
$$ = (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;
fc->colexpr = NULL;
fc->coldefexpr = 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->coldefexpr = NULL;
fc->location = @1;

$$ = (Node *) fc;
}
;

openjson_expr: OPENJSON '(' a_expr ')' opt_alias_clause
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
3 changes: 1 addition & 2 deletions contrib/babelfishpg_tsql/src/extendedproperty.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ static void init_scan_key(ScanKeyData *scanKey,
static void sp_execextended_property(PG_FUNCTION_ARGS, ExtendedPropertyProc proc);
static bool get_extended_property_from_tuple(Relation relation, HeapTuple tuple,
Datum *values, bool *nulls, int len);
static char* get_value_by_name_from_array(ArrayType *array, const char *name);

static void
init_scan_key(ScanKeyData *scanKey,
Expand Down Expand Up @@ -923,7 +922,7 @@ fn_listextendedproperty(PG_FUNCTION_ARGS)
extern const char *ATTOPTION_BBF_ORIGINAL_TABLE_NAME;
extern const char *ATTOPTION_BBF_ORIGINAL_NAME;

static char*
char*
get_value_by_name_from_array(ArrayType *array, const char *name)
{
int i;
Expand Down
1 change: 1 addition & 0 deletions contrib/babelfishpg_tsql/src/extendedproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef enum ExtendedPropertyType
} ExtendedPropertyType;

extern const char *const ExtendedPropertyTypeNames[];
extern char *get_value_by_name_from_array(ArrayType *array, const char *name);

extern void delete_extended_property(int16 db_id,
const char *type,
Expand Down
Loading