Using Custom SQL Queries
Connecting to a Custom SQL Query
Tableau normally determines what query should be run against Apache Phoenix in order to build a visualization. However, these queries requres may request data than is needed, or you may need to use features specific to Apache Phoenix that Tableau does not expose. In these cases you can write a custom SQL query.
- After you have connected to Apache Phoenix, navigate to the Data Source tab.
- In the left pane, select your Database and Schema.
- Instead of selecting one of the available tables, click New Custom SQL.
- You are then be prompted for your query. Provide any filters aggregates or joins you want here.
- Click OK.
With your custom SQL query provided, proceed to Visualizing Data as if the selection were a normal table.
Native Queries
In addition to writing custom SQL queries, the connector allows you to query Apache Phoenix in its native query language. This is only available when QueryPassthrough is disabled.
To use a native query, follow the steps to a custom SQL query but select from the NATIVEQUERY table function instead of a table:
SELECT * FROM NATIVEQUERY('...')
It is important to remember that Apache Phoenix only processes the part of the query given to NATIVEQUERY. This means that other operations performed by Tableau, such as grouping and counting the results for a chart, require the connector to read all the NATIVEQUERY results and aggregate them locally.
Queries without NATIVEQUERY are not limited in this way because the connector can analyze the entire query and send as much as possible to Apache Phoenix. For this reason, you should use NATIVEQUERY only when necessary and limit how much data you read with it.