Skip to content

Commit

Permalink
Merge pull request #49 from hiroshi-cl/feat/dl2u_del2
Browse files Browse the repository at this point in the history
ast2sqlでviewのΔに対してinsert/deleteを出力しない
  • Loading branch information
hiroshi-cl authored Oct 25, 2024
2 parents 3b52686 + 61cba51 commit ec0e384
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/dl2u_2-2.dl
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion src/ast2sql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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) ->
Expand Down Expand Up @@ -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 Option.fold ~none:true ~some:((<>) table) view_name && TableSet.mem table existent_tables then
let update =
match delta_kind with
| Insert ->
Expand Down

0 comments on commit ec0e384

Please sign in to comment.