When you upload CSV-format lookup tables, you can use the lookup() function to access that data in your NRQL queries. You can use lookup tables to help you parse telemetry data and customize your data groupings.
Basic query syntax
The following lookup query shows the basic syntax for this function using a table named storeNames and selecting all the data from that table:
FROM lookup(storeNames)
SELECT*
This query selects specific attributes from that same table:
FROM lookup(storeNames)
SELECT store_ID, store_name, description
Query limits
Lookup tables support a higher LIMIT when querying than other NRQL data types do. You can set a LIMIT of up to 20,000 when using a lookup table within a query, subquery, and nested aggregation.
Tip
When you use a lookup table within a subquery, the outer query LIMIT is bound by the standard maximum value unless it also uses a lookup table.
Technical limitations
You can't use lookup data with NRQL alert conditions.
You can only query lookup tables from the account you uploaded the lookup table in.
The following NRQL clauses aren't supported with lookup queries:
TIMESERIES
COMPARE WITH
EXTRAPOLATE
Note: You can use these clauses if you contain the lookup query in an inner query. See this query for an example.
Lookup examples
Lookup tables allow you to use queries that combine data with your New Relic-stored telemetry data.
Here are some query examples:
This query avoids hardcoding a long list of hosts by querying host names contained in a lookup table:
FROM Log
SELECTcount(*)
WHERE hostname IN(FROM lookup(myHosts)SELECT uniques(myHost))
Using JOIN queries can make your data easier to understand. For example, this query for a custom event type uses the storeNames table to show the store names along with the total sales.
FROM StoreEvent
JOIN(FROM lookup(storeNames)SELECT store_ID as storeId, storeName AS name LIMIT10000)ON shopId = storeId
SELECT shopId, storeName, totalSales
This allows a limit of 10,000 because lookup tables support a higher limit than other NRQL data types, as is mentioned in the query limits section.
This query maps shopId values to a broader storeCategory value by using a JOIN clause on lookup table data. This enables you to perform aggregations on StoreEvent records based on these broader categories and extract new insights from your data.
FROM StoreEvent
JOIN(FROM lookup(storeCategories)SELECT store_ID as storeId, storeCategory)ON shopId = storeId
SELECTsum(totalSales) FACET storeCategory
Here's a query that translates status codes to readable summaries of the status: