【问题标题】:AWS push down predicate not working when reading HIVE partitionsAWS 下推谓词在读取 HIVE 分区时不起作用
【发布时间】:2021-12-23 06:22:24
【问题描述】:

尝试测试一些粘合功能,并且下推谓词不适用于 S3 中已分区以用于 HIVE 的 avro 文件。我们的分区如下:YYYY-MM-DD。

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])

sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)

filterpred = "loaddate == '2019-08-08'"

datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "hive", 
                                                            table_name = "stuff", 
                                                            pushDownPredicate = filterpred)
print ('############################################')
print "COUNT: ", datasource0.count()
print ('##############################################')

df = datasource0.toDF()
df.show(5)

job.commit()

但是我仍然看到胶水将日期拉到范围之外。:

Opening 's3://data/2018-11-29/part-00000-a58ee9cb-c82c-46e6-9657-85b4ead2927d-c000.avro' for reading
2019-09-13 13:47:47,071 INFO [Executor task launch worker for task 258] s3n.S3NativeFileSystem (S3NativeFileSystem.java:open(1208)) -
Opening 's3://data/2017-09-28/part-00000-53c07db9-05d7-4032-aa73-01e239f509cf.avro' for reading

我尝试使用以下示例:

AWS Glue DynamicFrames and Push Down Predicate

AWS Glue DynamicFrames and Push Down Predicate

AWS Glue pushdown predicate not working properly

目前提出的解决方案都不适合我。我尝试添加分区列(加载日期),将其取出,引用,取消引用等。仍然在日期范围之外。

【问题讨论】:

    标签: amazon-web-services aws-glue


    【解决方案1】:

    您的代码中存在语法错误。传递给 from_catalog 函数的正确参数是“push_down_predicate”而不是“pushDownPredicate”。

    示例 sn-p:

    datasource0 = glueContext.create_dynamic_frame.from_catalog(
                 database = "hive", 
                 table_name = "stuff",
                 push_down_predicate = filterpred)
    

    参考 AWS 文档:https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-partitions.html

    【讨论】:

    • 疯了,我错过了那个错字。奇怪的是,它每次都成功运行而没有指出语法错误。
    【解决方案2】:

    似乎您的分区不是 Hive 命名样式,因此您必须在查询中使用 use a default one partition_0。另外,正如另一个答案中所建议的,该参数称为push_down_predicate

    filterpred = "partition_0 == '2019-08-08'"
    
    datasource0 = glue_context.create_dynamic_frame.from_catalog(
        database = "hive",
        table_name = "stuff",
        push_down_predicate = filterpred)
    

    【讨论】:

      【解决方案3】:

      确保您的代码正确分区并在 Glue 爬虫中运行以创建分区表。

      在 Athena 中运行查询以修复您的表。

       MSCK REPAIR TABLE tbl;
      

      在 Athena 中运行查询以检查分区。

        SHOW PARTITIONS tbl;
      

      Scala 你可以使用以下代码

      没有谓词

           val datasource0 = glueContext.getCatalogSource(database = "ny_taxi_db", tableName = "taxi_tbl", redshiftTmpDir = "", transformationContext = "datasource0").getDynamicFrame()
      
           datasource0.toDF().count()
      

      带谓词:

       val predicate = "(year == '2016' and year_month == '201601' and year_month_day == '20160114')"
      
       val datasource1 = glueContext.getCatalogSource(database = "ny_taxi_db",tableName = "taxi_tbl" , transformationContext = "datasource1",pushDownPredicate = predicate).getDynamicFrame() //
      
       datasource1.toDF().count()
      

      Python 你可以使用以下代码:

      没有谓词

        ds = glueContext.create_dynamic_frame.from_catalog(database = 
       "ny_taxi_db" , table_name = "taxi_data_by_vender", transformation_ctx = 
      "datasource0" )
      
        ds.toDF().count()
      

      带谓词:

      ds1 = glueContext.create_dynamic_frame.from_catalog(database = "ny_taxi_db" , table_name = "taxi_data_by_vender", transformation_ctx = "datasource1" , push_down_predicate = "(vendorid == 1)")
          
      ds1.toDF().count()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-06-18
        • 2021-07-11
        • 2019-09-28
        • 2021-03-05
        • 2018-12-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多