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

Conversation

@rakeshkky
Copy link
Member

@rakeshkky rakeshkky commented Jan 18, 2019

Description

What component does this PR affect?

  • Server
  • Console
  • CLI
  • Docs
  • Community Content
  • Build System

Requires changes from other components? If yes, please mark the components:

  • Server
  • Console
  • CLI
  • Docs
  • Community Content
  • Build System

Related Issue

close #1362

Solution and Design

For "type": "run_sql" in /v1/query, check whether input SQL contains any DDL statement of type DROP, ALTER and REPLACE. If present, perform schema diff and apply those changes in HGE metadata. If not present, just execute and return response of SQL statement.

Optional argument to enforce schema diff check:-
Introduce new optional field check_metadata_consistency (takes bool value, default false) in args section of payload. This enforces performing schema diff irrespective of SQL statement.

Ex:-

POST /v1/query
{
       "type": "run_sql",
	"args": {
		"sql": "select id from geom_table",
		"check_metadata_consistency": true
	}
}

Regex used to match against SQL string:-
alter table|drop table|alter view|drop view|replace view

Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Docs update
  • Community content

Checklist:

  • I have read the contributing guide and my code conforms to the guidelines.
  • This change requires a change in the documentation.
  • I have updated the documentation accordingly.
  • I have added required tests.

@rakeshkky rakeshkky added k/enhancement New feature or improve an existing feature s/ok-to-merge Status: This pull request can be merged to master labels Jan 18, 2019
@rakeshkky rakeshkky self-assigned this Jan 18, 2019
@rakeshkky rakeshkky requested a review from 0x777 January 18, 2019 05:41
@hasura-bot
Copy link
Contributor

Review app for commit 8bd39ac deployed to Heroku: https://hge-ci-pull-1406.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1406-8bd39ac

let e = err400 PostgresError "query execution failed"
in e {qeInternal = Just $ toJSON txe}
throwErr s = throw500 $ "compiling regex failed: " <> T.pack s
regex = "alter table|drop table|alter view|drop view|replace view"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just have "alter|drop|replace"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex will catch all SQL having alter, drop and replace words. We explicitly need alter table, replace view etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our metadata can get inconsistent by dropping schemas/constraints too. Instead of explicitly listing all the objects it will be simpler to just use alter|drop|replace.

_3 (_, _, z) = z

-- regex related
matchRegex :: String -> Bool -> T.Text -> Either String Bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text -> Bool -> Text -> Either String Bool

Use the Bytestring module of TDFA instead of String internally.

, rCascade :: !(Maybe Bool)
{ rSql :: T.Text
, rCascade :: !(Maybe Bool)
, rEnforceStateCheck :: !(Maybe Bool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this check_metadata_consistency.

adminOnly
encode <$> bool withoutMDChk runP2 chkMDCnstcy
where
chkMDCnstcy = fromMaybe False mChkMDCnstcy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to treat absence of check_metadata_consistency key differently from explicitly specifying it to False.

Cases
Nothing -> we do a check optimistically based on regex
Just True -> definitely enforce the check
Nothing -> do not enforce the check (i.e, we need not check what the sql contains)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume last case is Just False

let e = err400 PostgresError "query execution failed"
in e {qeInternal = Just $ toJSON txe}

runSqlP2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to execWithMetadataCheck

adminOnly >> runSqlP2 q
runRunSQL q@(RunSQL t _ mChkMDCnstcy) = do
adminOnly
encode <$> case mChkMDCnstcy of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simplified further:

  chkMdCnstncy <- case mChkMdCnstncy of
    Nothing -> isAltrDropReplace t
    Just b  -> return b
  encode <$> bool (execRawSQL t) (execWithCheck q) chkMdCnstncy

@hasura-bot
Copy link
Contributor

Review app for commit 62a69f7 deployed to Heroku: https://hge-ci-pull-1406.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1406-62a69f7

@hasura-bot
Copy link
Contributor

Review app for commit 6ccb8d4 deployed to Heroku: https://hge-ci-pull-1406.herokuapp.com
Docker image for server: hasura/graphql-engine:pull1406-6ccb8d4

@shahidhk
Copy link
Member

Just checking in to make sure we're doing case insensitive match.

@0x777 0x777 merged commit d91d7e6 into hasura:master Jan 18, 2019
@hasura-bot
Copy link
Contributor

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

hasura-bot pushed a commit that referenced this pull request Dec 2, 2024
…enDD query planning (#1406)

### What

Enforce type permissions while building sub-selection for a nested field
in OpenDD query planning.

### How

<!-- How is it trying to accomplish it (what are the implementation
steps)? -->
- While populating sub-selection for a nested field, include only
accessible fields to the role.
- Raise permission exception if the type is not accessible to the role.

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

Labels

k/enhancement New feature or improve an existing feature s/ok-to-merge Status: This pull request can be merged to master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

optimise Run SQL query

4 participants