hiveql

How to get the Date of the first day of a week given a time stamp in Hadoop Hive?

≯℡__Kan透↙ 提交于 2019-12-23 03:49:26
问题 Besides writing a custom UDF to support this issue, is there any known methods of achieving this? I'm currently using Hive 0.13. 回答1: date_sub(m.invitationdate,pmod(datediff(m.invitationdate,'1900-01-07'),7)) This expression gives the exact solution to my question. Regards, Boris 回答2: This is the easiest and the best solution for fetching 1st day of the week's date: For Current timstamp: select date_sub(from_unixtime(unix_timestamp()), cast(from_unixtime(unix_timestamp(), 'u') AS int)) ; For

Hive count tuple?

一笑奈何 提交于 2019-12-23 03:44:27
问题 I am pretty new with HiveQL and I am kinda stuck :S I have a table of the following schema. One column named res and three partitioned under partion_column named filed. create table results( res string) PARTITIONED BY (field STRING); I then imported data in this table insert overwrite table results PARTITION (field= 'title') SELECT explode(line) AS myNewCol FROM titles ; insert overwrite table results PARTITION (field= 'artist') SELECT explode(line) AS myNewCol FROM artist; insert overwrite

Hive CREATE EXTERNAL TABLE with parameterized LOCATION

别来无恙 提交于 2019-12-23 02:59:07
问题 This works as expected: DROP TABLE mytable; CREATE EXTERNAL TABLE mytable ( Dim1 STRING, Dim2 STRING, Dim3 STRING ) LOCATION 'hdfs:///user/myuser/data'; but this doesn't: set rootpath = 'hdfs:///user/myuser/data'; DROP TABLE mytable; CREATE EXTERNAL TABLE mytable ( Dim1 STRING, Dim2 STRING, Dim3 STRING ) LOCATION '${hiveconf:rootpath}'; It fails with the following error (Hive 0.9.0): FAILED: Parse Error: line 9:11 mismatched input 'hdfs' expecting EOF near '''' Am I doing something wrong, or

Creating and sum the values of variables in HiveQL

大兔子大兔子 提交于 2019-12-23 02:47:14
问题 In one of my use cases, I am trying to migrate traditional SQL based warehousing application into Hive. Neither I am an expert in SQL not in HiveQL. However, I have had decent success in creating tables and importing csv into hive tables. But then I hit a road block while replicating SQL based analytics query in Hive QL. In one of the analytics algorithms, we need to create multiple variables and calculate the sum of those variables, like below var x = query1 var y = query2 var z = query3 var

Calculate time difference between two columns of string type in hive without changing the data type string

天大地大妈咪最大 提交于 2019-12-22 18:06:51
问题 I am trying to calculate the time difference between two columns of a row which are of string data type. If the time difference between them is less than 2 hours then select the first column of that row else if the time difference is greater than 2 hours then select the second column of that row. It can be done by converting the columns to datetime format, but I want the result to be in string only. How can I do that? The data looks like this: col1(string type) 2018-07-16 02:23:00 2018-07-26

Error in Hive : Underlying error: org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException: One or more arguments are expected

一曲冷凌霜 提交于 2019-12-22 10:06:33
问题 I am trying to translate some PL/SQL script in hive, and i faced an error with one HiveQL script. The error is this one : FAILED: SemanticException Failed to breakup Windowing invocations into Groups. At least 1 group must only depend on input columns. Also check for circular dependencies. Underlying error: org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException: One or more arguments are expected. I think that the error is coming from this part of script : SELECT mag.co_magasin, dem.id

Hive function to replace comma in column value

[亡魂溺海] 提交于 2019-12-22 09:48:08
问题 I have a hive table which has String column having value as 12,345. Is there any way hive function which can remove comma during insertion in this hive table ? 回答1: You can use regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT) which is a function in Hive. So if you are moving the data from a table that contains the comma to a new table you will use : insert into table NEW select regexp_replace(commaColumn,',','') from OLD; 回答2: Hive does have split function. which can

How to reset textinputformat.record.delimiter to its default value within hive cli / beeline?

冷暖自知 提交于 2019-12-22 05:57:17
问题 Setting textinputformat.record.delimiter to a non-default value, is useful for loading multi-row text, as shown in the demo below. However, I'm failing to set this parameter back to its default value without exiting the cli and reopen it. None of the following options worked (nor some other trials) set textinputformat.record.delimiter='\n'; set textinputformat.record.delimiter='\r'; set textinputformat.record.delimiter='\r\n'; set textinputformat.record.delimiter=' '; reset; Any thought?

How to extract selected values from json string in Hive

我们两清 提交于 2019-12-22 05:23:28
问题 I am running a simple query in Hive that produces the following output (with a few other additional columns. |------|-----------------------------------------------------------| | col1 | col2 | |------|-----------------------------------------------------------| | A | {"variable1":123,"variable2":456,"variable3":789} | |------|-----------------------------------------------------------| | B | {"variable1":222,"variable2":333,"variable3":444} | -------------------------------------------------

Hive: Is it possible to rename an existing hive database?

淺唱寂寞╮ 提交于 2019-12-22 04:51:05
问题 There seems to be a similar requirement at: https://issues.apache.org/jira/browse/HIVE-4847 However, when I tried the proposed syntax from the issue's Description - 'ALTER DATABASE dbname RENAME TO newdbname', it gave me the following error: ALTER DATABASE testdb RENAME TO testdb1; NoViableAltException(26@[]) at org.apache.hadoop.hive.ql.parse.HiveParser.alterDatabaseStatementSuffix(HiveParser.java:7881) at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatement(HiveParser.java:6588) at org