当您使用 Ibis API 查询 impala 时,出于某种原因,Ibis API 强制它成为子查询(当您加入 4-5 个表时,它突然变得超级慢)。由于连接时的列名重叠问题,它根本不会正常连接。我想要一种快速重命名列的方法,这不是 SQL 通常的工作方式吗?
i0 = impCon.table('shop_inventory')
s0 = impCon.table('shop_expenditure')
s0 = s0.relabel({'element_date': 'spend_element_date', 'element_shop_item': 'spend_shop_item'})
jn = i0.inner_join(s0, [i0['element_date'] == s0['spend_element_date'], i0['element_shop_item'] == s0['spend_shop_item']])
jn.materialize()
jn.execute(limit=900)
然后你有 IBIS 生成 SQL,它在没有我建议的情况下对它进行 SUBQUERYING:
SELECT *
FROM (
SELECT `element_date`, `element_shop_item`, `element_address`, `element_expiration`,
`element_category`, `element_description`
FROM dbp.`shop_inventory`
) t0
INNER JOIN (
SELECT `element_shop_item` AS `spend_shop_item`, `element_comm` AS `spend_comm`,
`element_date` AS `spend_date`, `element_amount`,
`element_spend_type`, `element_shop_item_desc`
FROM dbp.`shop_spend`
) t1
ON (`element_shop_item` = t1.`spend_shop_item`) AND
(`element_category` = t1.`spend_category`) AND
(`element_subcategory` = t1.`spend_subcategory`) AND
(`element_comm` = t1.`spend_comm`) AND
(`element_date` = t1.`spend_date`)
LIMIT 900
为什么这么难?
理想情况下,它应该很简单:
jn = i0.inner_join(s0, [s0['element_date'].as('spend_date') == i0['element_date']]
生成一个:SELECT s0.element_date as spend_date, i0.element_date INNER JOIN s0 dbp.shop_spend ON s0.spend_date == i0.element_date
正确的?
我们是否不允许在正在连接的表上使用相同的列名?我很确定在原始 SQL 中,您可以只使用“X AS Y”而无需子查询。