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.49k stars 3.02k forks source link

Add Support for SQL Server `SYNONYM`s for Tables and Views #24206

Open daveedgn opened 1 day ago

daveedgn commented 1 day ago

Similar to the Oracle connector's support for SYNONYMs, please add support for the SQL Server connector.

Trino does not have visibility into all database objects in a SQL Server catalog. If we used a pass-thru query, we would be able to see it!

This should be included in metadata queries as well, so that database clients (e.g. DBeaver) connecting to Trino are aware of the "tables".

E.g.

-- Table not found
select * from foobar.dbo.enum_ABC;

-- Works
select * from table(foobar.system.query('SELECT * from enum_ABC'));

-- No results
select * from table(foobar.system.query('
    SELECT *
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_NAME = ''enum_ABC''
'));

-- We are able to find it via the database's `sys.synonyms` table
select * from table(foobar.system.query('SELECT * from sys.synonyms'));

For our purposes, we only care about viewing synonyms for TABLEs, VIEWs (and MATERIALIZED VIEWs).