这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@rakeshkky
Copy link
Member

Description

Affected components

  • Server
  • Console
  • Tests

Related Issues

close #1378

Design

Allow support for computed columns.
-> Add SQL functions through /v1/query API of type track_function.
-> Server will automatically determine the table to which the SQL function to be added as a computed column based on the first input parameter.
-> create_select_permission query type of /v1/query is updated to have an optional field computed_columns to permit SQL functions to be queried. An Example given in the next section.

Internal changes:-

  • Updated hdb_function_agg view to have qualified Postgres types for input arguments of a SQL function
  • Added hdb_computed_column to keep track of SQL function and table to which computed column is defined. Defined an array relationship from hdb_table with name computed_columns. This helps console to fetch list of computed columns to all tracked tables.
  • Catalog version bumped to 13 with SQL and Metdata migration

Steps to test and verify

  1. Create the following Postgres schema:
      CREATE TABLE person (
        id serial primary key,
        first_name text not null,
        last_name text not null
      );

      INSERT INTO person
      (first_name, last_name) VALUES
      ('taylor', 'chris'),
      ('clarke', 'michael');

      CREATE FUNCTION full_name(person person) RETURNS text AS $$
       SELECT  person.last_name || ' ' || person.first_name
      $$ LANGUAGE sql STABLE;

      CREATE FUNCTION full_name_prefix(person, prefix text) RETURNS text AS $$
       SELECT  prefix || ' ' || $1.last_name || ' ' || $1.first_name
      $$ LANGUAGE sql STABLE;
  1. Track table and SQL functions
  2. Make a graphql query as following
    query {
      person{
        id
        first_name
        last_name
        full_name
        full_name_prefix(args: {prefix: "Mr."})
      }
    }

reponse:-

{
  "data": {
    "person": [
      {
        "id": 1,
        "first_name": "taylor",
        "last_name": "chris",
        "full_name": "chris taylor",
        "full_name_prefix": "Mr. chris taylor"
      },
      {
        "id": 2,
        "first_name": "clarke",
        "last_name": "michael",
        "full_name": "michael clarke",
        "full_name_prefix": "Mr. michael clarke"
      }
    ]
  }
}
  1. Define select permission on computed columns
POST /v1/query
{
  "type": "create_select_permission",
  "args": {
    "table": "person",
    "role": "user",
    "permission": {
      "columns": "*",
      "computed_columns": [
        "full_name_prefix"
      ],
      "filter": {
        "id": "X-Hasura-Person-Id"
      }
    }
  }
}

Limitations, known bugs & workarounds

  • SQL function which returns BASIC type are allowed to be tracked as a computed column.
  • If any select permission defined using computed columns, then untracking SQL functions associated is not possible straight away. Server raises the dependency error. Drop select permission before untracking those SQL functions. To fix this, we've to add cascade field to untrack_function query type which will be a breaking change.

@rakeshkky rakeshkky added c/console Related to console c/server Related to server s/wip Status: This issue is a work in progress labels Apr 2, 2019
@rakeshkky rakeshkky self-assigned this Apr 2, 2019
@rakeshkky rakeshkky requested a review from 0x777 as a code owner April 2, 2019 15:45
@netlify
Copy link

netlify bot commented Apr 2, 2019

Deploy preview for hasura-docs ready!

Built with commit e4e574b

https://deploy-preview-1935--hasura-docs.netlify.com

@dsandip dsandip added this to the release-candidates milestone Apr 15, 2019
@chunsli
Copy link

chunsli commented May 7, 2019

just wondering if this PR is still alive, waiting to use this feature. the design looks good to me. thanks a lot for putting the effort into the feature

@chunsli
Copy link

chunsli commented May 28, 2019

checking-in on this feature, hoping to see it merged soon. thanks!

@dsandip
Copy link
Member

dsandip commented May 28, 2019

Hey @chunsli, this should be out in a couple of releases. Some of the underlying code has changed significantly, so a merge and a review are pending. cc: @rakeshkky @0x777

@chunsli
Copy link

chunsli commented Aug 7, 2019

following up again, is this still going to be merged? @rakeshkky @dsandip @0x777

thanks for the hard work

@jlowin
Copy link

jlowin commented Aug 25, 2019

I would like to echo that this would be an amazingly useful feature

@rakeshkky
Copy link
Member Author

closing in favour of #2917

@rakeshkky rakeshkky closed this Sep 21, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-1935.herokuapp.com is deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/console Related to console c/server Related to server s/wip Status: This issue is a work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants