trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.21k stars 2.95k forks source link

Polymorphic table functions #1839

Closed findepi closed 3 months ago

findepi commented 4 years ago

Add support for polymorphic table functions (https://www.iso.org/standard/69776.html)

related PRs: https://github.com/trinodb/trino/pull/11336 https://github.com/trinodb/trino/pull/12350 https://github.com/trinodb/trino/pull/12338

This document was moved from: https://github.com/trinodb/trino/issues/11937 It serves the following purposes:

  1. Decompose, prioritise and schedule the work.
  2. Provide visibility into state of the task.
  3. Provide a place for discussion and questions.

Definitions

A Table Function is a function which returns a relation, as opposed to a scalar function which returns a single value. A Polymorphic Table Function (PTF) is a Table Function which fulfils at least one of the following conditions:

Specifically, the output type of the Polymorphic Table Function may depend on the arbitrary table passed as an argument.

Scope of the task

The scope of the task is to provide full support for Table Functions, including Polymorphic Table Functions.

Subtasks

Achieved functionality

Currently, any PTF can be supported, which can be entirely realised by a connector. The connector can "capture" the PTF invocation, and replace it with a ConnectorTableHandle, which represents the PTF result.

Following work

To provide full support for PTF, as in the SQL standard, we need to:

Follow-ups

Possible improvements to be implemented if desired:

emerson-zhao commented 4 years ago

How's it going now?

tooptoop4 commented 4 years ago

I guess this would be like MSSQL 'Linked Server' functionality: https://docs.microsoft.com/en-us/sql/t-sql/functions/openquery-transact-sql?view=sql-server-ver15 / https://docs.microsoft.com/en-us/sql/relational-databases/linked-servers/linked-servers-database-engine?view=sql-server-ver15

buremba commented 3 years ago

The issue looks old, is there any interest in implementing table functions at the moment?

It would be great if we can add the support for syntax as a start.

findepi commented 2 years ago

https://github.com/trinodb/trino/pull/11336 is just merged

zhicwu commented 2 years ago

Quick question: will mutation be supported? Sometimes we issue multi-statement query(or just a stored procedure) on target database, where the last statement is for updating.

I noticed Query not supported: ResultSetMetaData not available for query in unit test, but I'm not sure if this will be addressed in the future or it's by design - perhaps you can fixed metadata(e.g. affected_rows Long) for non-query statements?

findepi commented 2 years ago

Quick question: will mutation be supported? Sometimes we issue multi-statement query(or just a stored procedure) on target database, where the last statement is for updating.

@zhicwu you may want to see https://github.com/trinodb/trino/pull/12322

I noticed Query not supported: ResultSetMetaData not available for query in unit test, but I'm not sure if this will be addressed in the future or it's by design

https://github.com/trinodb/trino/pull/12325 is by design for queries reading data.

zhicwu commented 2 years ago

Thanks @findepi. Does it make sense to you to support PTF by both embedded jdbc connector and external bridge server? I think clickhouse-jdbc-bridge is something very similar to the latter. It's just an inmature thought, but maybe I can rewrite jdbc bridge to benefit both sides.

findepi commented 3 months ago

The feature is generally available. The various follow-ups possible, or bugs like https://github.com/trinodb/trino/issues/20398 are tracked as separate issues.

awesome work @kasiafi