Knowledge Base

Cost Controls in NQL Queries

Cost Controls in NQL Queries

Efficiently managing costs is crucial when querying datasets within the Narrative Data Collaboration Platform, especially when accessing Rosetta Stone attributes or any dataset governed by access rules that entail costs. NQL offers robust mechanisms to control and manage data querying expenses effectively. This article delves into two primary cost control features available in NQL: the CPM filter and the budget limit filter.

1. Utilizing the CPM Filter

The Cost Per Mille (CPM) filter is a powerful tool that allows users to specify the maximum cost they are willing to pay for every 1000 rows of data queried. This filter ensures that the cost of data retrieval stays within the user's budgetary constraints by filtering out data exceeding the specified price threshold.

How to Apply the CPM Filter

The CPM filter is incorporated directly into the WHERE clause of your query. Specifying a maximum cost per 1000 rows ensures that only data rows costing less than or equal to your specified amount are retrieved.

Example:

SELECT rs."mobile_id_unique_identifier"."value"
FROM "narrative"."rosetta_stone" AS rs
WHERE rs."_price_cpm_usd" <= 1.50;

In this example, the query targets data rows where the cost does not exceed $1.50 per 1000 rows, effectively filtering out more expensive data and aligning with predefined budget limits.

2. Setting a Budget Limit

The budget limit filter enables users to define an overall budget for their query, expressed as LIMIT [X] USD PER CALENDAR_MONTH. This feature caps the total expenditure for the query over the specified period, offering another layer of cost control.

Implementing the Budget Limit

To utilize the budget limit, append the LIMIT clause to your query, specifying the maximum dollar amount you're willing to spend per calendar month. This ensures that the query's total cost does not exceed the budget, regardless of the number of rows retrieved.

Example:

SELECT rs."hl7_gender"."gender"
FROM "narrative"."rosetta_stone" AS rs
WHERE rs."hl7_gender"."gender" IS NOT NULL
LIMIT 100 USD PER CALENDAR_MONTH;

In this scenario, the query's expenditure is capped at $100 per calendar month. This limit applies to the total cost of data retrieved, allowing for efficient budget management and preventing unexpected expenses.

Understanding the Implications of Omitting Filters and Setting Them to 0

When crafting NQL queries, particularly those involving cost controls, the presence or absence of the _price_cpm_usd filter and the LIMIT budget filter, as well as setting these filters to 0, have specific implications:

Omitting the _price_cpm_usd Filter

  • Implication: Leaving off the _price_cpm_usd filter from your query means there are no restrictions based on the cost per 1000 rows (CPM). Consequently, the query will consider all available data, regardless of cost, which could potentially result in higher data retrieval expenses.
  • Use Case: This approach is suitable when conducting a broad data analysis where cost considerations are secondary to the comprehensiveness of the data.

Omitting the Budget Filter

  • Implication: Not specifying a LIMIT budget filter implies no upfront cap on the total cost of executing the query. Without this limit, the query could incur significant costs, especially when large volumes of data are retrieved or when data with higher per-row costs are accessed.
  • Use Case: Useful in scenarios where budget constraints are flexible, and the focus is on maximizing data retrieval without upfront cost limitations.

Setting Filters to 0

  • _price_cpm_usd Set to 0: Specifying a CPM filter value of 0 explicitly targets data that is free, excluding all data that incurs a cost per row. This is a strategic approach to ensure queries return only free data, avoiding any charges.
  • LIMIT Budget Filter Set to 0: Setting a LIMIT budget filter to 0 effectively imposes the strictest cost control, disallowing any expenditure for the query. It is equivalent to not allowing any paid data to be retrieved, ensuring the query costs nothing to execute.

Understanding these nuances enables you to tailor your NQL queries to meet both your data analysis objectives and your budgetary requirements efficiently.

Conclusion

By leveraging the CPM and budget limit filters in NQL queries, users can efficiently manage the costs associated with data retrieval on the Narrative Data Collaboration Platform. These cost control mechanisms ensure that data querying remains within budgetary constraints, providing users with the tools necessary for effective financial management of their data operations.

< 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.