diff options
Diffstat (limited to 'lib/analysers/query.ml')
-rw-r--r-- | lib/analysers/query.ml | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/analysers/query.ml b/lib/analysers/query.ml index e24da78..f89f5f0 100644 --- a/lib/analysers/query.ml +++ b/lib/analysers/query.ml @@ -1,15 +1,15 @@ open StdLabels module Expression = ImportExpression module Q = Expression.Query -module Syntax = ImportConf.Syntax module Table = ImportDataTypes.Table module Path = ImportDataTypes.Path (* Collect all the tables pointed by the expression. *) -let pointed_tables : Syntax.t -> 'a Expression.T.t -> (Table.t * string) list = +let pointed_tables : + ImporterSyntax.t -> 'a Expression.T.t -> (Table.t * string) list = fun conf expression -> Expression.T.fold_values expression ~init:[] ~f:(fun acc path -> - let table = ImportConf.get_table_for_name conf path.Path.alias in + let table = ImporterSyntax.get_table_for_name conf path.Path.alias in let table_name = Table.name table in (table, table_name) :: acc) |> List.sort_uniq ~cmp:Stdlib.compare @@ -37,7 +37,7 @@ let create_table : Dependency.t -> string = type query = { q : string; - parameters : ImportCSV.DataType.t Seq.t; + parameters : ImportDataTypes.Value.t Seq.t; } let rec take_elements : @@ -88,9 +88,9 @@ let clean_window : The select query will name each column with an alias, and the map allow to find which source is pointed by this alias. *) -let select : Syntax.t -> query * Path.t ImportExpression.T.t array = +let select : ImporterSyntax.t -> query * Path.t ImportExpression.T.t array = fun conf -> - let filter = ImportConf.CTE.of_filters conf.filters in + let filter = ImporterSyntax.CTE.of_filters conf.filters in (* For each column in the configuration file, add the corresponding element in the query. @@ -136,7 +136,7 @@ let select : Syntax.t -> query * Path.t ImportExpression.T.t array = Chunk.append ~head:request_header ~tail:filters; let formatter = Format.formatter_of_buffer b in - (match conf.Syntax.uniq with + (match conf.ImporterSyntax.uniq with | [] -> () | uniq -> Format.fprintf formatter "\nGROUP BY %a" @@ -149,7 +149,7 @@ let select : Syntax.t -> query * Path.t ImportExpression.T.t array = in Queue.transfer seq parameters)) uniq); - (match conf.Syntax.sort with + (match conf.ImporterSyntax.sort with | [] -> () | sort -> Format.fprintf formatter "\nORDER BY %a" @@ -166,15 +166,16 @@ let select : Syntax.t -> query * Path.t ImportExpression.T.t array = ({ q = Buffer.contents b; parameters = Queue.to_seq parameters }, headers) -let check_external : Syntax.t -> Syntax.Extern.t -> query = +let check_external : ImporterSyntax.t -> ImporterSyntax.Extern.t -> query = fun conf external_ -> let internal_chunk = Chunk.create () in - Chunk.add_expression ~conf internal_chunk external_.Syntax.Extern.intern_key; + Chunk.add_expression ~conf internal_chunk + external_.ImporterSyntax.Extern.intern_key; let external_key_buffer = Buffer.create 16 in Buffer.add_string external_key_buffer - (Table.print_column external_.Syntax.Extern.target - ("key_" ^ external_.Syntax.Extern.target.name)); + (Table.print_column external_.ImporterSyntax.Extern.target + ("key_" ^ external_.ImporterSyntax.Extern.target.name)); let pointed_tables = pointed_tables conf external_.intern_key in @@ -190,7 +191,9 @@ let check_external : Syntax.t -> Syntax.Extern.t -> query = This not the usual way to proceed (we start from the source and link the externals) *) let rec collect_links : - Syntax.Extern.t -> Syntax.Extern.t list -> Syntax.Extern.t list = + ImporterSyntax.Extern.t -> + ImporterSyntax.Extern.t list -> + ImporterSyntax.Extern.t list = fun table init -> let res = (* Do not add the same external if the value is already present *) @@ -200,16 +203,16 @@ let check_external : Syntax.t -> Syntax.Extern.t -> query = | Some _ -> init in - Expression.T.fold_values ~init table.Syntax.Extern.intern_key + Expression.T.fold_values ~init table.ImporterSyntax.Extern.intern_key ~f:(fun acc expr -> match expr.Path.alias with | None -> acc | Some _ as path -> ( - let table = ImportConf.get_table_for_name conf path in + let table = ImporterSyntax.get_table_for_name conf path in (* Look for this table in the externals *) let external_opt = - List.find_opt conf.Syntax.externals ~f:(fun t -> - t.Syntax.Extern.target == table) + List.find_opt conf.ImporterSyntax.externals ~f:(fun t -> + t.ImporterSyntax.Extern.target == table) in match external_opt with | None -> acc |