skuldshao commented on code in PR #18179: URL: https://github.com/apache/druid/pull/18179#discussion_r2241455421
########## docs/querying/set-query-context.md: ########## @@ -0,0 +1,239 @@ +--- +id: set-query-context +title: "Set query context" +sidebar_label: "Set query context" +description: + "This document configure and apply query context in Apache Druid + to customize query execution behavior and optimize performance." +--- + +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + + +The query context gives you fine-grained control over how Apache Druid executes your individual queries. While the default settings in Druid work well for most queries, you can set the query context to handle specific requirements and optimize performance. + +Common use cases for the query context include: +- Override default timeouts for long-running queries or complex aggregations. +- Debug query performance by disabling caching during testing. +- Configure SQL-specific behaviors like time zones for accurate time-based analysis. +- Set priorities to ensure critical queries get computational resources first. +- Adjust memory limits for queries that process large datasets. + +The way you set the query context depends on how you submit the query to Druid, whether using the web console or API. +It also depends on whether your query is Druid SQL or a JSON-based native query. +This guide shows you how to set the query context for each application. + +Before you begin, identify which context parameters you need to configure in order to establish your query context as query context carriers. For available parameters and their descriptions, see [Query context reference](query-context-reference.md). + +## Web console + +You can configure query context parameters is via the [Web console](../operations/web-console.md). In the web console, you can set up context parameters for both Druid SQL and native queries. + +The following steps show you how to set the query context using the web console: + +1. In the web console, select **Query** from the top-level navigation. + +  + +1. **Click** the **Engine** selector next to the **Run** button to choose the appropriate query type. Unless otherwise instructed, you can leave the engine as `Auto` to let Druid choose the best engine for you. + +  + +2. Enter the query you want to run. + +  + +3. Select **Edit query context** button in the **Select language and engine** menu. + +  + +4. In the **Edit query context** dialog, add your context parameters as JSON key-value pairs and then click **Save**. For example,you can insert the following context parameters: + + ```json + { + "timeout": 300000, + "useCache": false + } + ``` + + The web console validates the JSON object containing the query context parameters and highlights any syntax errors before you click **Run** the query. + +  + +6. Click **Run** to execute your query with the specified context parameters. + +  + + +For more information about using the web console Query view, see [Query view](../operations/web-console.md#query). + +## Druid SQL +When using Druid SQL programmatically—such as in applications, automated scripts, or database tools—you can set query context through various methods depending on how your queries are executed. + +### HTTP API + +When using the HTTP API, you include query context parameters in the `context` object of your JSON request. For more information on how to format Druid SQL API requests and handle responses, see [Druid SQL API](../api-reference/sql-api.md). + +The following example sets the `sqlTimeZone` parameter: + + ```json + { + "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2000-01-01 00:00:00'", Review Comment: Updated that too with wikipedia as data source -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
