我想知道如何避免执行期间超出的资源"错误。关于此问题的大多数其他问题涉及每次加入或每次组合,但我已经没有使用过这些问题了。如果我在日期或ABS(HASH(userId))上包含WHERE子句,那么查询可以工作,但我希望整个数据集可用,然后我会进一步过滤它在Tableau中。
如果删除t4查询有效,但我想要最后一列,并且我希望在event_parameters字段中创建更多列以供稍后查询使用。
作业ID是rhi-localytics-db:job_6MaesvuMK6mP6irmAnrcM9R3cx8以防万一。谢谢。
SELECT
t1.userId as userId,
t1.event_time AS event_time,
t1.Diamond_Balance as Diamond_Balance,
t2.Diamond_Change as Diamond_Change,
t3.Gold_Balance as Gold_Balance,
t4.Gold_Change as Gold_Change
FROM (
SELECT
userId,
event_time,
INTEGER(event_parameters.Value) AS Diamond_Balance,
FROM
FLATTEN([game_data], event_parameters)
WHERE
event_name LIKE 'Currency'
AND event_parameters.Name = 'Diamond_Balance'
-- and date(event_time) > '2015-09-11'
-- AND ABS(HASH(userId) % 5) = 0
GROUP BY
userId,
event_time,
Diamond_Balance ) AS t1
INNER JOIN (
SELECT
userId,
event_time,
INTEGER(event_parameters.Value) AS Diamond_Change,
FROM
FLATTEN([game_data], event_parameters)
WHERE
event_name LIKE 'Currency'
AND event_parameters.Name = 'Diamond_Change'
AND INTEGER(event_parameters.Value ) < 14000
AND INTEGER(event_parameters.Value ) > -14000
-- and date(event_time) > '2015-09-11'
-- AND ABS(HASH(userId) % 5) = 0
GROUP BY
userId,
event_time,
Diamond_Change ) AS t2
ON
t1.userId = t2.userId
AND t1.event_time = t2.event_time
INNER JOIN (
SELECT
userId,
event_time,
event_parameters.Value AS Gold_Balance,
FROM
FLATTEN([game_data], event_parameters)
WHERE
event_name LIKE 'Currency'
AND event_parameters.Name = 'Gold_Balance'
-- and date(event_time) > '2015-09-11'
-- AND ABS(HASH(userId) % 5) = 0
GROUP BY
userId,
event_time,
Gold_Balance ) AS t3
ON
t1.userId = t3.userId
AND t1.event_time = t3.event_time
INNER JOIN (
SELECT
userId,
event_time,
INTEGER(event_parameters.Value) AS Gold_Change,
FROM
FLATTEN([game_data], event_parameters)
WHERE
event_name LIKE 'Currency'
AND event_parameters.Name = 'Gold_Change'
-- and date(event_time) > '2015-09-11'
-- AND ABS(HASH(userId) % 5) = 0
GROUP BY
userId,
event_time,
Gold_Change ) AS t4
ON
t1.userId = t4.userId
AND t1.event_time = t4.event_time
答案 0 :(得分:5)
超出资源的一般建议可以在这里找到: https://stackoverflow.com/a/16579558/1375400
请注意,添加EACH
通常是资源超出错误的解决方案,而不是原因。 (虽然有些情况下它可以反过来工作!)
此外,EACH
对GROUP BY
不再有意义,并且很快就会在JOIN
上无关紧要。
答案 1 :(得分:4)
我认为你应该只用一个简单的扫描&#34;来做你所有的逻辑
根本没有加入!
像下面的东西。只是想法 - 但有机会按原样运作:)
SELECT
userId,
event_time,
MAX(CASE WHEN event_parameters.Name = 'Diamond_Balance'
THEN INTEGER(event_parameters.Value) END) AS Diamond_Balance,
MAX(CASE WHEN event_parameters.Name = 'Diamond_Change' AND INTEGER(event_parameters.Value ) BETWEEN -14000 AND 14000
THEN INTEGER(event_parameters.Value)) END AS Diamond_Change,
MAX(CASE WHEN event_parameters.Name = 'Gold_Balance'
THEN INTEGER(event_parameters.Value) END) AS Gold_Balance,
MAX(CASE WHEN event_parameters.Name = 'Gold_Change'
THEN INTEGER(event_parameters.Value) END) AS Gold_Change
FROM
FLATTEN([game_data], event_parameters)
WHERE
event_name LIKE 'Currency'
GROUP BY
userId,
event_time