Commit 2c338d3a authored by Pietro Abate's avatar Pietro Abate

[r2004-07-09 14:35:43 by cmiachon] CQL Aggregats. min, max, sum, avg, count,...

[r2004-07-09 14:35:43 by cmiachon] CQL Aggregats. min, max, sum, avg, count, member, distinct_values
todo: precise type for min max and distinct_values

Original author: cmiachon
Date: 2004-07-09 14:35:43+00:00
parent 4ec2d7d5
......@@ -629,7 +629,7 @@ let query_min = function
| Pair(i,p) ->
let rec aux l i = match l with
| Pair(j,r) -> if (compare i j <0) then aux r i else aux r j
| Atom(_) -> i
| Atom a when a = Sequence.nil_atom -> i
| _ -> assert false
in aux p i
|_ -> assert false
......@@ -638,7 +638,7 @@ let query_max = function
| Pair(i,p) ->
let rec aux l i = match l with
| Pair(j,r) -> if (compare i j >0) then aux r i else aux r j
| Atom(_) -> i
| Atom a when a = Sequence.nil_atom -> i
| _ -> assert false
in aux p i
|_ -> assert false
......@@ -647,7 +647,7 @@ let query_sum = function
| Pair(Integer i,p) ->
let rec aux l i = match l with
| Pair(Integer j,r) -> aux r i+Intervals.V.get_int(j)
| Atom(_) -> i
| Atom a when a = Sequence.nil_atom -> i
| _ -> assert false
in Integer(Intervals.V.from_int(aux p (Intervals.V.get_int(i))))
|_ -> assert false
......@@ -657,7 +657,7 @@ let query_avg = function
| Pair(Integer i,p) ->
let rec aux l i n = match l with
| Pair(Integer j,r) -> aux r (i+Intervals.V.get_int(j)) (n+1)
| Atom(_) -> i/(n+1)
| Atom a when a = Sequence.nil_atom -> i/(n+1)
| _ -> assert false
in Integer(Intervals.V.from_int(aux p (Intervals.V.get_int(i)) 0))
|_ -> assert false
......@@ -666,12 +666,37 @@ let query_count = function
| Pair(Integer i,p) ->
let rec aux l n = match l with
| Pair(_,r) -> aux r (n+1)
| Atom(_) -> n
| Atom a when a = Sequence.nil_atom -> n
| _ -> assert false
in Integer(Intervals.V.from_int(aux p 1))
| Atom a when a = Sequence.nil_atom -> Integer (Intervals.V.from_int 0)
|_ -> assert false
(* todo : sum, avg [Int+] instead of [Int*]
typage precis pour min et max
let query_member e l = match l with
| Pair(i,p) ->
let rec aux l i = match l with
| Pair(j,r) -> if (compare i j =0) then vtrue else aux r i
| Atom a when a = Sequence.nil_atom -> vfalse
| _ -> failwith"tutu"
in aux (Pair(i,p)) (e)
| Atom a when a = Sequence.nil_atom -> vfalse
|_ -> failwith"tata"
let query_distinct = function
| Pair(i,p) ->
let rec aux l1 l2 = match l1 with
| Pair(h,t) -> if (query_member h t)=vtrue
then (aux t l2) else (aux t (l2@[h]))
| Atom a when a = Sequence.nil_atom -> l2
| _ -> failwith "titi"
in sequence(aux (Pair(i,p)) [])
| Atom a when a = Sequence.nil_atom -> (Atom(Sequence.nil_atom))
|_ -> failwith "titi"
(* todo : typage precis pour min et max et distinct_values
*)
......@@ -118,8 +118,12 @@ val cduce2ocaml_bigint : t -> Big_int.big_int
val print_utf8: U.t -> unit
(*CQL Aggregats *)
val query_min: t-> t
val query_max: t-> t
val query_sum: t-> t
val query_avg: t-> t
val query_count: t-> t
val query_member: t->t -> t
val query_distinct: t -> t
......@@ -315,19 +315,26 @@ unary_op_gen "flatten"
register_fun "raise" any Types.empty
(fun v -> raise (Value.CDuceExn v));;
(* CQL agregats *)
register_fun "min" Sequence.any any
register_fun "min" (Sequence.plus any) any
(Value.query_min );;
register_fun "max" Sequence.any any
register_fun "max" (Sequence.plus any) any
(Value.query_max );;
register_fun "sum" Sequence.int int
register_fun "sum" (Sequence.plus int) int
(Value.query_sum );;
register_fun "avg" Sequence.int int
register_fun "avg" (Sequence.plus int) int
(Value.query_avg );;
register_fun "count" Sequence.any int
(Value.query_count );;
binary_op_cst "member" any Sequence.any bool
(Value.query_member );;
register_fun "distinct_values" Sequence.any Sequence.any
(Value.query_distinct );;
......@@ -44,9 +44,7 @@ let recurs f =
let star_node t = recurs (fun n -> Types.cup nil_type (Types.times t n ))
let any_node = star_node (Types.cons Types.any)
let int_node = star_node (Types.cons (Types.int_any))
let any = Types.descr any_node
let int= Types.descr int_node
let seqseq = Types.descr (star_node any_node)
let star t = Types.descr (star_node (Types.cons t))
......
......@@ -3,7 +3,6 @@ val nil_node: Types.Node.t
val nil_atom: Atoms.V.t
val nil_cst: Types.Const.t
val any: Types.t
val int: Types.t
val seqseq: Types.t
val string: Types.t
......
......@@ -473,19 +473,6 @@ let any = {
absent= false;
}
let int_any = {
hash = 0;
times = BoolPair.empty;
xml = BoolPair.empty;
arrow = BoolPair.empty;
record= BoolRec.empty;
ints = Intervals.any;
atoms = Atoms.empty;
chars = Chars.empty;
abstract = Abstract.empty;
absent= false;
}
let non_constructed =
{ any with
......
......@@ -67,7 +67,6 @@ val diff : t -> t -> t
val neg : t -> t
val empty : t
val any : t
val int_any : t
val any_node : Node.t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment