Segfault-Inc / Multicorn

Data Access Library
https://multicorn.org/
PostgreSQL License
697 stars 145 forks source link

Support for JOINs #262

Open alexguanga opened 3 years ago

alexguanga commented 3 years ago

Hi all,

We are trying to extract JOINS from the queries (or even the query itself would be helpful).

We are using https://github.com/gabfl/bigquery_fdw, which is built on top of https://github.com/Segfault-Inc/Multicorn. Now, if we try to PG join like SELECT col_a FROM foreign_table_a LEFT JOIN foreign_table_b USING (primary_key), the translation in BigQuery is SELECT col_a FROM foreign_table_a. This makes complete sense based on the bigquery_fdw's query builder.

However, is there any way to extract the foreign table I want to join?

snth commented 3 years ago

I'm not sure whether this is exactly the same but I think my issue is related. I have the following stylized example:

WITH config(param) AS (
    VALUES
        ('A')
--        , ('B')
)
SELECT
    *
FROM config AS cfg
LEFT JOIN LATERAL my_fdw AS fdw
    ON fdw.param = cfg.param
;

The code above works fine and my multicorn object receives Qual('param', '=', 'A') as a parameter. However when I enable the commented out line for ('B') then the quals received by my multicorn object are an empty list quals == [].

I thought that perhaps with a simple LEFT JOIN postgres only does the filtering at the end but I had hoped that with the LATERAL join multicorn would receive each qual in turn.

Any ideas on how I could achieve the desired behaviour? Basically I would like my multicorn API calls to loop over a set of configured values in some other table.