Skip to content

Commit 9be3183

Browse files
Added support for OPENXML with WITH clause (#133)
This PR adds support for OPENXML with WITH clause. OPENXML provides a rowset view over an XML document. Since OPENXML is a rowset provider and it returns a set of rows, we can use OPENXML in the FROM clause of a T-SQL statement just as we can use any other table, view, or table-valued function. The WITH clause in OPENXML provides a rowset format (and additional mapping information as required) by using either SchemaDeclaration or specifying an existing TableName. Currently Babelfish does not have support for openxml. So the primary objective is to add support for OPENXML with WITH clause. The syntax of openxml is as follows : OPENXML ( idoc int [ in ] , rowpattern nvarchar [ in ], [ flags byte [ in ] ] ) [ WITH ( SchemaDeclaration | TableName ) ] Arguments idoc The document handle of the internal representation of an XML document. The internal representation of an XML document is created by calling sp_xml_preparedocument. rowpattern The XPath pattern used to identify the nodes to be processed as rows. The nodes come from the XML document whose handle is passed in the idoc parameter. flags Indicates the mapping used between the XML data and the relational rowset, and how the spill-over column is filled. flags is an optional input parameter, and can be one of the following values. The WITH clause provides a rowset format (and additional mapping information as required) by using either SchemaDeclaration or specifying an existing TableName. If the optional WITH clause isn't specified, the results are returned in an edge table format. Edge tables represent the fine-grained XML document structure (such as element/attribute names, the document hierarchy, the namespaces, PIs, and so on) in a single table. BABEL-3635 Extensions PR : amazon-aurora/babelfish_extensions#76 Signed-off-by: Harsh Dubey [email protected]
1 parent b88c284 commit 9be3183

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/backend/parser/parse_clause.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ sortby_nulls_hook_type sortby_nulls_hook = NULL;
5656

5757
optimize_explicit_cast_hook_type optimize_explicit_cast_hook = NULL;
5858

59+
pre_transform_openxml_columns_hook_type pre_transform_openxml_columns_hook = NULL;
60+
5961
static int extractRemainingColumns(ParseState *pstate,
6062
ParseNamespaceColumn *src_nscolumns,
6163
List *src_colnames,
@@ -711,6 +713,13 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
711713
constructName = "XMLTABLE";
712714
docType = XMLOID;
713715

716+
/*
717+
* Hook to allow extensions to pre-process OPENXML column definitions
718+
* before standard XMLTABLE transformation.
719+
*/
720+
if (pre_transform_openxml_columns_hook && tf->functype == TFT_XMLTABLE)
721+
pre_transform_openxml_columns_hook(pstate, rtf);
722+
714723
/*
715724
* We make lateral_only names of this level visible, whether or not the
716725
* RangeTableFunc is explicitly marked LATERAL. This is needed for SQL

src/include/parser/parse_clause.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ extern PGDLLEXPORT optimize_explicit_cast_hook_type optimize_explicit_cast_hook;
6262
/* functions in parse_jsontable.c */
6363
extern ParseNamespaceItem *transformJsonTable(ParseState *pstate, JsonTable *jt);
6464

65+
/* Hook for preprocessing OPENXML column definitions before XMLTABLE transformation */
66+
typedef void (*pre_transform_openxml_columns_hook_type) (ParseState *pstate, RangeTableFunc *rtf);
67+
extern PGDLLIMPORT pre_transform_openxml_columns_hook_type pre_transform_openxml_columns_hook;
68+
6569
#endif /* PARSE_CLAUSE_H */

0 commit comments

Comments
 (0)