在hive中更新具有不同值的每一行

时间:2017-02-20 08:22:03

标签: sql hive

我有2张桌子

表1

key     comment
1       null
2       null
3       null
1       null
1       null
2       null

表2

key     type
1       1
2       2
3       3

我需要

表1

key     comment
1       1
2       2
3       3
1       1
1       1
2       2

我试过了。

UPDATE table1 hist
SET comment = (
    Select type
    from table2 mta
    WHERE hist.key = mta.key
    );

没用。看起来不支持子查询。唯一剩下的就是做一个左连接,但我很好奇是否有可能没有它。

这些是创建语句。 SHOW CREATE TABLE

CREATE TABLE `db.evkuz`(
  `subs_key` string,
  `mtr_comments` string)
ROW FORMAT SERDE
  'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS INPUTFORMAT
  'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
CREATE VIEW `db.RCR` AS 
Select `a`.`line`[64] as `SUBS_KEY`
, `a`.`line`[63] as `TYPE`
from(
  Select split(`rcr`.`line`, '\\|') as `LINE`
  from `db`.`MAK_RCR`
) `a`

这些是describe table

的结果

evkuz

subs_key                string
mtr_comments            string

RCR

subs_key                string
type                    string

这是更新声明

UPDATE t1 
SET t1.MTR_COMMENTS = t2.TYPE
FROM db.evkuz t1
inner join db.RCR t2 
on t1.SUBS_KEY = substr(t2.SUBS_KEY, 2);

1 个答案:

答案 0 :(得分:0)

试试这个

main function encountered error
Traceback (most recent call last):
  File "b.py", line 16, in <module>
    @task.react
  File "/Users/crodrigues/twisted8/src/twisted/internet/task.py", line 908, in react
    finished = main(_reactor, *argv)
  File "b.py", line 19, in main
    d = ensureDeferred(sleepy(reactor))
  File "/Users/crodrigues/twisted8/src/twisted/internet/defer.py", line 823, in ensureDeferred
    return _inlineCallbacks(None, coro, Deferred())
--- <exception caught here> ---
  File "/Users/crodrigues/twisted8/src/twisted/internet/defer.py", line 1301, in _inlineCallbacks
    result = g.send(result)
  File "b.py", line 12, in sleepy
    await asyncio.sleep(3, loop=reactor._asyncioEventloop)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 478, in sleep
    return (yield from future)
builtins.AssertionError: yield from wasn't used with future