Fix new hdb_table_info_agg query to fetch column base types

We mostly want to do this to make queries against information_schema
tables work, which the console cares about. information_schema tables
use types like sql_identifier, which have no corresponding array types
defined! Therefore, in order to generate valid queries for _in and _nin
conditions, we need to treat them as their base types, instead.
This commit is contained in:
Alexis King 2019-12-13 02:26:39 -06:00
parent e2eabcd54e
commit 25c5f97de2
6 changed files with 38 additions and 2 deletions

View File

@ -463,13 +463,15 @@ CREATE VIEW hdb_catalog.hdb_table_info_agg AS
( SELECT jsonb_agg(jsonb_build_object( ( SELECT jsonb_agg(jsonb_build_object(
'name', "column".attname, 'name', "column".attname,
'position', "column".attnum, 'position', "column".attnum,
'type', "type".typname, 'type', coalesce(base_type.typname, "type".typname),
'is_nullable', NOT "column".attnotnull, 'is_nullable', NOT "column".attnotnull,
'description', pg_catalog.col_description("table".oid, "column".attnum) 'description', pg_catalog.col_description("table".oid, "column".attnum)
)) AS info )) AS info
FROM pg_catalog.pg_attribute "column" FROM pg_catalog.pg_attribute "column"
LEFT JOIN pg_catalog.pg_type "type" LEFT JOIN pg_catalog.pg_type "type"
ON "type".oid = "column".atttypid ON "type".oid = "column".atttypid
LEFT JOIN pg_catalog.pg_type base_type
ON "type".typtype = 'd' AND base_type.oid = "type".typbasetype
WHERE "column".attrelid = "table".oid WHERE "column".attrelid = "table".oid
-- columns where attnum <= 0 are special, system-defined columns -- columns where attnum <= 0 are special, system-defined columns
AND "column".attnum > 0 AND "column".attnum > 0

View File

@ -38,13 +38,15 @@ CREATE VIEW hdb_catalog.hdb_table_info_agg AS
( SELECT jsonb_agg(jsonb_build_object( ( SELECT jsonb_agg(jsonb_build_object(
'name', "column".attname, 'name', "column".attname,
'position', "column".attnum, 'position', "column".attnum,
'type', "type".typname, 'type', coalesce(base_type.typname, "type".typname),
'is_nullable', NOT "column".attnotnull, 'is_nullable', NOT "column".attnotnull,
'description', pg_catalog.col_description("table".oid, "column".attnum) 'description', pg_catalog.col_description("table".oid, "column".attnum)
)) AS info )) AS info
FROM pg_catalog.pg_attribute "column" FROM pg_catalog.pg_attribute "column"
LEFT JOIN pg_catalog.pg_type "type" LEFT JOIN pg_catalog.pg_type "type"
ON "type".oid = "column".atttypid ON "type".oid = "column".atttypid
LEFT JOIN pg_catalog.pg_type base_type
ON "type".typtype = 'd' AND base_type.oid = "type".typbasetype
WHERE "column".attrelid = "table".oid WHERE "column".attrelid = "table".oid
-- columns where attnum <= 0 are special, system-defined columns -- columns where attnum <= 0 are special, system-defined columns
AND "column".attnum > 0 AND "column".attnum > 0

View File

@ -0,0 +1,17 @@
description: _in boolexp on column of type sql_identifier
url: /v1/graphql
status: 200
response:
data:
table_with_sql_identifier:
- { id: 3, sql_id: two }
- { id: 5, sql_id: four }
- { id: 7, sql_id: two }
query:
query: |
query {
table_with_sql_identifier(where: {sql_id: {_nin: ["one", "three"]}}) {
id
sql_id
}
}

View File

@ -275,3 +275,14 @@ args:
_where: _where:
id: X-Hasura-User-Id id: X-Hasura-User-Id
is_admin: true is_admin: true
- type: run_sql
args:
sql: |
CREATE TABLE table_with_sql_identifier
( id serial PRIMARY KEY
, sql_id information_schema.sql_identifier );
INSERT INTO table_with_sql_identifier (sql_id)
VALUES ('one'), ('one'), ('two'), ('three'), ('four'), ('one'), ('two');
- type: track_table
args: table_with_sql_identifier

View File

@ -3,6 +3,7 @@ args:
- type: run_sql - type: run_sql
args: args:
sql: | sql: |
DROP TABLE table_with_sql_identifier;
DROP TABLE article; DROP TABLE article;
DROP TABLE author; DROP TABLE author;
DROP TABLE city; DROP TABLE city;

View File

@ -247,6 +247,9 @@ class TestGraphQLQueryBoolExpBasic(DefaultTestSelectQueries):
def test_query_account_permission_fail(self, hge_ctx, transport): def test_query_account_permission_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_account_permission_fail.yaml', transport) check_query_f(hge_ctx, self.dir() + '/query_account_permission_fail.yaml', transport)
def test_in_sql_identifier_array(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/in_sql_identifier_array.yaml', transport)
@classmethod @classmethod
def dir(cls): def dir(cls):
return 'queries/graphql_query/boolexp/basic' return 'queries/graphql_query/boolexp/basic'