anchor.diff:          "time timestamp not null, " ++
           "weather varchar not null, " ++
           "temperature varchar, " ++
  -        "PRIMARY KEY((quantum(time, 15, m)), time, user))",
  +        "PRIMARY KEY((quantum(time, 15, s)), time, user))",
       Lexed = riak_ql_lexer:get_tokens(SQL),
       {ok, DDL} = riak_ql_parser:parse(Lexed),
       {module, _Module} = riak_ql_ddl_compiler:make_helper_mod(DDL),
       DDL.
  +
  +get_standard_pk() ->
  +    #key_v1{ast = [
  +		   #hash_fn_v1{mod = riak_ql_quanta,
  +			       fn = quantum,
  +			       args = [
  +				       #param_v1{name = [<<"time">>]},
  +				       15,
  +				       s
  +				      ],
  +			       type = timestamp}
  +		  ]
  +	   }.
  +
  +get_standard_lk() ->
  +    #key_v1{ast = [
  +		   #param_v1{name = [<<"time">>]},
  +		   #param_v1{name = [<<"user">>]}
  +		  ]}.
   
   %%
   %% Unit tests
  
positive.code: %% adding the local key here is a bodge
  %% should be a helper fun in the generated DDL module but I couldn't
  %% write that up in time
  comp2(#ddl_v1{local_key = LK, partition_key = PK} = DDL,
        #riak_sql_v1{is_executable = false,
                     'WHERE'       = W} = Q) ->
      case compile_where(DDL, W) of
          {error, E} -> [{error, E}];
          NewWs      -> [Q#riak_sql_v1{is_executable = true,
                                       type          = timeseries,
                                       'WHERE'       = X,
                                       local_key     = LK,
                                       partition_key = PK} || X <- NewWs]
      end.
  
  %% going forward the compilation and restructuring of the queries will be a big piece of work
  %% for the moment we just brute force assert that the query is a timeseries SQL request
  %% and go with that
  compile_where(DDL, Where) ->
      case is_timeseries(DDL, Where) of
          false         -> {error, {where_not_supported, Where}};
          {true, NewWs} -> NewWs
  end.
  
  is_timeseries(#ddl_v1{bucket = _B, partition_key = PK, local_key = LK},
                [{and_, _LHS, _RHS} = W]) ->
      try    #key_v1{ast = PAST} = PK,
             #key_v1{ast = LAST} = LK,
             LocalFields     = [X || #param_v1{name = X} <- LAST],
             PartitionFields = [X || #param_v1{name = X} <- PAST],
             QuantumFields   = [X || #hash_fn_v1{mod = riak_ql_quanta,
                                                 fn   = quantum,
                                                 args = [#param_v1{name = X} | _Rest]} <- PAST],
             StrippedW = strip(W, []),
             {StartW, EndW, Filter} = break_out_timeseries(StrippedW, LocalFields, QuantumFields),
             StartKey = rewrite(LK, StartW),
             EndKey = rewrite(LK, EndW),
             {true, [[
                     {startkey, StartKey},
                     {endkey,   EndKey},
                     {filter,   Filter}
                    ]]}
      catch  _:_ -> {error, {where_not_timeseries, W}}
      end;
  is_timeseries(_DLL, _Where) ->
      false.
  
  break_out_timeseries(Ands, LocalFields, QuantumFields) ->
      {NewAnds, [Ends, Starts]} = get_fields(QuantumFields, Ands, []),
  
negative.code:                                                           ]},
                                                 {filter,   []}
                                                ],
                                partition_key = get_standard_pk(),
                                local_key     = get_standard_lk()
                       }],
      %% simplify the test we overwrite a couple of fields
      ?assertEqual(Expected, Got).
  
  %% got for 3 queries to get partition ordering problems flushed out
  simple_spanning_boundary_test() ->
      DDL = get_standard_ddl(),
      Query = "select weather from GeoCheckin where time > 3000 and time < 31000 and user = \"user_1\"",
      {ok, Q} = get_query(Query),
      true = is_query_valid(DDL, Q),
      %% get basic query
      Got = compile(DDL, Q),
      %% now make the result - expecting 3 queries
      W1 = [
  	  {startkey, [{<<"time">>, 3000},  {<<"user">>, <<"user_1">>}]},
  	  {endkey,   [{<<"time">>, 15000}, {<<"user">>, <<"user_1">>}]},
  	  {filter, []}
  	 ],
      W2 = [
  	  {startkey, [{<<"time">>, 15000}, {<<"user">>, <<"user_1">>}]},
  	  {endkey,   [{<<"time">>, 30000}, {<<"user">>, <<"user_1">>}]},
  	  {filter, []}
  	 ],
      W3 = [
  	  {startkey, [{<<"time">>, 30000}, {<<"user">>, <<"user_1">>}]},
  	  {endkey,   [{<<"time">>, 31000}, {<<"user">>, <<"user_1">>}]},
  	  {filter, []}
  	 ],
      Expected = [
  		Q#riak_sql_v1{is_executable = true,
  			      type          = timeseries,
  			      'WHERE'       = W1,
                                partition_key = get_standard_pk(),
                                local_key     = get_standard_lk()},
  		Q#riak_sql_v1{is_executable = true,
  			      type          = timeseries,
  			      'WHERE'       = W2,
                                partition_key = get_standard_pk(),
                                local_key     = get_standard_lk()},
  		Q#riak_sql_v1{is_executable = true,
  			      type          = timeseries,
  			      'WHERE'       = W3,
                                partition_key = get_standard_pk(),
                                local_key     = get_standard_lk()}
  	       ],
      ?assertEqual(Expected, Got).
  
  %%
  