Skip to content

Commit

Permalink
ast2sqlでviewのΔに対してinsert/deleteを出力しない
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshi-cl committed Sep 18, 2024
1 parent 09e2f54 commit 9130a64
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/ast2sql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2420,14 +2420,14 @@ let divide_rules_into_groups (table_env : table_environment) (rules : Expr.rule
err @@ HasMoreThanOneRuleGroup state.current_delta_target
else
let group = DeltaGroup (state.current_delta_target, List.rev state.current_accumulated) in
return (table_env,
PredGrouping {
current_pred_target = table;
current_accumulated = [ intermediate ];
},
already_handled_delta |> DeltaKeySet.add state.current_delta_target,
already_handled_pred,
group :: group_acc)
return (table_env,
PredGrouping {
current_pred_target = table;
current_accumulated = [ intermediate ];
},
already_handled_delta |> DeltaKeySet.add state.current_delta_target,
already_handled_pred,
group :: group_acc)
end

| DeltaHead (delta_kind, table, columns_and_vars) ->
Expand Down Expand Up @@ -2474,7 +2474,7 @@ let divide_rules_into_groups (table_env : table_environment) (rules : Expr.rule
already_handled_delta |> DeltaKeySet.add state.current_delta_target,
already_handled_pred,
group :: group_acc)
end
end

) (table_env, NoneState, DeltaKeySet.empty, TableSet.empty, []) >>= fun (table_env, state_opt, _, _, group_acc) ->
match state_opt with
Expand Down 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, _) = 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) ->
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 table <> view_name && TableSet.mem table existent_tables then
let update =
match delta_kind with
| Insert ->
Expand All @@ -2584,7 +2585,7 @@ let convert_expr_to_operation_based_sql (expr : expr) : (sql_operation list, err
in
return (i + 1, creation :: creation_acc, update :: update_acc, delta_env, table_env)
else
return (i + 1, creation :: creation_acc, update_acc, delta_env, table_env)
return (i + 1, creation :: creation_acc, update_acc, delta_env, table_env)

) (0, [], [], DeltaEnv.empty, table_env) >>= fun (_, creation_acc, update_acc, _, _) ->

Expand Down

0 comments on commit 9130a64

Please sign in to comment.