# `SparkEx.MergeIntoWriter`
[🔗](https://github.com/lukaszsamson/spark_ex/blob/v0.1.1/lib/spark_ex/merge_into_writer.ex#L1)

Builder for MERGE INTO table commands.

Constructed via `SparkEx.DataFrame.merge_into/2`, configured with match
actions, and executed with `merge/1`.

## Examples

    import SparkEx.Functions, only: [col: 1]

    df
    |> DataFrame.merge_into("target_table")
    |> MergeIntoWriter.on(col("source.id") |> Column.eq(col("target.id")))
    |> MergeIntoWriter.when_matched_update_all()
    |> MergeIntoWriter.when_not_matched_insert_all()
    |> MergeIntoWriter.merge()

# `action`

```elixir
@type action() ::
  {:delete | :insert | :insert_star | :update | :update_star,
   SparkEx.Column.expr() | nil,
   [{SparkEx.Column.expr(), SparkEx.Column.expr()}]}
```

# `t`

```elixir
@type t() :: %SparkEx.MergeIntoWriter{
  condition: SparkEx.Column.expr() | nil,
  match_actions: [action()],
  not_matched_actions: [action()],
  not_matched_by_source_actions: [action()],
  schema_evolution: boolean(),
  source_df: SparkEx.DataFrame.t(),
  target_table: String.t()
}
```

# `merge`

```elixir
@spec merge(t()) :: :ok | {:error, term()}
```

Executes the MERGE INTO command.

Returns `:ok` or `{:error, reason}`.

# `on`

```elixir
@spec on(t(), SparkEx.Column.t()) :: t()
```

Sets the merge condition (ON clause).

# `when_matched_delete`

```elixir
@spec when_matched_delete(t(), SparkEx.Column.t() | nil) :: t()
```

Deletes matched rows. Optional condition filters which matched rows to delete.

# `when_matched_update`

```elixir
@spec when_matched_update(
  t(),
  %{required(String.t()) =&gt; SparkEx.Column.t()},
  SparkEx.Column.t() | nil
) ::
  t()
```

Updates specific columns of matched rows.

`assignments` is a map of `%{"target_col" => Column.t()}`.

# `when_matched_update_all`

```elixir
@spec when_matched_update_all(t(), SparkEx.Column.t() | nil) :: t()
```

Updates all columns of matched rows.

# `when_not_matched_by_source_delete`

```elixir
@spec when_not_matched_by_source_delete(t(), SparkEx.Column.t() | nil) :: t()
```

Deletes target rows not matched by source.

# `when_not_matched_by_source_update`

```elixir
@spec when_not_matched_by_source_update(
  t(),
  %{required(String.t()) =&gt; SparkEx.Column.t()},
  SparkEx.Column.t() | nil
) :: t()
```

Updates specific columns of target rows not matched by source.

`assignments` is a map of `%{"target_col" => Column.t()}`.

# `when_not_matched_by_source_update_all`

```elixir
@spec when_not_matched_by_source_update_all(t(), SparkEx.Column.t() | nil) :: t()
```

Updates all columns of target rows not matched by source.

# `when_not_matched_insert`

```elixir
@spec when_not_matched_insert(
  t(),
  %{required(String.t()) =&gt; SparkEx.Column.t()},
  SparkEx.Column.t() | nil
) :: t()
```

Inserts specific columns for non-matched source rows.

`assignments` is a map of `%{"target_col" => Column.t()}`.

# `when_not_matched_insert_all`

```elixir
@spec when_not_matched_insert_all(t(), SparkEx.Column.t() | nil) :: t()
```

Inserts all columns for non-matched source rows.

# `with_schema_evolution`

```elixir
@spec with_schema_evolution(t()) :: t()
```

Enables schema evolution for the merge operation.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
