Skip to content
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

Added support for sp_xml_preparedocument and sp_xml_removedocument procedures #3461

Open
wants to merge 10 commits into
base: BABEL_5_X_DEV
Choose a base branch
from

Conversation

harshdubey166
Copy link

@harshdubey166 harshdubey166 commented Feb 6, 2025

Description

Currently babelfish does not support procedures like sp_xml_preparedocument and sp_xml_removedocument. This PR adds support for the sp_xml_preparedocument and sp_xml_removedocument procedures.
The procedure sp_xml_preparedocument parses an XML text given as input , stores it at session level and returns a handle to this document, which can be used to fetch the document.
Similarly , the purpose of sp_xml_removedocument is to remove the internal representation of the XML document and invalidate that handle which was created using the sp_xml_preparedocument procedure.

The syntax for the procedures is as folllows:

  • sp_xml_preparedocument hdoc OUTPUT [ , xmltext ] [ , xpath_namespaces ] [ ; ]

    • hdoc is the handle to the newly created document. hdoc is an integer.
    • xmltext is the given XML document in text format. The default value is NULL.
    • xpath_namespaces is a text parameter which specifies the namespace declarations that are used in row and column XPath expressions in OPENXML. The default value is NULL.
  • sp_xml_removedocument hdoc [ ; ]

    • The handle to the already existing created document. A handle that isn't valid returns an error. hdoc is an integer.

BABEL-1168
Signed-off-by: Harsh Dubey harshdu@amazon.com

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.

…ocedures

Signed-off-by: Harsh Dubey <harshdu@amazon.com>
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 13173804274

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 74.985%

Totals Coverage Status
Change from base Build 13110163021: 0.003%
Covered Lines: 47083
Relevant Lines: 62790

💛 - Coveralls

Comment on lines 347 to 351
CREATE TEMPORARY TABLE IF NOT EXISTS SessionXMLDocuments (
Handle INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
Xml_content XML,
NamespaceDefinitions XML
) ON COMMIT PRESERVE ROWS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to prevent this table from dropping accidentally by end user (may be).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created catalog table instead of temporary table as we need to see the handles across the sessions. Now the drop issue is fixed.

@@ -333,3 +333,68 @@ 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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this changes, can you please try out following scenario?

create table #SessionXMLDocuments(handle text, xml)

insert some dummy rows in the this table

DECLARE @hdoc INT;
EXEC sp_xml_preparedocument @hdoc OUTPUT, '<root><child></root', 'xmlns:ns1="http://example.com/ns1"/>';
SELECT @hdoc as handle;
EXEC sp_xml_removedocument @hdoc;
GO

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to create the same table name as the new catalog table(sys.babelfish_xml_handles), it showed error that permission denied for sys schema.

Comment on lines 347 to 351
CREATE TEMPORARY TABLE IF NOT EXISTS SessionXMLDocuments (
Handle INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
Xml_content XML,
NamespaceDefinitions XML
) ON COMMIT PRESERVE ROWS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

xml_data XML;
ns_data XML;
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS SessionXMLDocuments (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is session specific can we name this using something like xml_data_sha256(pid of backend) to prevent name collisions? also would likely decrease chances of dropping this table.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are now creating a catalog table instead of session specific table


CREATE OR REPLACE PROCEDURE sys.sp_xml_preparedocument(
INOUT hdoc INTEGER,
IN xmltext sys.VARCHAR DEFAULT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test cases to check max length limits of arguments

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added that tests in the test file.

RAISE EXCEPTION 'The XML input is not well-formed.';
END IF;

IF xpath_namespaces IS NULL OR length(xpath_namespaces)=0 OR xml_is_well_formed_document(xpath_namespaces) THEN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use fully qualified name whereever possible to avoid future issues

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, got that.

@shah-nirmit
Copy link
Contributor

Also as Rob mentioned there are procedures in T-SQL which returns a list of handles based on backend/session Id, I dont think temp table approach will be able to support that usecase

Harsh Dubey added 9 commits February 14, 2025 15:22
Signed-off-by: Harsh Dubey <harshdu@amazon.com>
… in upgrades file

Signed-off-by: Harsh Dubey <harshdu@amazon.com>
…in C instead of pgsql. Also implemented callback function to remove the entries on exiting the session.

Signed-off-by: Harsh Dubey <harshdu@amazon.com>
…ction in the catalog.c file to mark it as an extended catalog table. Also removed the dump restore condition as we don't need that since we are storing sesion based data.

Signed-off-by: Harsh Dubey <harshdu@amazon.com>
Signed-off-by: Harsh Dubey <harshdu@amazon.com>
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.

4 participants