> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/devops/pro-code/custom-query-managers.md).

# Custom Query Managers

Custom state managers can be created and added to runners to query new data sources, if needed.

All query managers extend the abstract QueryManager class or one of its subclasses.

```java
public class MyQueryManager extends QueryManager{

  /** 
   * Constructor with provided "alias", event runner which owns the manager
   * as well as all the configurations available to the runner
   */
  public MyQueryManager(String name, EventRunner runner, Map<String, String> config) {
    super(name, runner, config);
  }
  
  /** 
   * Function called during initialization of a query manager, typically
   * used to establish connections.
   */
  @Override
  public void configure() throws HotException {
  }
   
  /** 
   * Function called during termination of a query manager, typically
   * used to close connections with external systems.
   */
  @Override
  public void close() throws IOException {
  }
  
  /**
   * Function called for streaming records from
   * the query manager for a given query definition.
   * Data can be returned in any format preferred by the target
   * system, as convertToJson function is called for the output.
   */
  @Override
  public abstract Stream getRawQueryStream(Query query, InjectionHelper helper) throws HotException{
  }

  /**
   * Function called for translating target system specific records
   * into JsonNode.
   */
   public JsonNode convertToJson(Object object) throws HotException{
   }

}
```

Query managers typically utilize query producers for translating Rierino platform specific query definitions into target system specific language (e.g. SQL).  Query producers implement a wide range of abstract functions to provide this support, depending on their type:

* **CommandProducer:** For translating open ended query definitions to target system
* **SimpleProducer:** For translating regular queries with where condition, field selection and joins
* **AggregationProducer:** For translating group by and aggregation queries
* **PipelineProducer:** For translating step by step query pipelines supported by certain systems (e.g. MongoDB)
* **BundleProducer:** For translating bundled queries which submit multiple queries at once, supported by certain systems (e.g. Elasticsearch)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/devops/pro-code/custom-query-managers.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
