Apache Druid supports two query languages: Druid SQL and native queries. This document describes the native language. For information about functions available in SQL, refer to the SQL documentation.

Virtual columns are queryable column “views” created from a set of columns during a query.

A virtual column can potentially draw from multiple underlying columns, although a virtual column always presents itself as a single column.

Virtual columns can be used as dimensions or as inputs to aggregators.

Each Apache Druid query can accept a list of virtual columns as a parameter. The following scan query is provided as an example:

  1. {
  2. "queryType": "scan",
  3. "dataSource": "page_data",
  4. "columns":[],
  5. "virtualColumns": [
  6. {
  7. "type": "expression",
  8. "name": "fooPage",
  9. "expression": "concat('foo' + page)",
  10. "outputType": "STRING"
  11. },
  12. {
  13. "type": "expression",
  14. "name": "tripleWordCount",
  15. "expression": "wordCount * 3",
  16. "outputType": "LONG"
  17. }
  18. ],
  19. "intervals": [
  20. "2013-01-01/2019-01-02"
  21. ]
  22. }

Virtual column types

Expression virtual column

The expression virtual column has the following syntax:

  1. {
  2. "type": "expression",
  3. "name": <name of the virtual column>,
  4. "expression": <row expression>,
  5. "outputType": <output value type of expression>
  6. }
propertydescriptionrequired?
nameThe name of the virtual column.yes
expressionAn expression that takes a row as input and outputs a value for the virtual column.yes
outputTypeThe expression’s output will be coerced to this type. Can be LONG, FLOAT, DOUBLE, or STRING.no, default is FLOAT