anchor.diff:          infer_col_type(get_sel_ddl(), {{window_agg_fn, 'SUM'}, [{integer, 4}]}, [])
       ).
   
  +compile_query_with_function_type_error_1_test() ->
  +    {ok, Q} = get_query(
  +          "SELECT SUM(location) FROM GeoCheckin "
  +          "WHERE time > 5000 AND time < 10000"
  +          "AND user = 'user_1' AND location = 'derby'"),
  +    ?assertEqual(
  +        {error, [{invalid_function_call,'SUM',[varchar]}]},
  +        compile(get_standard_ddl(), Q, 100)
  +    ).
  +
  +compile_query_with_function_type_error_2_test() ->
  +    {ok, Q} = get_query(
  +          "SELECT SUM(location), AVG(location) FROM GeoCheckin "
  +          "WHERE time > 5000 AND time < 10000"
  +          "AND user = 'user_1' AND location = 'derby'"),
  +    ?assertEqual(
  +        {error, [
  +            {invalid_function_call,'SUM',[varchar]},
  +            {invalid_function_call,'AVG',[varchar]}]},
  +        compile(get_standard_ddl(), Q, 100)
  +    ).
  +
  +compile_query_with_function_type_error_3_test() ->
  +    {ok, Q} = get_query(
  +          "SELECT AVG(location + 1) FROM GeoCheckin "
  +          "WHERE time > 5000 AND time < 10000"
  +          "AND user = 'user_1' AND location = 'derby'"),
  +    ?assertEqual(
  +        {error, [{invalid_type,'+',varchar,sint64}]},
  +        compile(get_standard_ddl(), Q, 100)
  +    ).
  +
  +compile_query_with_arithmetic_type_error_1_test() ->
  +    {ok, Q} = get_query(
  +          "SELECT location + 1 FROM GeoCheckin "
  +          "WHERE time > 5000 AND time < 10000"
  +          "AND user = 'user_1' AND location = 'derby'"),
  +    ?assertEqual(
  +        {error, [{invalid_type,'+',varchar,sint64}]},
  +        compile(get_standard_ddl(), Q, 100)
  +    ).
  +
  +compile_query_with_arithmetic_type_error_2_test() ->
  +    {ok, Q} = get_query(
  +          "SELECT 2*(location + 1) FROM GeoCheckin "
  +          "WHERE time > 5000 AND time < 10000"
  +          "AND user = 'user_1' AND location = 'derby'"),
  +    ?assertEqual(
  +        {error, [{invalid_type,'+',varchar,sint64}]},
  +        compile(get_standard_ddl(), Q, 100)
  +    ).
  +
   -endif.
  
positive.code:           col_return_types :: [riak_pb_ts_codec:ldbvalue()],
            col_name         :: riak_pb_ts_codec:tscolumnname(),
            clause           :: function(),
            is_valid         :: true | {error, [any()]},
            finaliser        :: [function()]
           }).
  
  
negative.code:     {error, 'query is already compiled'};
  compile(#ddl_v1{}, ?SQL_SELECT{'SELECT' = #riak_sel_clause_v1{ clause = [] } }, _MaxSubQueries) ->
      {error, 'full table scan not implemented'};
  compile(#ddl_v1{} = DDL,
          ?SQL_SELECT{is_executable = false, type = sql} = Q, MaxSubQueries) ->
      case compile_select_clause(DDL, Q) of
          {ok, S} ->
              compile_where_clause(DDL, Q?SQL_SELECT{'SELECT' = S}, MaxSubQueries);
          {error, _} = Error ->
              Error
      end.
  
  %% adding the local key here is a bodge
  %% should be a helper fun in the generated DDL module but I couldn't
  