Skip to content

Conversation

harshdubey166
Copy link
Contributor

@harshdubey166 harshdubey166 commented Jun 10, 2025

Description

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.

Engine PR : babelfish-for-postgresql/postgresql_modified_for_babelfish#587
Signed-off-by: Harsh Dubey [email protected]
Authored-by: Harsh Dubey [email protected]

Issues Resolved

BABEL-3635, BABEL-6045

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@coveralls
Copy link
Collaborator

coveralls commented Jun 10, 2025

Pull Request Test Coverage Report for Build 17972673400

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 110 of 122 (90.16%) changed or added relevant lines in 5 files are covered.
  • 214 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.03%) to 76.632%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_tsql/src/procedures.c 29 33 87.88%
contrib/babelfishpg_tsql/src/hooks.c 73 81 90.12%
Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/pltsql_utils.c 1 92.28%
contrib/babelfishpg_tsql/src/guc.c 5 97.08%
contrib/babelfishpg_tsql/src/hooks.c 208 86.07%
Totals Coverage Status
Change from base Build 17918846922: 0.03%
Covered Lines: 51664
Relevant Lines: 67418

💛 - Coveralls

Signed-off-by: Harsh Dubey <[email protected]>
Harsh Dubey added 2 commits September 17, 2025 13:06
Deepesh125
Deepesh125 previously approved these changes Sep 23, 2025
Harsh Dubey added 5 commits September 23, 2025 16:49
Deepesh125 pushed a commit to babelfish-for-postgresql/postgresql_modified_for_babelfish that referenced this pull request Sep 24, 2025
…587)

To add support for Openxml with WITH clause, this commit exposes wrapper hooks to facilitate support for T-SQL
OPENXML functionalities by allowing Babelfish to customised XML table processing during query parsing.

Added two new hooks:
1. pre_transform_openxml_columns_hook , to allow extensions to pre-process OPENXML column definitions
before standard XMLTABLE transformation.
2. openxml_set_namespaces_hook, which fetches and register namespaces in xpath context.

Extensions PR : babelfish-for-postgresql/babelfish_extensions#3820

Task: BABEL-3635, BABEL 6045
Signed-off-by: Harsh Dubey <[email protected]>
@Deepesh125 Deepesh125 merged commit 2e9f584 into babelfish-for-postgresql:BABEL_5_X_DEV Sep 24, 2025
47 checks passed
Vineetha125 pushed a commit to amazon-aurora/babelfish_extensions that referenced this pull request Sep 25, 2025
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 TSQL query 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.

Primary objective of this commit 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.

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) as a single table.

Engine PR : babelfish-for-postgresql/postgresql_modified_for_babelfish#587

Task: BABEL-3635, BABEL-6045
Signed-off-by: Harsh Dubey <[email protected]>
@harshdubey166 harshdubey166 deleted the BABEL_3635 branch September 30, 2025 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants