curl --request POST \
--url https://api-dev.narrative.io/nql/validate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"nql": "CREATE MATERIALIZED VIEW \"dataset_name\" AS SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\""
}
'import requests
url = "https://api-dev.narrative.io/nql/validate"
payload = { "nql": "CREATE MATERIALIZED VIEW \"dataset_name\" AS SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\"" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
nql: 'CREATE MATERIALIZED VIEW "dataset_name" AS SELECT "company_data"."1".x AS xx, "company_data"."1".y AS yy, "company_data"."1".z AS zz, "company_data"."1".x + "company_data"."1".y + "company_data"."1".z AS xyz_sum FROM "company_data"."1"'
})
};
fetch('https://api-dev.narrative.io/nql/validate', 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://api-dev.narrative.io/nql/validate",
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([
'nql' => 'CREATE MATERIALIZED VIEW "dataset_name" AS SELECT "company_data"."1".x AS xx, "company_data"."1".y AS yy, "company_data"."1".z AS zz, "company_data"."1".x + "company_data"."1".y + "company_data"."1".z AS xyz_sum FROM "company_data"."1"'
]),
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://api-dev.narrative.io/nql/validate"
payload := strings.NewReader("{\n \"nql\": \"CREATE MATERIALIZED VIEW \\\"dataset_name\\\" AS SELECT \\\"company_data\\\".\\\"1\\\".x AS xx, \\\"company_data\\\".\\\"1\\\".y AS yy, \\\"company_data\\\".\\\"1\\\".z AS zz, \\\"company_data\\\".\\\"1\\\".x + \\\"company_data\\\".\\\"1\\\".y + \\\"company_data\\\".\\\"1\\\".z AS xyz_sum FROM \\\"company_data\\\".\\\"1\\\"\"\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://api-dev.narrative.io/nql/validate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"nql\": \"CREATE MATERIALIZED VIEW \\\"dataset_name\\\" AS SELECT \\\"company_data\\\".\\\"1\\\".x AS xx, \\\"company_data\\\".\\\"1\\\".y AS yy, \\\"company_data\\\".\\\"1\\\".z AS zz, \\\"company_data\\\".\\\"1\\\".x + \\\"company_data\\\".\\\"1\\\".y + \\\"company_data\\\".\\\"1\\\".z AS xyz_sum FROM \\\"company_data\\\".\\\"1\\\"\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/nql/validate")
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 \"nql\": \"CREATE MATERIALIZED VIEW \\\"dataset_name\\\" AS SELECT \\\"company_data\\\".\\\"1\\\".x AS xx, \\\"company_data\\\".\\\"1\\\".y AS yy, \\\"company_data\\\".\\\"1\\\".z AS zz, \\\"company_data\\\".\\\"1\\\".x + \\\"company_data\\\".\\\"1\\\".y + \\\"company_data\\\".\\\"1\\\".z AS xyz_sum FROM \\\"company_data\\\".\\\"1\\\"\"\n}"
response = http.request(request)
puts response.read_body{
"type": "create_materialized_view",
"nql": "CREATE MATERIALIZED VIEW \"dataset_name\" AS SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\"",
"name": "dataset_name",
"select": {
"type": "select",
"nql": "SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\"",
"columns": [
{
"as": "xx",
"nql": "\"company_data\".\"1\".x AS xx",
"type": "column",
"db": null,
"schema": "company_data",
"table": "1",
"column": "x",
"metadata": {
"column_type": "column"
}
},
{
"as": "yy",
"nql": "\"company_data\".\"1\".y AS yy",
"type": "column",
"db": null,
"schema": "company_data",
"table": "1",
"column": "y",
"metadata": {
"column_type": "column"
}
},
{
"as": "zz",
"nql": "\"company_data\".\"1\".z AS zz",
"type": "column",
"db": null,
"schema": "company_data",
"table": "1",
"column": "z",
"metadata": {
"column_type": "column"
}
},
{
"as": "xyz_sum",
"nql": "\"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum",
"type": "binary_op",
"name": "+",
"left": {
"type": "binary_op",
"nql": "\"company_data\".\"1\".x + \"company_data\".\"1\".y",
"name": "+",
"left": {
"type": "column",
"nql": "\"company_data\".\"1\".x",
"db": null,
"schema": "company_data",
"table": "1",
"column": "x",
"metadata": {
"column_type": "column"
}
},
"right": {
"type": "column",
"nql": "\"company_data\".\"1\".y",
"db": null,
"schema": "company_data",
"table": "1",
"column": "y",
"metadata": {
"column_type": "column"
}
}
},
"right": {
"type": "column",
"nql": "\"company_data\".\"1\".z",
"db": null,
"schema": "company_data",
"table": "1",
"column": "z",
"metadata": {
"column_type": "column"
}
}
}
],
"from": {
"type": "table",
"nql": "\"company_data\".\"1\"",
"db": null,
"schema": "company_data",
"table": "1",
"metadata": {
"id": 1,
"name": "dataset_name_1",
"table_type": "dataset"
}
},
"group_by": [],
"having": null,
"is_distinct": false,
"limit": null,
"order_by": [],
"qualify": null,
"where": null,
"windows": [],
"with": []
}
}Validate an NQL statement
Parse and validate an NQL statement without running it. The statement is parsed with the SQL dialect of
the given data plane and checked against the datasets, access rules and views the token’s company can
see. A valid statement returns its AST (see the Ast schema). An invalid one returns an RFC 7807
problem whose title and detail say what is wrong, with the status code /nql/run and
/v1/nql/execute return for the same problem.
Requires a token with read access to subscriptions. POST /nql/parse does the same check for any
token, or for no token at all.
curl --request POST \
--url https://api-dev.narrative.io/nql/validate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"nql": "CREATE MATERIALIZED VIEW \"dataset_name\" AS SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\""
}
'import requests
url = "https://api-dev.narrative.io/nql/validate"
payload = { "nql": "CREATE MATERIALIZED VIEW \"dataset_name\" AS SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\"" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
nql: 'CREATE MATERIALIZED VIEW "dataset_name" AS SELECT "company_data"."1".x AS xx, "company_data"."1".y AS yy, "company_data"."1".z AS zz, "company_data"."1".x + "company_data"."1".y + "company_data"."1".z AS xyz_sum FROM "company_data"."1"'
})
};
fetch('https://api-dev.narrative.io/nql/validate', 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://api-dev.narrative.io/nql/validate",
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([
'nql' => 'CREATE MATERIALIZED VIEW "dataset_name" AS SELECT "company_data"."1".x AS xx, "company_data"."1".y AS yy, "company_data"."1".z AS zz, "company_data"."1".x + "company_data"."1".y + "company_data"."1".z AS xyz_sum FROM "company_data"."1"'
]),
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://api-dev.narrative.io/nql/validate"
payload := strings.NewReader("{\n \"nql\": \"CREATE MATERIALIZED VIEW \\\"dataset_name\\\" AS SELECT \\\"company_data\\\".\\\"1\\\".x AS xx, \\\"company_data\\\".\\\"1\\\".y AS yy, \\\"company_data\\\".\\\"1\\\".z AS zz, \\\"company_data\\\".\\\"1\\\".x + \\\"company_data\\\".\\\"1\\\".y + \\\"company_data\\\".\\\"1\\\".z AS xyz_sum FROM \\\"company_data\\\".\\\"1\\\"\"\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://api-dev.narrative.io/nql/validate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"nql\": \"CREATE MATERIALIZED VIEW \\\"dataset_name\\\" AS SELECT \\\"company_data\\\".\\\"1\\\".x AS xx, \\\"company_data\\\".\\\"1\\\".y AS yy, \\\"company_data\\\".\\\"1\\\".z AS zz, \\\"company_data\\\".\\\"1\\\".x + \\\"company_data\\\".\\\"1\\\".y + \\\"company_data\\\".\\\"1\\\".z AS xyz_sum FROM \\\"company_data\\\".\\\"1\\\"\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/nql/validate")
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 \"nql\": \"CREATE MATERIALIZED VIEW \\\"dataset_name\\\" AS SELECT \\\"company_data\\\".\\\"1\\\".x AS xx, \\\"company_data\\\".\\\"1\\\".y AS yy, \\\"company_data\\\".\\\"1\\\".z AS zz, \\\"company_data\\\".\\\"1\\\".x + \\\"company_data\\\".\\\"1\\\".y + \\\"company_data\\\".\\\"1\\\".z AS xyz_sum FROM \\\"company_data\\\".\\\"1\\\"\"\n}"
response = http.request(request)
puts response.read_body{
"type": "create_materialized_view",
"nql": "CREATE MATERIALIZED VIEW \"dataset_name\" AS SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\"",
"name": "dataset_name",
"select": {
"type": "select",
"nql": "SELECT \"company_data\".\"1\".x AS xx, \"company_data\".\"1\".y AS yy, \"company_data\".\"1\".z AS zz, \"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum FROM \"company_data\".\"1\"",
"columns": [
{
"as": "xx",
"nql": "\"company_data\".\"1\".x AS xx",
"type": "column",
"db": null,
"schema": "company_data",
"table": "1",
"column": "x",
"metadata": {
"column_type": "column"
}
},
{
"as": "yy",
"nql": "\"company_data\".\"1\".y AS yy",
"type": "column",
"db": null,
"schema": "company_data",
"table": "1",
"column": "y",
"metadata": {
"column_type": "column"
}
},
{
"as": "zz",
"nql": "\"company_data\".\"1\".z AS zz",
"type": "column",
"db": null,
"schema": "company_data",
"table": "1",
"column": "z",
"metadata": {
"column_type": "column"
}
},
{
"as": "xyz_sum",
"nql": "\"company_data\".\"1\".x + \"company_data\".\"1\".y + \"company_data\".\"1\".z AS xyz_sum",
"type": "binary_op",
"name": "+",
"left": {
"type": "binary_op",
"nql": "\"company_data\".\"1\".x + \"company_data\".\"1\".y",
"name": "+",
"left": {
"type": "column",
"nql": "\"company_data\".\"1\".x",
"db": null,
"schema": "company_data",
"table": "1",
"column": "x",
"metadata": {
"column_type": "column"
}
},
"right": {
"type": "column",
"nql": "\"company_data\".\"1\".y",
"db": null,
"schema": "company_data",
"table": "1",
"column": "y",
"metadata": {
"column_type": "column"
}
}
},
"right": {
"type": "column",
"nql": "\"company_data\".\"1\".z",
"db": null,
"schema": "company_data",
"table": "1",
"column": "z",
"metadata": {
"column_type": "column"
}
}
}
],
"from": {
"type": "table",
"nql": "\"company_data\".\"1\"",
"db": null,
"schema": "company_data",
"table": "1",
"metadata": {
"id": 1,
"name": "dataset_name_1",
"table_type": "dataset"
}
},
"group_by": [],
"having": null,
"is_distinct": false,
"limit": null,
"order_by": [],
"qualify": null,
"where": null,
"windows": [],
"with": []
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
A NQL query.
A dataplane represent where you would run the query. Your query get compiled to the SQL dialect that your data engine understands. If you leave it blank, your query will target Narrative's dataplane on AWS using Apache Spark. We currently support Snowflake and we plan to support other dataplanes in the future. See https://next.narrative.io/products/narrative-anywhere for more details.
Response
The statement is valid. The body is its AST, or an empty object for a MERGE statement, which has
no AST representation.
The parsed statement as an AST. A MERGE statement has no AST representation and returns an empty
object instead, as does a statement whose AST could not be serialized.
"agg_function"The text of the query fragment this node was parsed from.
The function name as written, for example SUM or COUNT.
The alias given with AS. Only present on aliased nodes: select-list expressions, FROM items and
common table expressions. When it is present the node's nql is the full <expression> AS <alias> text.
The ALL or DISTINCT quantifier, or null when none was written.
all, distinct, null Was this page helpful?

