> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prophecy.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SetOperation

> Union, Intersect and Difference

<Panel>
  <Info>
    Dependencies:

    * ProphecySparkBasicsPython 0.0.1+
    * ProphecySparkBasicsScala 0.0.1+
  </Info>

  <Info>
    Cluster requirements:

    * UC dedicated clusters 14.3+ supported
    * UC standard clusters 14.3+ supported
    * Livy clusters 3.0.1+ supported
  </Info>
</Panel>

Use the SetOperation gem to perform addition or subtraction of rows from DataFrames with identical schemas and different data.

## Parameters

| Parameter      | Description                                                                                                                                                                                                                                                                                                                                                                                                                     |
| :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| DataFrame 1    | First input DataFrame                                                                                                                                                                                                                                                                                                                                                                                                           |
| DataFrame 2    | Second input DataFrame                                                                                                                                                                                                                                                                                                                                                                                                          |
| DataFrame N    | Nth input DataFrame                                                                                                                                                                                                                                                                                                                                                                                                             |
| Operation type | Choose an operation type: <ul><li> Union: Returns a DataFrame containing rows in any one of the input DataFrames, while preserving duplicates.</li><li>Intersect All: Returns a DataFrame containing rows in all of the input DataFrames, while preserving duplicates.</li><li>Except All: Returns a DataFrames containing rows in the first DataFrame, but not in the other DataFrames, while preserving duplicates.</li></ul> |

To add more input DataFrames, you can click the `+` icon on the left sidebar.

<img src="https://mintcdn.com/prophecy-62973bd0/5tvw_2e98LqB5rz7/data-engineering/gems/transform/img/set_add_inputs.png?fit=max&auto=format&n=5tvw_2e98LqB5rz7&q=85&s=a033da1cba73e40da1591bd8bd666707" alt="Set Operation - Add input dataframe" width="556" height="136" data-path="data-engineering/gems/transform/img/set_add_inputs.png" />

## Examples

### Operation Type: `Union`

<img src="https://mintcdn.com/prophecy-62973bd0/5tvw_2e98LqB5rz7/data-engineering/gems/transform/img/set_eg_1.png?fit=max&auto=format&n=5tvw_2e98LqB5rz7&q=85&s=2b080e37bfb6db040ffa28826ade224a" alt="Example usage of Set Operation - Union" width="1798" height="904" data-path="data-engineering/gems/transform/img/set_eg_1.png" />

<CodeGroup>
  ```python example.py theme={null}
  def union(spark: SparkSession, in0: DataFrame, in1: DataFrame, ) -> DataFrame:
   return in0.unionAll(in1)
  ```

  ```scala example.scala theme={null}
  object union {
   def apply(spark: SparkSession, in0: DataFrame, in1: DataFrame): DataFrame =
   in0.unionAll(in1)
  }
  ```
</CodeGroup>

### Operation Type: `Intersect All`

<img src="https://mintcdn.com/prophecy-62973bd0/5tvw_2e98LqB5rz7/data-engineering/gems/transform/img/set_eg_2.png?fit=max&auto=format&n=5tvw_2e98LqB5rz7&q=85&s=3c305e23bf95c71fe14010de27ea3492" alt="Example usage of Set Operation - Intersect All" width="1822" height="868" data-path="data-engineering/gems/transform/img/set_eg_2.png" />

<CodeGroup>
  ```python example.py theme={null}
  def intersectAll(spark: SparkSession, in0: DataFrame, in1: DataFrame, ) -> DataFrame:
   return in0.intersectAll(in1)
  ```

  ```scala example.scala theme={null}
  object intersectAll {
   def apply(spark: SparkSession, in0: DataFrame, in1: DataFrame): DataFrame =
   in0.intersectAll(in1)
  }
  ```
</CodeGroup>

### Operation Type: `Except All`

<img src="https://mintcdn.com/prophecy-62973bd0/5tvw_2e98LqB5rz7/data-engineering/gems/transform/img/set_eg_3.png?fit=max&auto=format&n=5tvw_2e98LqB5rz7&q=85&s=b00cb82cff891b7ba6e2dd2531d4d783" alt="Example usage of Set Operation - Except All" width="1812" height="783" data-path="data-engineering/gems/transform/img/set_eg_3.png" />

<CodeGroup>
  ```python example.py theme={null}
  def exceptAll(spark: SparkSession, in0: DataFrame, in1: DataFrame, ) -> DataFrame:
   return in0.exceptAll(in1)
  ```

  ```scala example.scala theme={null}
  object exceptAll {
   def apply(spark: SparkSession, in0: DataFrame, in1: DataFrame): DataFrame =
   in0.exceptAll(in1)
  }
  ```
</CodeGroup>
