在配置单元顶部添加一些行 table
Add some lines at the top of hive table
我在配置单元中有一个 table 这种形式(之前):
AB_dimp|SF_0060H00000nhSrmQAE|EBA Order 1127735|Execute|New From
AB_dimp|SF_0060H00000nhSwkQAE|EBA Order 1127725|Execute|New From
AB_Dimp|SF_0060H00000nhSyDQAU|EBA Order 1127728|Execute|New From
我想将这 3 行以这种形式(之后)显示在配置单元中 table 的顶部:
[Yellow]
Cat ID|AN_Net|
[network]
AB_dimp|SF_0060H00000nhSkPQAU|EBA Order 1127708|Execute|New From
AB_DIMP|SF_0060H00000nhSl8QAE|EBA Order 1127709|Execute|New From
AB_DIMP|SF_0060H00000nhSrmQAE|EBA Order 1127735|Execute|New From
请问我如何在 Hive 中实现它?
a.) 首先,创建另一个 table(比方说,NewTable)并插入这 3 条记录
b.) 现在,将现有数据插入另一个 table
insert overwrite table NewTable select * from ExisitngTable;
c.) 删除 ExisitngTable
d.) 现在将数据从 NewTable 插入到 ExisitngTable
insert overwrite table ExisitngTable select * from NewTable name;
全部使用联合:
select '[Yellow]' as col_name union all
select 'ID|AN_Net|' union all
select '[network]' union all
select col_name from your_table;
如果要在 table 中添加这些行,不仅 select 它们,您不需要中间 table 来实现:
insert overwrite your_table
select * from
(
select '[Yellow]' as col_name union all
select 'ID|AN_Net|' union all
select '[network]' union all
select col_name from your_table
)s;
但请记住,table 中的行未排序。当你 select table 而没有 order by
时,select 正在许多映射器上并行执行。基础文件正在拆分,映射器读取每个自己的拆分。它们是并行执行的,彼此完全隔离,并且 return 结果也是独立的。哪个更快它的结果将被更快 returned,你看,只有 order by 保证行的顺序 returned。这意味着下次当您 select 这个 table 时,您可能会有这些额外的行 return 而不是第一行。只有 ORDER BY 才能保证行的顺序。并且您需要有一些可用于对行进行排序的列,例如 id,或者您的列可用于排序依据。
如果 table 很小,它有可能在单个映射器上读取,并且行将按原始顺序 returned,就像在基础文件中一样。
要保留文件中的行顺序,您可以添加 row_order 列并在 ORDER BY 的上层查询中使用它:
select DRM_Pln_Parent, opportunityid, opportunity_name
from
(
SELECT 1 as row_order, '[hier]' as DRM_Pln_Parent, '' as opportunityid, '' as opportunity_name
UNION ALL
SELECT 2 as row_order, 'Opportunity ID|SF_AllOpportunities|' as DRM_Pln_Parent, '' as opportunityid, '' as opportunity_name
UNION ALL
SELECT 3 as row_order, '[relation]' as DRM_Pln_Parent, '' as opportunityid, '' as opportunity_name
UNION ALL
SELECT DISTINCT 4 as row_order, 'SF_AllOpportunities' AS DRM_Pln_Parent,
CONCAT('SF_',opportunityid) as opportunityid,
opportunity_name,
from ...
)s
order by row_order
为了更好地理解,另请参阅此答案:
我在配置单元中有一个 table 这种形式(之前):
AB_dimp|SF_0060H00000nhSrmQAE|EBA Order 1127735|Execute|New From
AB_dimp|SF_0060H00000nhSwkQAE|EBA Order 1127725|Execute|New From
AB_Dimp|SF_0060H00000nhSyDQAU|EBA Order 1127728|Execute|New From
我想将这 3 行以这种形式(之后)显示在配置单元中 table 的顶部:
[Yellow]
Cat ID|AN_Net|
[network]
AB_dimp|SF_0060H00000nhSkPQAU|EBA Order 1127708|Execute|New From
AB_DIMP|SF_0060H00000nhSl8QAE|EBA Order 1127709|Execute|New From
AB_DIMP|SF_0060H00000nhSrmQAE|EBA Order 1127735|Execute|New From
请问我如何在 Hive 中实现它?
a.) 首先,创建另一个 table(比方说,NewTable)并插入这 3 条记录
b.) 现在,将现有数据插入另一个 table
insert overwrite table NewTable select * from ExisitngTable;
c.) 删除 ExisitngTable
d.) 现在将数据从 NewTable 插入到 ExisitngTable
insert overwrite table ExisitngTable select * from NewTable name;
全部使用联合:
select '[Yellow]' as col_name union all
select 'ID|AN_Net|' union all
select '[network]' union all
select col_name from your_table;
如果要在 table 中添加这些行,不仅 select 它们,您不需要中间 table 来实现:
insert overwrite your_table
select * from
(
select '[Yellow]' as col_name union all
select 'ID|AN_Net|' union all
select '[network]' union all
select col_name from your_table
)s;
但请记住,table 中的行未排序。当你 select table 而没有 order by
时,select 正在许多映射器上并行执行。基础文件正在拆分,映射器读取每个自己的拆分。它们是并行执行的,彼此完全隔离,并且 return 结果也是独立的。哪个更快它的结果将被更快 returned,你看,只有 order by 保证行的顺序 returned。这意味着下次当您 select 这个 table 时,您可能会有这些额外的行 return 而不是第一行。只有 ORDER BY 才能保证行的顺序。并且您需要有一些可用于对行进行排序的列,例如 id,或者您的列可用于排序依据。
如果 table 很小,它有可能在单个映射器上读取,并且行将按原始顺序 returned,就像在基础文件中一样。
要保留文件中的行顺序,您可以添加 row_order 列并在 ORDER BY 的上层查询中使用它:
select DRM_Pln_Parent, opportunityid, opportunity_name
from
(
SELECT 1 as row_order, '[hier]' as DRM_Pln_Parent, '' as opportunityid, '' as opportunity_name
UNION ALL
SELECT 2 as row_order, 'Opportunity ID|SF_AllOpportunities|' as DRM_Pln_Parent, '' as opportunityid, '' as opportunity_name
UNION ALL
SELECT 3 as row_order, '[relation]' as DRM_Pln_Parent, '' as opportunityid, '' as opportunity_name
UNION ALL
SELECT DISTINCT 4 as row_order, 'SF_AllOpportunities' AS DRM_Pln_Parent,
CONCAT('SF_',opportunityid) as opportunityid,
opportunity_name,
from ...
)s
order by row_order
为了更好地理解,另请参阅此答案: