hiveql

Month in MM using Month() in Hive

我是研究僧i 提交于 2019-12-05 20:33:32
Select * from concat(YEAR(DATE_SUB(MAX(Column_name),60),MONTH(DATE_SUB(MAX(Column_name),60),-01) The month() yields only single digit for months until September i.e Jan returns 1 instead of 01 . Need help in handling this. I am using this output to feed to another SELECT query using TO_DATE . month() function returns integer, that is why there is no leading zero. You can use lpad(month,2,0) function to format month: hive> select lpad(month('2017-09-01'),2,0); OK 09 Time taken: 0.124 seconds, Fetched: 1 row(s) hive> select lpad(month('2017-10-01'),2,0); OK 10 Time taken: 0.433 seconds, Fetched:

Hive UDF for selecting all except some columns

别等时光非礼了梦想. 提交于 2019-12-05 18:15:35
问题 The common query building pattern in HiveQL (and SQL in general) is to either select all columns ( SELECT * ) or an explicitly-specified set of columns ( SELECT A, B, C ). SQL has no built-in mechanism for selecting all but a specified set of columns. There are various mechanisms for excluding some columns as outlined in this SO question but none apply naturally to HiveQL. (For example, the idea to create a temporary table with SELECT * then ALTER TABLE DROP some of its columns would wreak

MismatchedTokenException on hive create table query

ぐ巨炮叔叔 提交于 2019-12-05 17:24:58
I'm trying to create a Hive table with the following query: CREATE TABLE IF NOT EXISTS BXDataSet (ISBN STRING, BookTitle STRING, BookAuthor STRING, YearOfPublication STRING, Publisher STRING, ImageURLS STRING, ImageURLM STRING, ImageURLL STRING) COMMENT 'BX-Books Table' ROW FORMAT DELIMITED FIELDS TERMINATED BY ';' LINE TERMINATED BY '\n' STORED AS TEXTFILE; How when I submitted to Hive I got the following exception: MismatchedTokenException(-1!=301) at org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:617) at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer

Hive error: parseexception missing EOF

旧街凉风 提交于 2019-12-05 16:54:34
问题 I am not sure what I am doing wrong here: hive> CREATE TABLE default.testtbl(int1 INT,string1 STRING) stored as orc tblproperties ("orc.compress"="NONE") LOCATION "/user/hive/test_table"; FAILED: ParseException line 1:107 missing EOF at 'LOCATION' near ')' while the following query works perfectly fine: hive> CREATE TABLE default.testtbl(int1 INT,string1 STRING) stored as orc tblproperties ("orc.compress"="NONE"); OK Time taken: 0.106 seconds Am I missing something here. Any pointers will

Creating a rank that resets on a specific value of a column

橙三吉。 提交于 2019-12-05 15:07:18
My current data looks like this (note that it is sorted on datetime): +----------------+---------------------+---------+ | CustomerNumber | Date | Channel | +----------------+---------------------+---------+ | 120584446 | 2015-05-22 21:16:05 | A | | 120584446 | 2015-05-25 18:04:16 | A | | 120584446 | 2015-05-25 18:05:25 | B | | 120584446 | 2015-05-28 20:35:09 | A | | 120584446 | 2015-05-28 20:36:01 | A | | 120584446 | 2015-05-28 20:37:02 | B | | 120584446 | 2015-05-29 13:39:00 | B | +----------------+---------------------+---------+ I want to create a rank in hive that splits on cutomer number

Hive - Split delimited columns over multiple rows, select based on position

烂漫一生 提交于 2019-12-05 14:37:09
I'm Looking for a way to split the column based on comma delimited data. Below is my dataset id col1 col2 1 5,6 7,8 I want to get the result id col1 col2 1 5 7 1 6 8 The position of the index should match because I need to fetch results accordingly. I tried the below query but it returns the cartesian product. Query : SELECT col3, col4 FROM test ext lateral VIEW explode(split(col1,'\002')) col1 AS col3 lateral VIEW explode(split(col2,'\002')) col2 AS col4 Result : id col1 col2 1 5 7 1 5 8 1 6 7 1 6 8 You can use posexplode() to create position index columns for your split arrays. Then, select

Get the sysdate -1 in Hive

风格不统一 提交于 2019-12-05 10:34:56
Is there any way to get the current date -1 in Hive means yesterdays date always? And in this format- 20120805 ? I can run my query like this to get the data for yesterday's date as today is Aug 6th - select * from table1 where dt = '20120805'; But when I tried doing this way with date_sub function to get the yesterday's date as the below table is partitioned on date(dt) column. select * from table1 where dt = date_sub(TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP(), 'yyyyMMdd')) , 1) limit 10; It is looking for the data in all the partitions? Why? Something wrong I am doing in my query? How I can make

How do you insert data into complex data type “Struct” in Hive

Deadly 提交于 2019-12-05 10:19:41
I'm completely new to Hive and Stack Overflow. I'm trying to create a table with complex data type "STRUCT" and then populate it using INSERT INTO TABLE in Hive. I'm using the following code: CREATE TABLE struct_test ( address STRUCT< houseno: STRING ,streetname: STRING ,town: STRING ,postcode: STRING > ); INSERT INTO TABLE struct_test SELECT NAMED_STRUCT('123', 'GoldStreet', London', W1a9JF') AS address FROM dummy_table LIMIT 1; I get the following error: Error while compiling statement: FAILED: semanticException [Error 10044]: Cannot insert into target because column number type are

How to list all hive databases being in use or created so far?

孤街浪徒 提交于 2019-12-05 09:55:12
问题 Similar to SHOW TABLES command, do we have any such command to list all databases created so far? 回答1: This page mentions the command SHOW DATABASES . From the manual: SHOW (DATABASES|SCHEMAS) [LIKE identifier_with_wildcards]; SHOW DATABASES lists all of the databases defined in the metastore. The optional LIKE clause allows the list of databases to be filtered using a regular expression. Wildcards in the regular expression can only be '' for any character(s) or '|' for a choice. Examples are

Transferring hive table from one database to another

安稳与你 提交于 2019-12-05 08:52:34
问题 I need to move a hive table from one database to another. How can I do that? 回答1: Since 0.14, you can use following statement to move table from one database to another in the same metastore: use old_database; alter table table_a rename to new_database.table_a The above statements will also move the table data on hdfs if table_a is a managed table. 回答2: create external table new_db.table like old_db.table location '(path of file in hdfs file)'; if you have partition in table then you have to