anchor.diff:      Query = "select weather from GeoCheckin where time >= 3000 and time < 30000 and user = 'user_1' and location = 'Scotland'",
       {ok, Q} = get_query(Query),
       true = is_query_valid(DDL, Q),
  -    Got = compile(DDL, Q),
       %% now make the result - expecting 2 queries
  -    W1 = [
  -        {startkey,        [
  -            {<<"location">>, varchar, <<"Scotland">>},
  -            {<<"user">>, varchar,    <<"user_1">>},
  -            {<<"time">>, timestamp, 3000}
  -        ]},
  -        {endkey,          [
  -            {<<"location">>, varchar, <<"Scotland">>},
  -            {<<"user">>, varchar,    <<"user_1">>},
  -            {<<"time">>, timestamp, 15000}
  -        ]},
  -      {filter,          []}
  -     ],
  -    W2 = [
  -        {startkey,        [
  -            {<<"location">>, varchar, <<"Scotland">>},
  -            {<<"user">>, varchar,    <<"user_1">>},
  -            {<<"time">>, timestamp, 15000}
  -        ]},
  -        {endkey,          [
  -            {<<"location">>, varchar, <<"Scotland">>},
  -            {<<"user">>, varchar,    <<"user_1">>},
  -            {<<"time">>, timestamp, 30000}
  -        ]},
  -      {filter,          []}
  -     ],
  -    Expected =
  -        [Q#riak_sql_v1{is_executable = true,
  +    [Where1, Where2] =
  +        test_data_where_clause(<<"Scotland">>, <<"user_1">>, [{3000, 15000}, {15000, 30000}]),
  +    PK = get_standard_pk(),
  +    LK = get_standard_lk(),
  +    ?assertMatch(
  +        [#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,
  +                       'WHERE'       = Where1,
  +                       partition_key = PK,
  +                       local_key     = LK},
  +         #riak_sql_v1{ is_executable = true,
                          type          = timeseries,
  -                       'WHERE'       = W2,
  -                       partition_key = get_standard_pk(),
  -                       local_key     = get_standard_lk()}],
  -    ?assertEqual(Expected, Got).
  +                       'WHERE'       = Where2,
  +                       partition_key = PK,
  +                       local_key     = LK
  +                       }],
  +        compile(DDL, Q)
  +    ).
   
   %%
   %% test failures
  
positive.code:     Got = compile(DDL, Q),
      ?assertEqual(2, length(Got)).
  
  %% check for spanning precision (same as above except selection range
  %% is exact multiple of quantum size)
  simple_spanning_boundary_precision_test() ->
  
negative.code: 
  complex_with_boolean_rewrite_filter_test() ->
      DDL = get_long_ddl(),
      {ok, Q} = get_query(
          "SELECT weather FROM GeoCheckin "
          "WHERE time > 3000 AND time < 5000 "
          "AND user = 'user_1' AND location = 'Scotland' "
          "AND (myboolean = False OR myboolean = tRue)"),
      true = is_query_valid(DDL, Q),
      [[StartKey, EndKey |_]] =
          test_data_where_clause(<<"Scotland">>, <<"user_1">>, [{3000, 5000}]),
      PK = get_standard_pk(),
      LK = get_standard_lk(),
      Where = [
          StartKey,
          EndKey,
          {filter,
                  {or_,
                      {'=', {field, <<"myboolean">>, boolean}, {const, false}},
                      {'=', {field, <<"myboolean">>, boolean}, {const, true}}
                  }
          },
          {start_inclusive, false}
      ],
      ?assertMatch(
          [#riak_sql_v1{is_executable  = true,
                         type          = timeseries,
                         'WHERE'       = Where,
                         partition_key = PK,
                         local_key     = LK
                       }], 
          compile(DDL, Q)
      ).
  
  %% got for 3 queries to get partition ordering problems flushed out
  simple_spanning_boundary_test() ->
      DDL = get_standard_ddl(),
      {ok, Q} = get_query(
          "select weather from GeoCheckin where time >= 3000 and time < 31000 and user = 'user_1' and location = 'Scotland'"),
      true = is_query_valid(DDL, Q),
      %% get basic query
      %% now make the result - expecting 3 queries
      [Where1, Where2, Where3] =
          test_data_where_clause(<<"Scotland">>, <<"user_1">>, 
                                 [{3000, 15000}, {15000, 30000}, {30000, 31000}]),
      PK = get_standard_pk(),
      LK = get_standard_lk(),
      ?assertMatch([
              #riak_sql_v1{is_executable = true,
                        type          = timeseries,
                        'WHERE'       = Where1,
                        partition_key = PK,
                        local_key     = LK},
              #riak_sql_v1{is_executable = true,
                        type          = timeseries,
                        'WHERE'       = Where2,
                        partition_key = PK,
                        local_key     = LK},
              #riak_sql_v1{is_executable = true,
                        type          = timeseries,
                        'WHERE'       = Where3,
                        partition_key = PK,
                        local_key     = LK}
         ],
         compile(DDL, Q)
      ).
  
  %% Values right at quanta edges are tricky. Make sure we're not
  %% missing them: we should be generating two queries instead of just
  