         throw new Error("filter type '#{filter.type}' not defined")
 
   addFilter: (filter) ->
+    dateToIntervalPart = DruidQueryBuilder.dateToIntervalPart
     return unless filter
     [@filter, intervals] = @filterToDruid(filter)
     if intervals
-      @intervals = intervals.map((({start, end}) -> "#{@dateToIntervalPart(start)}/#{@dateToIntervalPart(end)}"), this)
+      @intervals = intervals.map((({start, end}) -> "#{dateToIntervalPart(start)}/#{dateToIntervalPart(end)}"), this)
     return this
 
   addSplit: (split) ->

    else
      return { type: 'and', filters }

rangeToDruidInterval = (interval) ->
  return interval.map((d) -> d.toISOString().replace('Z', '')).join('/')


class DruidQueryBuilder
  @ALL_DATA_CHUNKS = 10000
  @allTimeInterval = ["1000-01-01/3000-01-01"]

  constructor: (@dataSource, @timeAttribute, @forceInterval, @approximate) ->
    throw new Error("must have a dataSource") unless typeof @dataSource is 'string'

    @nameIndex = 0
    @intervals = null
    @useCache = true

  unionIntervals: (intervals) ->
    null # ToDo
