# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0.  If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.

module batsql;
module sql;


pattern calc.hash( v:hge ) :lng address MKEYhash; 
command batcalc.hash( b:bat[:hge] ) :bat[:lng] address MKEYbathash;

command sql.dec_round( v:hge, r:hge ) :hge 
address hge_dec_round_wrap
comment "round off the value v to nearests multiple of r";
command batsql.dec_round( v:bat[:hge], r:hge ) :bat[:hge] 
address hge_bat_dec_round_wrap
comment "round off the value v to nearests multiple of r";

command sql.round( v:hge, d:int, s:int, r:bte) :hge
address hge_round_wrap
comment "round off the decimal v(d,s) to r digits behind the dot (if r < 0, before the dot)";
command batsql.round( v:bat[:hge], d:int, s:int, r:bte) :bat[:hge]
address hge_bat_round_wrap
comment "round off the decimal v(d,s) to r digits behind the dot (if r < 0, before the dot)";

command calc.second_interval( sc:int, v:hge, ek:int, sk:int ) :lng
address hge_dec2second_interval
comment "cast hge decimal to a second_interval";


command calc.hge( v:void, digits:int ) :hge 
address nil_2num_hge
comment "cast to hge and check for overflow";
command calc.hge( v:void, digits:int, scale:int ) :hge 
address nil_2dec_hge
comment "cast to dec(hge) and check for overflow";
command batcalc.hge( v:bat[:void], digits:int ) :bat[:hge] 
address batnil_2num_hge
comment "cast to hge and check for overflow";
command batcalc.hge( v:bat[:void], digits:int, scale:int ) :bat[:hge] 
address batnil_2dec_hge
comment "cast to dec(hge) and check for overflow";

command calc.hge( v:str, digits:int ) :hge 
address str_2num_hge
comment "cast to hge and check for overflow";
command calc.hge( v:str, digits:int, scale:int ) :hge 
address str_2dec_hge
comment "cast to dec(hge) and check for overflow";
command batcalc.hge( v:bat[:str], digits:int ) :bat[:hge] 
address batstr_2num_hge
comment "cast to hge and check for overflow";
command batcalc.hge( v:bat[:str], digits:int, scale:int ) :bat[:hge] 
address batstr_2dec_hge
comment "cast to dec(hge) and check for overflow";


pattern calc.month_interval( v:hge, ek:int, sk:int ) :int
address month_interval
comment "cast hge to a month_interval and check for overflow";

pattern calc.second_interval( v:hge, ek:int, sk:int ) :lng
address second_interval
comment "cast hge to a second_interval and check for overflow";

include sql_decimal_hge;
include sql_aggr_hge;
