Run queries on an asset
To run SQL queries on an asset:
Running SQL query on an asset | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
- To create a minimal query object, use the
QueryRequest
creator method and provide the following arguments:- SQL query to run.
- unique name of the connection to use for the query.
- You must provide default schema name to use for
unqualified objects in the SQL, in the form
DB.SCHEMA
. - You can now execute the query using the
stream()
method.
Running SQL query on an asset | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 |
|
- To build a query, you need to use the
QueryRequest
and provide the following parameters:sql
: SQL query to run.data_source_name
: unique name of the connection to use for the query.default_schema
: default schema name to use for unqualified objects in the SQL, in the formDB.SCHEMA
.
- You can now execute the query using the
stream()
method.
POST /api/sql/query/stream | |
---|---|
1 2 3 4 5 |
|
- You must provide the following properties:
sql
: SQL query to run.dataSourceName
: unique name of the connection to use for the query.defaultSchema
: default schema name to use for unqualified objects in the SQL, in the formDB.SCHEMA
.
Use API token to run queries¶
You can also grant permission to run SQL queries on an asset using an API token, if you want. (This must be explicitly granted, as it is not possible by default.) You can even mask certain information through data policies on purposes linked to the API token.
API token permissions
Before executing queries on an asset using an API token, ensure that the token is linked to a persona with a data policy that permits queries for that specific asset.
Running SQL query on an asset with API token | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
- Use the
createDataPolicy()
method to start building a data policy with the minimal required information. - You must give the policy a name.
- You must provide the GUID of the
purpose
to attach this policy to. - Specify the type of policy (granting, denying or masking the data of assets with the tags in the purpose).
- Set the policy user to the API
token
. - Set the type of masking to
REDACT
to redact the tagged elements in the query response. - To then add the policy to the purpose in Atlan,
call the
save()
method with the policy object you've built. - Obtain the API token client.
- Set the API token for the client.
- To create a minimal query object, use the
QueryRequest
creator method and provide the following arguments:- SQL query to run.
- unique name of the connection to use for the query.
- You must provide default schema name to use for
unqualified objects in the SQL, in the form
DB.SCHEMA
. - You can now execute the query using the
stream()
method.
Running SQL query on an asset with API token | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
- Use the
create_data_policy()
method to start building a data policy with the minimal required information. - You must give the policy a name.
- You must provide the GUID of the
purpose
to attach this policy to. - Specify the type of policy (granting, denying or masking the data of assets with the tags in the purpose).
- Set the
policy_users
to the APItoken
. - Set the
all_users
option toFalse
as this policy is intended specifically for the API token. - Set the type of masking to
REDACT
to redact the tagged elements in the query response. - To then add the policy to the purpose in Atlan,
call the
save()
method with the policy object you've built. - Create a new client with the API token.
- To build a query, you need to use the
QueryRequest
and provide the following parameters:sql
: SQL query to run.data_source_name
: unique name of the connection to use for the query.default_schema
: default schema name to use for unqualified objects in the SQL, in the formDB.SCHEMA
.
- You can now execute the query using the
stream()
method.
POST /api/sql/query/stream | |
---|---|
1 2 3 4 5 |
|
- You must provide the following properties:
sql
: SQL query to run.dataSourceName
: unique name of the connection to use for the query.defaultSchema
: default schema name to use for unqualified objects in the SQL, in the formDB.SCHEMA
.
Policy implementation delay
Be aware that there is a delay of a few minutes after applying new policies to the token before they become fully effective. If you run a query immediately after creating the policy, you may still observe unredacted information until the policy is fully implemented.