1.0.0 • Published 1 month ago

druid-query-toolkit v1.0.0

Weekly downloads
1,653
License
Apache-2.0
Repository
github
Last release
1 month ago

npm version

Druid Query Toolkit

A number of tools to make working with Druid queries a treat. There are a number of use cases for this toolkit and one of the chief use cases can be found in Druid's own web-console.

Search for uses within web-console/src for some examples. Specifically the query view uses these tools a lot.

Parts

At a high level there are 4 parts to this toolkit:

  • SQL - a set of classes and parsers to model and parse DruidSQL.
  • QueryResult - a class to model and decode all the different shapes of Druid query results.
  • QueryRunner - a class to wrap around the boilerplate of running a query
  • Introspection - a set of utilities that help in decoding the results of Druid introspective metadata queries.

There are plenty of examples in the unit tests.

SQL

The SQL parser parses and models the whitespace and casing as well as the logical representation of the query allowing the query to be transformed in a very human friendly way.

Here are a few examples of what the SQL parser can do:

Adding a column at the start of the select clause.

import { SqlQuery } from 'druid-query-toolkit';

const sql = SqlQuery.parse(`
SELECT
  isAnonymous,
  cityName,
  flags,
  COUNT(*) AS "Count",
  SUM(added) AS "sum_added"
FROM wikipedia
GROUP BY 1, 2, 3
ORDER BY 4 DESC
`);

sql.addSelect(`"new_column" AS "New column"`, { insertIndex: 0 }).toString()
/* →
`
SELECT
  "new_column" AS "New column",
  isAnonymous,
  cityName,
  flags,
  COUNT(*) AS "Count",
  SUM(added) AS "sum_added"
FROM wikipedia
GROUP BY 2, 3, 4
ORDER BY 5 DESC
`
 */

sql.addSelect(`UPPER(city) AS City`, { insertIndex: 'last-grouping', addToGroupBy: 'end' }).toString()
/* →
`
SELECT
  isAnonymous,
  cityName,
  flags,
  UPPER(city) AS City,
  COUNT(*) AS "Count",
  SUM(added) AS "sum_added"
FROM wikipedia
GROUP BY 1, 2, 3, 4
ORDER BY 5 DESC
`
 */

For more examples check out the unit tests.

ToDo

Not every valid DruidSQL construct can currently be parsed, the following snippets are not currently supported:

  • (a, b) IN (subquery)
  • Support FROM "wikipedia_k" USING (k)

License

Apache 2.0

1.0.0

1 month ago

0.18.13

2 years ago

0.18.12

2 years ago

0.19.0

2 years ago

0.19.1

2 years ago

0.18.9

2 years ago

0.18.4

2 years ago

0.18.5

2 years ago

0.18.6

2 years ago

0.18.7

2 years ago

0.18.8

2 years ago

0.18.11

2 years ago

0.18.10

2 years ago

0.17.4

2 years ago

0.17.5

2 years ago

0.18.1

2 years ago

0.18.2

2 years ago

0.18.3

2 years ago

0.18.0

2 years ago

0.17.3

2 years ago

0.17.2

2 years ago

0.17.0

2 years ago

0.17.1

2 years ago

0.16.3

2 years ago

0.16.0

2 years ago

0.16.1

2 years ago

0.16.2

2 years ago

0.14.24

2 years ago

0.15.0

2 years ago

0.15.1

2 years ago

0.15.2

2 years ago

0.15.3

2 years ago

0.14.17

3 years ago

0.14.19

3 years ago

0.14.18

3 years ago

0.14.20

3 years ago

0.14.23

2 years ago

0.14.22

2 years ago

0.14.21

2 years ago

0.14.13

3 years ago

0.14.16

3 years ago

0.14.15

3 years ago

0.14.14

3 years ago

0.14.12

3 years ago

0.14.11

3 years ago

0.13.3

3 years ago

0.14.10

3 years ago

0.14.5

3 years ago

0.14.6

3 years ago

0.14.7

3 years ago

0.14.8

3 years ago

0.14.9

3 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.14.2

3 years ago

0.14.3

3 years ago

0.14.4

3 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.13.2

3 years ago

0.12.7

3 years ago

0.12.8

3 years ago

0.12.4

3 years ago

0.12.5

3 years ago

0.12.6

3 years ago

0.12.1

3 years ago

0.12.2

3 years ago

0.12.3

3 years ago

0.11.18

3 years ago

0.12.0

3 years ago

0.11.16

3 years ago

0.11.17

3 years ago

0.11.15

3 years ago

0.11.14

3 years ago

0.11.12

3 years ago

0.11.13

3 years ago

0.11.11

3 years ago

0.11.10

3 years ago

0.11.9

3 years ago

0.11.8

4 years ago

0.10.9

4 years ago

0.10.8

4 years ago

0.11.0

4 years ago

0.11.1

4 years ago

0.11.2

4 years ago

0.11.3

4 years ago

0.11.4

4 years ago

0.10.10

4 years ago

0.11.5

4 years ago

0.10.11

4 years ago

0.11.6

4 years ago

0.11.7

4 years ago

0.10.7

4 years ago

0.10.6

4 years ago

0.10.5

4 years ago

0.10.4

4 years ago

0.10.3

4 years ago

0.10.2

4 years ago

0.10.0

4 years ago

0.9.16

4 years ago

0.9.15

4 years ago

0.9.14

4 years ago

0.9.13

4 years ago

0.9.12

4 years ago

0.9.11

4 years ago

0.9.10

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.6

4 years ago

0.8.5

4 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.30

4 years ago

0.7.29

4 years ago

0.7.28

4 years ago

0.7.27

4 years ago

0.7.26

4 years ago

0.7.25

4 years ago

0.7.23

4 years ago

0.7.21

4 years ago

0.7.20

4 years ago

0.7.19

4 years ago

0.7.18

4 years ago

0.7.17

4 years ago

0.7.16

4 years ago

0.7.15

4 years ago

0.7.14

4 years ago

0.7.12

4 years ago

0.7.11

5 years ago

0.7.10

5 years ago

0.7.9

5 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.6

5 years ago

0.7.5

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.0

5 years ago

0.3.29

5 years ago

0.3.28

5 years ago

0.3.27

5 years ago

0.3.26

5 years ago

0.3.25

5 years ago

0.3.24

5 years ago

0.3.23

5 years ago

0.3.22

5 years ago

0.3.21

5 years ago

0.3.20

5 years ago

0.3.19

5 years ago

0.3.18

5 years ago

0.3.17

5 years ago

0.3.16

5 years ago

0.3.15

5 years ago

0.3.14

5 years ago

0.3.13

5 years ago

0.3.12

5 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago