我想在 Amazon Simple Storage Service (Amazon S3) 位置的特定分割上執行 AWS Glue 作業。
簡短描述
若要篩選 AWS Glue Data Catalog 中的分割區,請使用下拉述詞。與篩選器轉換不同,下拉述詞可讓您篩選分割區,而不必列出和讀取資料集中的所有檔案。
解決方法
建立 AWS Glue 作業,然後在** DynamicFrame** 中指定下拉述詞。在下列範例中,作業只會處理 s3://awsexamplebucket/product_category=Video 分割區中的資料:
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "testdata", table_name = "sampletable", transformation_ctx = "datasource0",push_down_predicate = "(product_category == 'Video')")
在下列範例中,下拉述詞會依日期篩選。作業只會處理 s3://awsexamplebucket/year=2019/month=08/day=02 分割區中的資料:
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "testdata", table_name = "sampletable", transformation_ctx = "datasource0",push_down_predicate = "(year == '2019' and month == '08' and day == '02')")
在下列範例中,非 Hive 樣式分割區的下拉述詞依日期篩選。作業只會處理 s3://awsexamplebucket/2019/07/03 分割區中的資料:
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "testdata", table_name = "sampletable", transformation_ctx = "datasource0",push_down_predicate ="(partition_0 == '2019' and partition_1 == '07' and partition_2 == '03')" )