-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add table function to execute stored procedure in SQLServer #16696
Add table function to execute stored procedure in SQLServer #16696
Conversation
These methods can be reused for Procedures PTF - Extract building columns from ResultSetMetaData as a separate method. - Extract creating connection based on session
d676f4a
to
a584b86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% nits
The ``procedure`` function allows you to run stored procedures on the underlying | ||
database directly. It requires syntax native to SQL Server, because the full query | ||
is pushed down and processed in SQL Server. In order to use this table function we | ||
need to set ``sqlserver.stored-procedure-table-function.enabled`` to ``true``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write why this toggle exists. To mention because of security reasons and the fact it is experimental its signature may change in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it as a warning
plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/TestingH2JdbcClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-sqlserver/src/main/java/io/trino/plugin/sqlserver/SqlServerClient.java
Show resolved
Hide resolved
plugin/trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/BaseSqlServerConnectorTest.java
Outdated
Show resolved
Hide resolved
a584b86
to
77fc2a9
Compare
@kokosing AC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple quick changes needed to the docs, otherwise the docs LGTM.
The ``procedure`` function allows you to run stored procedures on the underlying | ||
database directly. It requires syntax native to SQL Server, because the full query | ||
is pushed down and processed in SQL Server. In order to use this table function we | ||
need to set ``sqlserver.stored-procedure-table-function.enabled`` to ``true``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"we need to set ... to true
" -> "set the ... catalog configuration property to true
"
|
||
.. warning:: | ||
|
||
This feature is experimental only. The function signature might change in the future and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"signature" -> "syntax"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "in the future"
.. warning:: | ||
|
||
This feature is experimental only. The function signature might change in the future and | ||
it could be backward incompatible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "it could"
|
||
|
||
The follow example runs the stored procedure ``employee_sp`` in the ``example`` catalog and the | ||
``example_schema`` in the underlying SQL Server database:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"example_schema
in the" -> "example_schema
schema in the"
FROM | ||
TABLE( | ||
example.system.procedure( | ||
query => 'EXECUTE example_schema.employee_sp 0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this added whitespace after query
needed or was that added in error?
) | ||
); | ||
|
||
If the stored procedure ``employee_sp`` requires any input :: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a bit more descriptive, like "requires any input, append the parameter value to the procedure statement::"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, lgtm
@@ -152,6 +160,10 @@ public Optional<SystemTable> getSystemTable(ConnectorSession session, SchemaTabl | |||
@Override | |||
public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(ConnectorSession session, ConnectorTableHandle table, Constraint constraint) | |||
{ | |||
if (table instanceof JdbcProcedureHandle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd extract table instanceof JdbcProcedureHandle
as a simple static method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added,
return storedProcedureTableFunctionEnabled; | ||
} | ||
|
||
@Config("sqlserver.stored-procedure-table-function.enabled") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs say it's experimental, and there is no experimental prefix here. Can you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing it out. Added prefix.
@Test | ||
public void testProcedureWithInsertOperation() | ||
{ | ||
try (TestTable table = new TestTable(onRemoteDatabase(), "table_to_insert", "(id BIGINT)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. You stated in PR description that non-select statements are not supported. And here we have insert, delete and update...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a test that fails for these operations and also check if doesn't modify the underlying data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally missed the fact that these are negative assertions.
77fc2a9
to
104f7e9
Compare
@jhlodin AC |
104f7e9
to
bd76ee3
Compare
bd76ee3
to
75eebe6
Compare
Description
A dedicated table function which allows us to run stored procedures in SQLServer. We can't use existing query table function - as it wraps with inside a query like
SELECT * FROM (EXECUTE my_procedure) o
- so we are handing them via a different function. All the pushdown are disabled forJdbcProcedureHandle
resolved by thisProcedure
.Slightly different implementation from #15982
Limitation
Example
Release notes
( ) This is not user-visible or docs only and no release notes are required.
(x) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: