[New Feature Introducing]“Explain Plan”statement for Druid SQL

Created with Sketch.

[New Feature Introducing]“Explain Plan”statement for Druid SQL

0
(0)

Druid SQL is a very convenient interface that allows you to execute queries on Druid in SQL format. However, Druid Query in JSON format still provides powerful features that Druid SQL cannot provide (for example, when you want to export query results in orc format). The problem is that the more complicated the Druid Query is, the more difficult it is to write it. Metatron distribution Druid provides “Explain Plan” syntax that helps you to know JSON Query actually executed from the created SQL.

Below is an example of its use.

explain plan WITH IMPLEMENTATION for 
SELECT t1.Province_State,
   sum(t1.positive) as positive
FROM "druid"."covid_worldwide_test_data" t1
GROUP BY  t1.Province_State;

If you execute Druid SQL like this, you can get the execution plan including the json query result as follows.

{
  "queryType": "groupBy",
  "dataSource": {
    "type": "table",
    "name": "covid_worldwide_test_data"
  },
  "granularity": {
    "type": "all"
  },
  "dimensions": [
    {
      "type": "default",
      "dimension": "Province_State",
      "outputName": "d0"
    }
  ],
  "aggregations": [
    {
      "type": "sum",
      "name": "a0",
      "fieldName": "positive",
      "inputType": "double"
    }
  ],
  "limitSpec": {
    "type": "noop"
  },
  "context": {
    "groupby.sort.on.time": false,
    "sqlQueryId": "fac2dee2-17d4-42f1-b6ed-e4ea16e25dac"
  },
  "descending": false
}

If it is difficult to write a json query, you can easily create a json query by using the “Explain Plan” statement after writing the SQL query as above.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Share this post on your social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *