Knowledge Base

Executing NQL Statements

Executing NQL Statements on the Narrative Data Collaboration Platform

Executing NQL (Narrative SQL) statements effectively is essential for data analysis and management on the Narrative Data Collaboration Platform. This guide focuses on two critical commands: EXPLAIN and CREATE MATERIALIZED VIEW, outlining their purposes, benefits, and how they can be utilized within your data workflows.

EXPLAIN Example Usage

EXPLAIN
SELECT * FROM "narrative"."rosetta_stone"
WHERE "event_timestamp" > CURRENT_TIMESTAMP - INTERVAL '30' DAYS;

1. Understanding the EXPLAIN Command

The EXPLAIN command is used to diagnose and understand the execution plan of an NQL query without actually running it. This is particularly useful for optimizing queries and managing costs associated with data retrieval.

Benefits of EXPLAIN

  • Cost Forecasting: Provides an estimate of the query's data volume and associated costs, helping you manage your budget effectively.
  • Performance Insights: Identifies potential query inefficiencies, allowing for optimization before execution.
  • Execution Plan Overview: Details the steps the database engine will take to execute your query.

Learn more about creating materialized views here

2. Creating Materialized Views with NQL

CREATE MATERIALIZED VIEW enables the storage of query results as a new dataset within the platform. This command is especially useful for preserving the output of complex queries for further analysis and sharing.

CREATE MATERIALIZED VIEW Example Usage

CREATE MATERIALIZED VIEW "user_engagement_metrics"
AS
SELECT COUNT(DISTINCT user_id) AS unique_users, event_date
FROM "narrative"."user_events"
GROUP BY event_date;

Advantages of Creating Datasets with NQL

Creating a materialized view (generating a dataset) allows:

  • Data Persistence: Allows for the storage of query results as datasets, which can be queried, shared, or analyzed further.
  • Dataset Benefits: Enjoy all the advantages of having a dataset on the platform, including access control, data sharing, and integration with other tools.
  • Simplifies Repeated Analysis: Stores the result of complex queries, facilitating easy access to the data without re-execution of the query.

For comprehensive guidance on creating materialized views, visit the CREATE MATERIALIZED VIEW documentation.

Conclusion

Both EXPLAIN and CREATE MATERIALIZED VIEW are potent tools in the NQL arsenal, offering distinct benefits for query planning, optimization, and data management. While EXPLAIN provides valuable insights for optimizing queries and managing costs, CREATE MATERIALIZED VIEW enables the persistence of query results as datasets, extending the flexibility and utility of data within the Narrative platform. Utilizing these commands effectively can enhance your data analysis workflows, contributing to more informed decision-making and efficient data management.

For a deeper understanding of datasets and their management on the platform, consult the Dataset Documentation.

Learn more about datasets

Learn more about the Narrative dataset construct.

< Back
Rosetta

Hi! I’m Rosetta, your big data assistant. Ask me anything! If you want to talk to one of our wonderful human team members, let me know! I can schedule a call for you.