質問

I'd like to run statements like

SELECT date_add('2008-12-31', 1) FROM DUAL

Does Hive (running on Amazon EMR) have something similar?

役に立ちましたか?

他のヒント

Best solution is not to mention table name.

select 1+1;

Gives the result 2. But poor Hive need to spawn map reduce to find this!

To create a dual like table in hive where there is one column and one row you can do the following:

create table dual (x int);
insert into table dual select count(*)+1 as x from dual;

Test an expression:

select split('3,2,1','\\,') as my_new_array from dual;

Output:

["3","2","1"]

There is a nice working solution (well, workaround) available in the link, but it is slow as you might imagine.

The idea is that you create a table with a dummy field, create a text file whose content is just 'X', load that text into that table. Viola.

CREATE TABLE dual (dummy STRING);

load data local inpath '/path/to/textfile/dual.txt' overwrite into table dual;

SELECT date_add('2008-12-31', 1) from dual;

Quick Solution:

We can use existing table to achieve dual functionality by following query.

SELECT date_add('2008-12-31', 1) FROM <Any Existing Table> LIMIT 1

For example:

SELECT CONCAT('kbdjj','56454') AS a, null AS b FROM tbl_name LIMIT 1

Result

"limit 1" in query is used to avoid multiple occurrences of specified values (kbdjj56454,null).

Hive does support this function now and also does support many other dates function as well.

You can run query like below in hive, which will add days the provided date in first argument.

SELECT DATE_ADD('2019-03-01', 5);

Hive Date Functions

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top