SparkEx.MergeIntoWriter (SparkEx v0.1.0)

Copy Markdown View Source

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()

Summary

Functions

Executes the MERGE INTO command.

Sets the merge condition (ON clause).

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

Updates specific columns of matched rows.

Updates all columns of matched rows.

Deletes target rows not matched by source.

Updates specific columns of target rows not matched by source.

Updates all columns of target rows not matched by source.

Inserts specific columns for non-matched source rows.

Inserts all columns for non-matched source rows.

Enables schema evolution for the merge operation.

Types

action()

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

t()

@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()
}

Functions

merge(m)

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

Executes the MERGE INTO command.

Returns :ok or {:error, reason}.

on(m, condition)

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

Sets the merge condition (ON clause).

when_matched_delete(m, condition \\ nil)

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

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

when_matched_update(m, assignments, condition \\ nil)

@spec when_matched_update(
  t(),
  %{required(String.t()) => 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(m, condition \\ nil)

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

Updates all columns of matched rows.

when_not_matched_by_source_delete(m, condition \\ nil)

@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(m, assignments, condition \\ nil)

@spec when_not_matched_by_source_update(
  t(),
  %{required(String.t()) => 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(m, condition \\ nil)

@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(m, assignments, condition \\ nil)

@spec when_not_matched_insert(
  t(),
  %{required(String.t()) => 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(m, condition \\ nil)

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

Inserts all columns for non-matched source rows.

with_schema_evolution(m)

@spec with_schema_evolution(t()) :: t()

Enables schema evolution for the merge operation.