AWS Glue 3.0 이상은 Linux Foundation Delta Lake 프레임워크를 지원합니다. Delta Lake는 ACID 트랜잭션을 수행하고, 메타데이터 처리를 확장하고, 스트리밍 및 배치 데이터 처리를 통합하는 데 도움이 되는 오픈 소스 데이터 레이크 스토리지 프레임워크입니다. 이 항목에서는 Delta Lake 테이블에서 데이터를 전송하거나 저장할 때 AWS Glue에서 데이터를 사용하는 데 사용할 수 있는 기능에 대해 설명합니다. Delta Lake에 대한 자세한 내용은 공식 Delta Lake 설명서를 참조하세요.
AWS Glue를 사용하여 Amazon S3의 Delta Lake 테이블에서 읽기 및 쓰기 작업을 수행하거나 AWS Glue 데이터 카탈로그를 사용하여 Delta Lake 테이블로 작업할 수 있습니다. 삽입, 업데이트, 테이블 배치 읽기 및 쓰기와 같은 추가 작업도 지원됩니다. Delta Lake 테이블을 사용할 경우 Delta Lake Python 라이브러리(예: DeltaTable.forPath
)의 메서드를 사용할 수도 있습니다. Delta Lake Python 라이브러리에 대한 자세한 내용은 Delta Lake의 Python 설명서 소개 페이지를 참조하세요.
다음 표에는 각 AWS Glue 버전에 포함된 Delta Lake의 버전이 나와 있습니다.
AWS Glue 버전 |
지원되는 Delta Lake 버전 |
4.0 |
2.1.0 |
3.0 |
1.0.0 |
AWS Glue가 지원하는 데이터 레이크 프레임워크에 대한 자세한 내용은 AWS Glue ETL 작업에서 데이터 레이크 프레임워크 사용 섹션을 참조하세요.
Delta Lake for AWS Glue를 활성화하려면 다음 작업을 완료합니다.
-
delta
를 --datalake-formats
작업 파라미터의 값으로 지정합니다. 자세한 내용은 AWS Glue 작업 파라미터 섹션을 참조하세요.
-
AWS Glue 작업에 대한 --conf
키를 생성하고 다음 값으로 설정합니다. 또는 스크립트에서 SparkConf
를 사용하여 다음 구성을 설정할 수 있습니다. 이러한 설정은 Apache Spark에서 Delta Lake 테이블을 올바르게 처리하는 데 도움이 됩니다.
spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension --conf spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog
다른 Delta Lake 버전 사용
AWS Glue에서 지원하지 않는 Delta Lake 버전을 사용하려면 --extra-jars
작업 파라미터를 사용하여 고유한 Delta Lake JAR 파일을 지정하세요. --datalake-formats
작업 파라미터의 값으로 delta
를 포함하지 마세요. 이 경우에 Delta Lake Python 라이브러리를 사용하려면 --extra-py-files
작업 파라미터를 사용하여 라이브러리 JAR 파일을 지정해야 합니다. Python 라이브러리는 Delta Lake JAR 파일에 패키징되어 제공됩니다.
다음 AWS Glue ETL 스크립트는 Amazon S3에 Delta Lake 테이블을 작성하고 AWS Glue 데이터 카탈로그에 테이블을 등록하는 방법을 보여줍니다.
- Python
-
# Example: Create a Delta Lake table from a DataFrame
# and register the table to Glue Data Catalog
additional_options = {
"path": "s3://<s3Path>
"
}
dataFrame.write \
.format("delta") \
.options(**additional_options) \
.mode("append") \
.partitionBy("<your_partitionkey_field>
") \
.saveAsTable("<your_database_name>
.<your_table_name>
")
- Scala
-
// Example: Example: Create a Delta Lake table from a DataFrame
// and register the table to Glue Data Catalog
val additional_options = Map(
"path": "s3://<s3Path>
"
)
dataFrame.write.format("delta")
.options(additional_options)
.mode("append")
.partitionBy("<your_partitionkey_field>
")
.saveAsTable("<your_database_name>
.<your_table_name>
")
다음 AWS Glue ETL 스크립트는 예: Amazon S3에 Delta Lake 테이블을 작성하고 AWS Glue 데이터 카탈로그에 등록에서 생성한 Delta Lake 테이블을 읽습니다.
- Python
-
이 예에서는 create_data_frame.from_catalog 메서드를 사용합니다.
# Example: Read a Delta Lake table from Glue Data Catalog
from awsglue.context import GlueContext
from pyspark.context import SparkContext
sc = SparkContext()
glueContext = GlueContext(sc)
df = glueContext.create_data_frame.from_catalog(
database="<your_database_name>
",
table_name="<your_table_name>
",
additional_options=additional_options
)
- Scala
-
이 예에서는 getCatalogSource 메서드를 사용합니다.
// Example: Read a Delta Lake table from Glue Data Catalog
import com.amazonaws.services.glue.GlueContext
import org.apacke.spark.SparkContext
object GlueApp {
def main(sysArgs: Array[String]): Unit = {
val spark: SparkContext = new SparkContext()
val glueContext: GlueContext = new GlueContext(spark)
val df = glueContext.getCatalogSource("<your_database_name>
", "<your_table_name>
",
additionalOptions = additionalOptions)
.getDataFrame()
}
}
이 예에서는 예: Amazon S3에 Delta Lake 테이블을 작성하고 AWS Glue 데이터 카탈로그에 등록에서 생성한 Delta Lake 테이블에 데이터를 삽입합니다.
이 예에서는 AWS Glue 데이터 카탈로그를 Apache Spark Hive 메타스토어로 사용하기 위해 --enable-glue-datacatalog
작업 파라미터를 설정해야 합니다. 자세한 내용은 AWS Glue 작업 파라미터 단원을 참조하세요.
- Python
-
이 예에서는 write_data_frame.from_catalog 메서드를 사용합니다.
# Example: Insert into a Delta Lake table in S3 using Glue Data Catalog
from awsglue.context import GlueContext
from pyspark.context import SparkContext
sc = SparkContext()
glueContext = GlueContext(sc)
glueContext.write_data_frame.from_catalog(
frame=dataFrame,
database="<your_database_name>
",
table_name="<your_table_name>
",
additional_options=additional_options
)
- Scala
-
이 예에서는 getCatalogSink 메서드를 사용합니다.
// Example: Insert into a Delta Lake table in S3 using Glue Data Catalog
import com.amazonaws.services.glue.GlueContext
import org.apacke.spark.SparkContext
object GlueApp {
def main(sysArgs: Array[String]): Unit = {
val spark: SparkContext = new SparkContext()
val glueContext: GlueContext = new GlueContext(spark)
glueContext.getCatalogSink("<your_database_name>
", "<your_table_name>
",
additionalOptions = additionalOptions)
.writeDataFrame(dataFrame, glueContext)
}
}
이 예에서는 Spark API를 사용하여 Amazon S3에서 Delta Lake 테이블을 읽습니다.
- Python
-
# Example: Read a Delta Lake table from S3 using a Spark DataFrame
dataFrame = spark.read.format("delta").load("s3://<s3path/>
")
- Scala
-
// Example: Read a Delta Lake table from S3 using a Spark DataFrame
val dataFrame = spark.read.format("delta").load("s3://<s3path/>
")
이 예에서는 Spark를 사용하여 Amazon S3에 Delta Lake 테이블을 씁니다.
- Python
-
# Example: Write a Delta Lake table to S3 using a Spark DataFrame
dataFrame.write.format("delta") \
.options(**additional_options) \
.mode("overwrite") \
.partitionBy("<your_partitionkey_field>
")
.save("s3://<s3Path>
")
- Scala
-
// Example: Write a Delta Lake table to S3 using a Spark DataFrame
dataFrame.write.format("delta")
.options(additionalOptions)
.mode("overwrite")
.partitionBy("<your_partitionkey_field>
")
.save("s3://<s3path/>
")