Skip to main content
POST
/
nql
/
validate
Validate an NQL query
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

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
nql
string
required

A NQL query.

data_plane_id
string<uuid>

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

OK

type
string
required
Allowed value: "agg_function"
nql
string
required
args
array
required
quantifier
enum<string>
Available options:
all,
distinct