Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean code

  • Loading branch information...
commit 1205176a8af08e2cb3729e5955dd441e58b4e98a 1 parent 86c687f
@ckroxigor ckroxigor authored
Showing with 10 additions and 60 deletions.
  1. +10 −60 eval.ml
View
70 eval.ml
@@ -296,7 +296,7 @@ let aggregate_function_to_SQL f t =
| "+count" -> "COUNT("^t^")"
| "+min" -> "MIN("^t^")"
| "+max" -> "MAX("^t^")"
- | _ -> raise(QueryError("Error1: Unknown aggregation function '"^f^"'"))
+ | _ -> raise(QueryError("Error: Unknown aggregation function '"^f^"'"))
;;
(*Returns an string containing the select information deleting the repeated names*)
@@ -319,9 +319,8 @@ let prepare_variables_selection cols as_name =
Hashtbl.add hash_names s 1;
s
end
- | AggFun (f,t) -> raise(QueryError("Error1: Aggregation function not expected in a goal."))
+ | AggFun (f,t) -> raise(QueryError("Error: Aggregation function not expected in a goal."))
else "" in
-Printf.printf "AS_NAME: %s\n" c_name;
let exists =
begin
try
@@ -333,36 +332,11 @@ Printf.printf "AS_NAME: %s\n" c_name;
false
end
in
-Printf.printf "exists: %b\n" exists;
let out_name = if not exists && List.length as_name > n && (String.compare c_name "") != 0 then " AS "^c_name else "" in
-Printf.printf "result: %s\n" ((param_to_string x)^out_name);
(param_to_string x)^out_name
) cols)))
;;
-(*Returns an string containing the select information deleting the repeated names*)
-let prepare_variables_selection_old cols as_name =
- let hash_names = Hashtbl.create 10 in
- Hashtbl.add hash_names "_ANONVAR_" 1; (* ignoring anonymous variables *)
- (String.concat ", " (List.filter(fun x -> (String.compare x "") != 0) (List.mapi(fun n x ->
- match x with
- | ParamI i -> ""
- | ParamS s ->
- begin
- try
- let _ = Hashtbl.find hash_names s in
- ""
- with Not_found ->
- (*Init the list in the hash*)
- Hashtbl.add hash_names s 1;
- (param_to_string (List.nth cols n))^" AS "^s
- end
- | AggFun (f,t) -> raise(QueryError("Error1: Aggregation function not expected in a goal."))
- ) as_name)))
-;;
-
-
-
let rec agg_param_to_string p =
match p with
| ParamS s -> s
@@ -396,8 +370,6 @@ let prepare_groupby_selection2 cols as_name =
) cols)))
;;
-
-
let prepare_groupby_having cols as_name =
let hash_names = Hashtbl.create 10 in
let res =
@@ -423,7 +395,7 @@ let prepare_groupby_having cols as_name =
Hashtbl.add hash_names s n;
""
end
- | AggFun (f,t) -> raise(QueryError("Error1: Aggregation function not expected in a goal."))
+ | AggFun (f,t) -> raise(QueryError("Error: Aggregation function not expected in a goal."))
) as_name)))
in
if (String.compare res "") == 0 then "" else " HAVING "^res;
@@ -444,27 +416,6 @@ let prepare_groupby_selection cols =
(String.concat ", " (List.mapi(fun n x -> (param_to_string x)^" AS "^"_attr"^(string_of_int n)^"_") cols))
;;
-let prepare_having_restrictions cols as_name =
- let hash_names = Hashtbl.create 10 in
- (List.filter(fun x -> (String.compare x "") != 0) (List.mapi(fun n x ->
- let name = "_attr"^(string_of_int n)^"_" in
- match x with
- | ParamI i -> (agg_param_to_string (List.nth cols n))^" = "^string_of_int i
- | ParamS s ->
- begin
- try
- let c = Hashtbl.find hash_names x in
- (agg_param_to_string (List.nth cols n))^" = "^c
- with Not_found ->
- (*Init the list in the hash*)
- if ((String.compare s "_ANONVAR_") != 0) then (* ignoring anonymous variables *)
- Hashtbl.add hash_names x (agg_param_to_string (List.nth cols n));
- ""
- end
- | AggFun (f,t) -> raise(QueryError("Error3: Aggregation function not expected in a goal."))
- ) as_name))
-;;
-
let check_is_aggregatesd cols =
List.exists(fun x -> match x with
| ParamI i -> false
@@ -489,7 +440,7 @@ let s_prepare_variables_selection cols as_name =
Hashtbl.add hash_names s 1;
(List.nth cols n)^" AS "^s
end
- | AggFun (f,t) -> raise(QueryError("Error2: Aggregation function not expected in a goal."))
+ | AggFun (f,t) -> raise(QueryError("Error: Aggregation function not expected in a goal."))
) as_name)))
;;
@@ -510,7 +461,7 @@ let generate_select_restrictions cols as_name =
Hashtbl.add hash_names x (param_to_string (List.nth cols n));
""
end
- | AggFun (f,t) -> raise(QueryError("Error3: Aggregation function not expected in a goal."))
+ | AggFun (f,t) -> raise(QueryError("Error: Aggregation function not expected in a goal."))
) as_name))
;;
@@ -531,7 +482,7 @@ let s_generate_select_restrictions cols as_name =
Hashtbl.add hash_names x (List.nth cols n);
""
end
- | AggFun (f,t) -> raise(QueryError("Error4: Aggregation function not expected in a goal."))
+ | AggFun (f,t) -> raise(QueryError("Error: Aggregation function not expected in a goal."))
) as_name))
;;
@@ -633,7 +584,7 @@ let rec get_subquery_body e name col_names =
(*Printf.printf "Head columns(%i): %s\n" (List.length head_cols) (String.concat "," (List.map(fun x -> param_to_string x) head_cols));*)
(*Check if it is aggregated*)
let is_aggregated = check_is_aggregatesd head_cols in
-Printf.printf "Is aggregated: %b\n" is_aggregated;
+ (*Printf.printf "Is aggregated: %b\n" is_aggregated;*)
let lrel = get_rel predicate in
(*Printf.printf "Number of relations: %i\n" (List.length lrel);*)
if num_queried_columns == num_anonym_columns then
@@ -644,7 +595,7 @@ Printf.printf "Is aggregated: %b\n" is_aggregated;
let col_names2 = (if is_recursive || is_aggregated then prepare_variables_selection_rec_queries name col_names else col_names) in
(*Printf.printf "col_names2(%i): %s\n" (List.length head_cols) (String.concat "," (List.map(fun x -> param_to_string x) col_names2));*)
let sel = (prepare_variables_selection head_cols col_names2) in
-Printf.printf "Sel: %s\n" sel;
+ (*Printf.printf "Sel: %s\n" sel;*)
if is_aggregated then
(String.concat " " [
"SELECT";
@@ -659,7 +610,6 @@ Printf.printf "Sel: %s\n" sel;
prepare_groupby_columns head_cols;
(*"HAVING";*)
prepare_groupby_having head_cols col_names
- (*prepare_having_restrictions head_cols col_names2;*)
])
else
(String.concat " " [
@@ -691,7 +641,7 @@ and gen_sub_tables e l sel sel_as name =
let vars_not_in = ref [] in (*Conatins name of the variables that appear in the negated realtions*)
let num_table = ref 0 in (*Contains the number of the table in the select*)
let str_sel = prepare_variables_selection sel_as sel in
-Printf.printf "Str_sel: %s\n" str_sel;
+ (*Printf.printf "Str_sel: %s\n" str_sel;*)
(*Generate the table expressions for the from*)
let tables = List.filter (fun x -> match x with | Rel r -> true | _ -> false) l in
for ntable = 0 to List.length tables - 1 do
@@ -706,7 +656,7 @@ Printf.printf "Str_sel: %s\n" str_sel;
vars_from := List.append vars_from.contents (List.filter(fun x -> match x with
| ParamS s -> true
| ParamI i -> false
- | AggFun (f,t) -> raise(QueryError("Error5: Aggregation function not expected in a goal."))) col_names);
+ | AggFun (f,t) -> raise(QueryError("Error: Aggregation function not expected in a goal."))) col_names);
done;
(*Extract negations*)
let nots = ref (List.filter (fun x -> match x with | Not t -> true | _ -> false) l) in
Please sign in to comment.
Something went wrong with that request. Please try again.