【问题标题】:How to execute a query with Amazon Athena without exhausted resources?如何在不耗尽资源的情况下使用 Amazon Athena 执行查询?
【发布时间】:2018-10-06 00:57:47
【问题描述】:

我正在尝试执行此查询以获取一些数据。我在 s3://my_datalake/my_table/year=2018/month=9/day=7/ 中的 s3 上的文件大小为 1.1 TB,我有 10014 个 snappy.parquet 对象。

SELECT  array_join(array_agg(distinct endpoint),',') as endpoints_all, count(endpoint) as count_endpoints 
    FROM my_datalake.my_table  
    WHERE year=2018 and month=09 and day=07 
    and ts between timestamp '2018-09-07 00:00:00' and timestamp '2018-09-07 23:59:59'
    and status = '2'
    GROUP BY domain, size, device_id, ip

但我得到了那个错误:

在这个比例因子下查询耗尽的资源

(Run time: 6 minutes 41 seconds, Data scanned: 153.87GB)

我有分区 YEAR、MONTH、DAY 和 HOUR。我该怎么做这个查询?我可以使用 Amazon Athena 还是需要使用其他工具?

我的表的架构是:

   CREATE EXTERNAL TABLE `ssp_request_prueba`(
  `version` string, 
  `adunit` string, 
  `adunit_original` string, 
  `brand` string, 
  `country` string, 
  `device_connection_type` string, 
  `device_density` string, 
  `device_height` string, 
  `device_id` string, 
  `device_type` string, 
  `device_width` string, 
  `domain` string, 
  `endpoint` string, 
  `endpoint_version` string, 
  `external_dfp_id` string, 
  `id_req` string, 
  `ip` string, 
  `lang` string, 
  `lat` string, 
  `lon` string, 
  `model` string, 
  `ncc` string, 
  `noc` string, 
  `non` string, 
  `os` string, 
  `osv` string, 
  `scc` string, 
  `sim_operator_code` string, 
  `size` string, 
  `soc` string, 
  `son` string, 
  `source` string, 
  `ts` timestamp, 
  `user_agent` string, 
  `status` string, 
  `delivery_network` string, 
  `delivery_time` string, 
  `delivery_status` string, 
  `delivery_network_key` string, 
  `delivery_price` string, 
  `device_id_original` string, 
  `tracking_limited` string, 
  `from_cache` string, 
  `request_price` string)
PARTITIONED BY ( 
  `year` int, 
  `month` int, 
  `day` int, 
  `hour` int)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
  's3://my_datalake/my_table'
TBLPROPERTIES (
  'has_encrypted_data'='false', 
  'transient_lastDdlTime'='1538747353')

【问题讨论】:

  • 您能否发送有关您的数据源的更多信息?它在 S3 还是 db 上?数据示例。你使用什么格式的数据?
  • 它在 s3 上。字段 domain、size、device_id、ip 和 endpoint 是字符串。示例:域 = stackoverlow.com。大小=6x6,device_id=a15848sdsd,ip=127.0.0.7,端点=VASTSDSDSDS128。
  • 您可以使用“SHOW CREATE TABLE my_datalake.my_table; 发送表定义吗?

标签: amazon-s3 amazon-athena


【解决方案1】:

问题可能与array_join 和array_agg 函数有关。我想在这种情况下,已经超出了 Athena 服务中节点的内存限制。可能 Athena 无法结合这些功能来管理如此大量的数据。

【讨论】:

  • 我刚试过,但我遇到了同样的问题:在这个比例因子下查询耗尽的资源(运行时间:6 分 57 秒,扫描的数据:133.91GB)
  • 在 s3 上您在查询中使用的这些分区的文件大小是多少?我的意思是在 s3://my_datalake/my_table/year=2018/month=9/day=7/
  • 查询有效吗?结果是什么 ? SELECT count(endpoint) as count_endpoints FROM my_datalake.my_table WHERE year=2018 and month=09 and day=07 and ts between timestamp '2018-09-07 00:00:00' and timestamp '2018-09-07 23:59' :59' and status = '2' GROUP BY domain, size, device_id, ip
  • 我的示例数据不超过 10GB,但在您的情况下,您可能超出了 athena 服务中每个节点的内存限制。我还测试了查询的一些变体,使用 array_join(array_agg(distinct endpoint),',')、array_agg(distinct endpoint) 和 count(distinct endpoint),所有变体在 s3 上扫描相同数量的数据,所以可能是内存问题。
  • 我的意思是,您可以将查询放入 EMR 并生成平面文件以供以后在 Athena 中查询。你有相当大的数据湖,所以我想你在执行临时查询时会遇到很多问题。我认为您应该在 Athena 中执行查询之前转换部分数据并创建数据子集。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-03
  • 2018-01-06
  • 2017-12-03
  • 2016-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多