cube-js / cube

šŸ“Š Cube ā€” The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.96k stars 1.78k forks source link

SQL Error with metabase #8201

Open itestyoy opened 6 months ago

itestyoy commented 6 months ago

Hi! When we started using Metabase 0.49.7, we began encountering an error with our queries. What does this error mean?

SELECT   tmp.table_cat,
         tmp.table_schem,
         tmp.table_name,
         tmp.non_unique,
         tmp.index_qualifier,
         tmp.index_name,
         tmp.type,
         tmp.ordinal_position,
         trim(both '\"' FROM pg_catalog.pg_get_indexdef(tmp.ci_oid, tmp.ordinal_position, false)) AS column_name,
         CASE tmp.am_name
                  WHEN 'btree' THEN
                           CASE tmp.i_indoption[tmp.ORDINAL_POSITION - 1] & 1::smallint
                                    WHEN 1 THEN 'D'
                                    ELSE 'A'
                           END
                  ELSE NULL
         END AS asc_or_desc,
         tmp.cardinality,
         tmp.pages,
         tmp.filter_condition
FROM     (
                SELECT NULL              AS table_cat,
                       n.nspname         AS table_schem,
                       ct.relname        AS table_name,
                       NOT i.indisunique AS non_unique,
                       NULL              AS index_qualifier,
                       ci.relname        AS index_name,
                       CASE i.indisclustered
                              WHEN true THEN 1
                              ELSE
                                     CASE am.amname
                                            WHEN 'hash' THEN 2
                                            ELSE 3
                                     END
                       END                                              AS type,
                       (information_schema._pg_expandarray(i.indkey)).n AS ordinal_position,
                       ci.reltuples                                     AS cardinality,
                       ci.relpages                                      AS pages,
                       pg_catalog.pg_get_expr(i.indpred, i.indrelid)    AS filter_condition,
                       ci.oid                                           AS ci_oid,
                       i.indoption                                      AS i_indoption,
                       am.amname                                        AS am_name
                FROM pg_catalog.pg_class ct
                JOIN pg_catalog.pg_namespace n ON (ct.relnamespace = n.oid)
                JOIN pg_catalog.pg_index I ON (ct.oid = i.indrelid)
                JOIN pg_catalog.pg_class ci ON (ci.oid = i.indexrelid)
                JOIN pg_catalog.pg_am am ON (ci.relam = am.oid)
                WHERE  true
                AND    n.nspname = 'public'
                AND    ct.relname = 'calendar') AS tmp
ORDER BY non_unique,
         type,
         index_name,
         ordinal_position;
{
  "securityContext": {},
  "appName": "Metabase v0.49.7 [e5c35f15-2ae1-400d-b22a-f065f293da0a]",
  "protocol": "postgres",
  "apiType": "sql"
} 
Error during processing PostgreSQL message: CubeError: Error during planning:
The expression to get an indexed field is only valid for `List` and `Struct` types, actual: Utf8

v0.35.22

igorlukanin commented 1 month ago

I've tried to reproduce this on v0.36.4 with the query pushdown in the SQL API on and I've got a different error:

ERROR:  Error during planning: No field named 'i.indkey'.
Valid fields are 'ct.oid', 'ct.relname', 'ct.relnamespace', 'n.oid', 'n.nspname', 'I.indexrelid', 'ci.oid',
'ci.relname', 'ci.relam', 'ci.relpages', 'ci.reltuples', 'am.oid', 'am.amname'

It looks like the query errors on this expression:

                       (information_schema._pg_expandarray(i.indkey)).n AS ordinal_position,

@itestyoy I wonder if this is still an issue for you. I see that this was reported for Metabase v0.49.7 but it was released more than 6 months ago. Does this still reproduce for you with a fresh Metabase install?