anchor.diff:  %%%
   
   -ifdef(TEST).
  --include_lib("eunit/include/eunit.hrl").
   
   helper_compile_def_to_module(SQL) ->
       Lexed = riak_ql_lexer:get_tokens(SQL),
  
positive.code: -export([explain_query/1, explain_query/2]).
  -export([explain_query_print/1]).
  
  
  %% NOTE on table_to_bucket/1: Clients will work with table
  %% names. Those names map to a bucket type/bucket name tuple in Riak,
  
negative.code:         validate_rows(Mod, [{}, {<<"f">>, <<"s">>, 11}, {a, <<"s">>, 12}, {"hithere"}])
      ).
  
  bad_timestamp_test() ->
      BadFormat = "20151T10",
      BadQuery = lists:flatten(
                   io_lib:format("select * from table1 "
                                 "where b > '~s' and "
                                 " b < '20151013T20:00:00'", [BadFormat])),
      {_DDL, _Mod} = helper_compile_def_to_module(
          "CREATE TABLE table1 ("
          "a SINT64 NOT NULL, "
          "b TIMESTAMP NOT NULL, "
          "c SINT64 NOT NULL, "
          "PRIMARY KEY((a, quantum(b, 15, 's')), a, b))"),
      Lexed = riak_ql_lexer:get_tokens(BadQuery),
      {ok, Q} = riak_ql_parser:parse(Lexed),
      ?assertMatch({error, <<"Invalid date/time string">>},
                   build_sql_record(select, Q, undefined)).
  
  good_timestamp_test() ->
      GoodQuery = "select * from table1 "
          " where b > '20151013T18:30' and "
          " b < '20151013T20:00:00' ",
      {_DDL, _Mod} = helper_compile_def_to_module(
          "CREATE TABLE table1 ("
          "a SINT64 NOT NULL, "
          "b TIMESTAMP NOT NULL, "
          "c SINT64 NOT NULL, "
          "PRIMARY KEY((a, quantum(b, 15, 's')), a, b))"),
      Lexed = riak_ql_lexer:get_tokens(GoodQuery),
      {ok, Q} = riak_ql_parser:parse(Lexed),
      {ok, Select} = build_sql_record(select, Q, undefined),
      Where = Select?SQL_SELECT.'WHERE',
      %% Navigate the tree looking for integer values for b
      %% comparisons. Verify that we find both (hence `2' as our
      %% equality)
      ?assertEqual(2,
                   check_integer_timestamps(
                     hd(Where),
                     %% The first value, the lower bound, is
                     %% 20151013T18:31:00 because of the
                     %% incomplete datetime string
                     1444761060000,
                     1444766400000)).
  
  check_integer_timestamps({_Op, A, B}, Lower, Upper) when is_tuple(A), is_tuple(B) ->
      check_integer_timestamps(A, Lower, Upper) +
          check_integer_timestamps(B, Lower, Upper);
  check_integer_timestamps({'<', <<"b">>, Compare}, _Lower, Upper) ->
      ?assertEqual({integer, Upper}, Compare),
      1;
  check_integer_timestamps({'>', <<"b">>, Compare}, Lower, _Upper) ->
      ?assertEqual({integer, Lower}, Compare),
      1;
  check_integer_timestamps(_, _, _) ->
      0.
  
  timestamp_parsing_test() ->
      BadFormat = "20151T10",
      BadQuery = lists:flatten(
                   io_lib:format("select * from table1 "
                                 "where b > '~s' and "
                                 " b < '201510T20:00:00'", [BadFormat])),
      {_DDL, Mod} = helper_compile_def_to_module(
          "CREATE TABLE table1 ("
          "a SINT64 NOT NULL, "
          "b TIMESTAMP NOT NULL, "
          "c SINT64 NOT NULL, "
          "PRIMARY KEY((a, quantum(b, 15, 's')), a, b))"),
      ?assertEqual(timestamp, Mod:get_field_type([<<"b">>])),
      Lexed = riak_ql_lexer:get_tokens(BadQuery),
      {ok, Q} = riak_ql_parser:parse(Lexed),
      ?assertMatch({error, <<"Invalid date/time string">>},
                   build_sql_record(select, Q, undefined)).
  
  -endif.
  