Search code examples
apache-drill

How to perform a Apache Drill date range query?


As the question puts, how do I make a date range query with Apache Drill? I see my "date" columns in my csv file are shown using the following format "2016-01-9 08:00:00.0"


Solution

  • testdate.csv:

    2016-01-9 08:00:00.0,dev1
    2016-02-9 08:00:00.0,dev2
    2016-03-9 08:00:00.0,dev3
    2016-04-9 08:00:00.0,dev4
    2016-05-9 08:00:00.0,dev5
    

    Query:

    select columns[0],columns[1] from dfs.`/home/impadmin/testdate.csv` 
         where columns[0]  BETWEEN '2016-02-9 08:00:00.0' AND '2016-04-9 08:00:00.0';
    

    output:

    +-----------------------+---------+
    |        EXPR$0         | EXPR$1  |
    +-----------------------+---------+
    | 2016-02-9 08:00:00.0  | dev2    |
    | 2016-03-9 08:00:00.0  | dev3    |
    | 2016-04-9 08:00:00.0  | dev4    |
    +-----------------------+---------+