Encrypts specified columns in a DataFrame using the provided key.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> from pyspark.sql import SparkSession
>>> from pyspark.sql.types import StructType, StructField, StringType
>>> spark = SparkSession.builder.getOrCreate()
>>> schema = StructType([
... StructField("id", StringType(), True),
... StructField("name", StringType(), True)
... ])
>>> data = [("1", "Alice"), ("2", "Bob")]
>>> df = spark.createDataFrame(data, schema)
>>> key = generate_encryption_key()
>>> encrypted_df = encrypt_dataframe(df, ["name"], key)
Logs:
-
ERROR: Encryption Failed:
columnis not present in the DataFrame! -
INFO: DataFrame columns
columns_to_encryptencrypted successfully.