Examining the OJAI Query Plan

This section describes two ways to access a Java OJAI query plan and provides general information about how to interpret the query plan. You can examine the query plan to determine if the Java OJAI client chooses an appropriate execution path.

Using OJAI Tracing

After following the steps at Determining the Query Execution Path for OJAI Queries, if you determine that your query directly accesses MapR-DB JSON and does not use the OJAI Distributed Query Service, you can further examine the query plan in the trace output.

As noted in the referenced topic, to enable tracing, set the following property in your log4j.properties file, located in the /opt/mapr/conf directory:

log4j.logger.com.mapr.ojai.store.impl=TRACE, stdout

In the following logged output, the query plan uses an index named i1_idx and projects field id1. It also limits the result to two documents:

2017-10-18 11:29:32,876 TRACE [main] com.mapr.ojai.store.impl.OjaiDocumentStore - Query Plan: '[{"streamName":"DBDocumentStream","parameters":{"queryConditionPath":false,"indexName":"i1_idx","projectionPath":["id1"],"primaryTable":"/tmp/test-728918932/tab"}},{"streamName":"LimitStream","parameters":{"limit":2}}]'

Calling QueryResult.getQueryPlan

Instead of using OJAI tracing, you can programmatically retrieve query plans by calling QueryResult.getQueryPlan. The method returns a JSON document that is a list of Maps. Each Map in the list represents a DocumentStream in the query plan, which corresponds to an operation. The order of the list represents the order the MapR-DB client processes each operation. Each Map entry contains the name of the DocumentStream (streamName) and its parameters. You may see Map entries corresponding to the following DocumentStreams in a query plan:

  • DBDocumentStream - Accesses MapR-DB without the OJAI Distributed Query Service
  • DrillDocumentStream - Uses the OJAI Distributed Query Service to process the query
  • LimitStream - Limits the number of documents to return
  • OffsetStream - Skips past specified number of documents before reading
Important: The DocumentStream names and their parameters are subject to change from one release to the next. Take that into consideration if you plan to write tools that interpret the contents of an OJAI query plan