Addys
Addys

Reputation: 2499

Hive CREATE EXTERNAL TABLE with parameterized LOCATION

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 is this a known issue/limitation? Are there any suggestions for workarounds?

Upvotes: 1

Views: 7341

Answers (2)

Raunak Jhawar
Raunak Jhawar

Reputation: 1651

You can also use an environment variable which we often use in the create table DDL's. It can be referred as ${env:variable_name}

Upvotes: 0

Michael Hausenblas
Michael Hausenblas

Reputation: 14011

I think it should read LOCATION ${hiveconf:rootpath}.

Upvotes: 2

Related Questions