From 09e2f540c8b0a2a5d35fba2bb1a4c86252d26eea Mon Sep 17 00:00:00 2001 From: Hiroshi Date: Sat, 31 Aug 2024 17:49:03 +0900 Subject: [PATCH 1/3] add example --- examples/dl2u_2-2.dl | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/dl2u_2-2.dl diff --git a/examples/dl2u_2-2.dl b/examples/dl2u_2-2.dl new file mode 100644 index 0000000..b1df2c1 --- /dev/null +++ b/examples/dl2u_2-2.dl @@ -0,0 +1,7 @@ +source a('A':int, 'B':int). +source b('B':int, 'C':int). +view v('A':int, 'B':int, 'C':int). +-a(A, B) :- a(A, B) , not __updated__v(A, B, _). +-b(B, C) :- a(GENV2, B) , b(B, C) , b(B, GENV3) , not -v(GENV2, B, GENV3) , not __updated__v(_, B, C). +__updated__v(A, B, C) :- a(A, B) , b(B, C) , not -v(A, B, C). +-v(GENV1, GENV2, GENV3) :- a(GENV1, GENV2) , b(GENV2, GENV3) , GENV2 = 30. From 9a4d524e243dab240beb66d7aa296515d0e6ae52 Mon Sep 17 00:00:00 2001 From: Hiroshi Date: Wed, 18 Sep 2024 16:26:03 +0900 Subject: [PATCH 2/3] =?UTF-8?q?ast2sql=E3=81=A7view=E3=81=AE=CE=94?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E3=81=97=E3=81=A6insert/delete=E3=82=92?= =?UTF-8?q?=E5=87=BA=E5=8A=9B=E3=81=97=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast2sql.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ast2sql.ml b/src/ast2sql.ml index 22fb365..7aeb42f 100644 --- a/src/ast2sql.ml +++ b/src/ast2sql.ml @@ -2505,6 +2505,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err table_env |> TableEnv.add table cols ) TableEnv.empty in + let (view_name, _) = get_view expr in let existent_tables = table_env |> TableEnv.to_list |> List.map fst |> TableSet.of_list in let rules = List.rev expr.rules in (* `expr` holds its rules in the reversed order *) divide_rules_into_groups table_env rules >>= fun (rule_groups, table_env) -> @@ -2559,7 +2560,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err get_column_names_from_table ~error_detail:(InGroup delta_key) table_env table >>= fun cols -> let delta_env = delta_env |> DeltaEnv.add delta_key (temporary_table, cols) in let creation = SqlCreateTemporaryTable (temporary_table, sql_query) in - if TableSet.mem table existent_tables then + if table <> view_name && TableSet.mem table existent_tables then let update = match delta_kind with | Insert -> From 5d8b072d82dc610f13da5566209c1aa6a303a3b9 Mon Sep 17 00:00:00 2001 From: Hiroshi Date: Wed, 18 Sep 2024 21:29:08 +0900 Subject: [PATCH 3/3] =?UTF-8?q?view=E3=81=8C=E3=81=AA=E3=81=84Datalog?= =?UTF-8?q?=E5=BC=8F=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast2sql.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ast2sql.ml b/src/ast2sql.ml index 7aeb42f..d14ff23 100644 --- a/src/ast2sql.ml +++ b/src/ast2sql.ml @@ -2505,7 +2505,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err table_env |> TableEnv.add table cols ) TableEnv.empty in - let (view_name, _) = get_view expr in + let view_name = expr.view |> Option.map (fun (view_name, _) -> view_name) in let existent_tables = table_env |> TableEnv.to_list |> List.map fst |> TableSet.of_list in let rules = List.rev expr.rules in (* `expr` holds its rules in the reversed order *) divide_rules_into_groups table_env rules >>= fun (rule_groups, table_env) -> @@ -2560,7 +2560,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err get_column_names_from_table ~error_detail:(InGroup delta_key) table_env table >>= fun cols -> let delta_env = delta_env |> DeltaEnv.add delta_key (temporary_table, cols) in let creation = SqlCreateTemporaryTable (temporary_table, sql_query) in - if table <> view_name && TableSet.mem table existent_tables then + if Option.fold ~none:true ~some:((<>) table) view_name && TableSet.mem table existent_tables then let update = match delta_kind with | Insert ->