【问题标题】:Spark.sql run query without any optimizations (aws glue athena)Spark.sql 在没有任何优化的情况下运行查询(aws 胶水雅典娜)
【发布时间】:2020-03-18 10:45:36
【问题描述】:

我需要从 Glue Job (spark.sql) 向 AWS 上的 Athena 执行 SQL 请求。

我的查询很简单

df = spark.sql("select * from hashes 
               where year='2109' and month='10' and day='08' 
               and myhashes in (%s) order by timestamp desc" % ( 
               ",".join( "'"+str(x)+"'" for x in myhashes ))  )

这段代码产生一个类似的字符串

select * from hashes where year='2019' 
     and month='10' and day='08' 
     and myhashes in (
    '06SN931', 
    '06SN931', 
    '06SP317', 
    ...........
    '86X0297'
    )

它在雅典娜中运行得很好

但是,如果我运行 Glue Job,火花似乎会将查询从 IN 转换为 OR 语法,例如

其中 .... day ='08' and (myhashes = '06XH8V3' or myhashes = '06X68P4' or my.....) 并产生错误。

Here the exception
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.sql.hive.client.Shim_v0_13.getPartitionsByFilter(HiveShim.scala:759)
    ... 64 more


Caused by: MetaException(message:1 validation error detected: Value 'year = '2019' and month = '10' and day = '08' and (myhashes = '06XH58V3' or myhashes = '06X658P4' or myhashes = '45X42051' or myhashes = '15S03560' or myhashes = '10S2868' or myhashes = '416S2661' or myhashes = 'dDSD' or myhashes = 'DSSD' or myhashes = '13XE639' or myhashes = '06X668N7' or myhashes = '06X364T2' or 
.......
myhashes = '96S652207' or myhashes = '06X26365M' or myhashes = '10X560c89' or myhashes = '06X01N8' or )' 


at 'expression' failed to satisfy constraint: Member must have length less than or equal to 2048 (Service: AWSGlue; Status Code: 400; Error Code: ValidationException; Request ID: 83f7bc7b-0d10-11ea-9a8c-fdfadfa2a22b))
            at com.amazonaws.glue.catalog.converters.CatalogToHiveConverter.getHiveException(CatalogToHiveConverter.java:100)
            at com.amazonaws.glue.catalog.converters.CatalogToHiveConverter.wrapInHiveException(CatalogToHiveConverter.java:88)
            at com.amazonaws.glue.catalog.metastore.GlueMetastoreClientDelegate.getCatalogPartitions(GlueMetastoreClientDelegate.java:948)
            at com.amazonaws.glue.catalog.metastore.GlueMetastoreClientDelegate.getPartitions(GlueMetastoreClientDelegate.java:911)
            at com.amazonaws.glue.catalog.metastore.AWSCatalogMetastoreClient.listPartitionsByFilter(AWSCatalogMetastoreClient.java:1179)
            at org.apache.hadoop.hive.ql.metadata.Hive.getPartitionsByFilter(Hive.java:2255)
            ... 69 more

        End of LogType:stdout

有没有办法禁用 SQL 的 Spark 内部优化?

【问题讨论】:

标签: sql apache-spark pyspark


【解决方案1】:

错误消息提示您的查询太长(超过 2048 个字符)。 AWS Athena 和 AWS Glue 具有不同的约束条件。

如果可能,尝试通过加入一个包含myhashes 值的表来过滤表(“哈希”),而不是使用 SQL in,只要数字要比较的元素会变大。

【讨论】:

  • 这是一种解决方法,而不是解决方案。有没有办法解除这个约束?
  • @Vlad 我非常怀疑。您在询问是否可以请求 AWS 更改其 API 之一的限制。虽然您通常可以请求增加消耗的资源和吞吐量,但我不知道像这样更改 API 调用限制。虽然不是 AWS 员工,所以也许你最好直接问他们?请注意,正如您所写,此问题与 Spark 内部优化无关,因为 Spark 很乐意允许您制定此类查询计划,即使有更好的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-04
  • 2019-04-29
  • 2021-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多