Run query
Required capabilities:
transformationsAcl:READ
Preview a SQL query.
POST
/
transformations
/
query
/
run
Python SDK
query_result = client.transformations.preview(query="select * from _cdf.assets")
df = client.transformations.preview(query="select * from _cdf.assets").to_pandas()
result = client.transformations.preview(query="select * from my_raw_db.my_raw_table", limit=None)
print(result.results)
result = client.transformations.preview(query="select * from my_raw_db.my_raw_table", limit=None, source_limit=None)
print(result.results)
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"convertToString": true,
"limit": 123,
"sourceLimit": 123,
"inferSchemaLimit": 123,
"timeout": 123
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
query: '<string>',
convertToString: true,
limit: 123,
sourceLimit: 123,
inferSchemaLimit: 123,
timeout: 123
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'convertToString' => true,
'limit' => 123,
'sourceLimit' => 123,
'inferSchemaLimit' => 123,
'timeout' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"convertToString\": true,\n \"limit\": 123,\n \"sourceLimit\": 123,\n \"inferSchemaLimit\": 123,\n \"timeout\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"convertToString\": true,\n \"limit\": 123,\n \"sourceLimit\": 123,\n \"inferSchemaLimit\": 123,\n \"timeout\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"<string>\",\n \"convertToString\": true,\n \"limit\": 123,\n \"sourceLimit\": 123,\n \"inferSchemaLimit\": 123,\n \"timeout\": 123\n}"
response = http.request(request)
puts response.read_body{
"schema": {
"items": [
{
"name": "<string>",
"sqlType": "<string>",
"type": {
"type": "<string>"
},
"nullable": true
}
]
},
"results": {
"items": [
{}
]
}
}{
"error": {
"code": 123,
"message": "<string>",
"missing": [
{
"externalId": "my.known.id"
}
],
"duplicated": [
{
"externalId": "my.known.id"
}
]
}
}{
"error": {
"code": 123,
"message": "<string>",
"missing": [
{
"externalId": "my.known.id"
}
],
"duplicated": [
{
"externalId": "my.known.id"
}
]
}
}Authorizations
oidc-tokenoauth2-client-credentialsoauth2-open-industrial-dataoauth2-auth-code
Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.
Scopes
Body
application/json
Query object to run a query to preview results.
⌘I
Python SDK
query_result = client.transformations.preview(query="select * from _cdf.assets")
df = client.transformations.preview(query="select * from _cdf.assets").to_pandas()
result = client.transformations.preview(query="select * from my_raw_db.my_raw_table", limit=None)
print(result.results)
result = client.transformations.preview(query="select * from my_raw_db.my_raw_table", limit=None, source_limit=None)
print(result.results)
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"convertToString": true,
"limit": 123,
"sourceLimit": 123,
"inferSchemaLimit": 123,
"timeout": 123
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
query: '<string>',
convertToString: true,
limit: 123,
sourceLimit: 123,
inferSchemaLimit: 123,
timeout: 123
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'convertToString' => true,
'limit' => 123,
'sourceLimit' => 123,
'inferSchemaLimit' => 123,
'timeout' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"convertToString\": true,\n \"limit\": 123,\n \"sourceLimit\": 123,\n \"inferSchemaLimit\": 123,\n \"timeout\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"convertToString\": true,\n \"limit\": 123,\n \"sourceLimit\": 123,\n \"inferSchemaLimit\": 123,\n \"timeout\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/transformations/query/run")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"<string>\",\n \"convertToString\": true,\n \"limit\": 123,\n \"sourceLimit\": 123,\n \"inferSchemaLimit\": 123,\n \"timeout\": 123\n}"
response = http.request(request)
puts response.read_body{
"schema": {
"items": [
{
"name": "<string>",
"sqlType": "<string>",
"type": {
"type": "<string>"
},
"nullable": true
}
]
},
"results": {
"items": [
{}
]
}
}{
"error": {
"code": 123,
"message": "<string>",
"missing": [
{
"externalId": "my.known.id"
}
],
"duplicated": [
{
"externalId": "my.known.id"
}
]
}
}{
"error": {
"code": 123,
"message": "<string>",
"missing": [
{
"externalId": "my.known.id"
}
],
"duplicated": [
{
"externalId": "my.known.id"
}
]
}
}