Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Hive recursively descend into subdirectories without partitions or editing hive-site.xml?

I have some web server logs that I'd like to query with Hive. The directory structure, in HDFS, looks like this:

/data/access/web1/2014/09
/data/access/web1/2014/09/access-20140901.log
[... etc ...]
/data/access/web1/2014/10
/data/access/web1/2014/10/access-20141001.log
[... etc ...]
/data/access/web2/2014/09
/data/access/web2/2014/09/access-20140901.log
[... etc ...]
/data/access/web2/2014/10
/data/access/web2/2014/10/access-20141001.log
[... etc ...]

I'm able to create an external table:

CREATE EXTERNAL TABLE access(
  host STRING,
  identity STRING,
  user STRING,
  time STRING,
  request STRING,
  status STRING,
  size STRING,
  referer STRING,
  agent STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
  "input.regex" = "([^ ]*) ([^ ]*) ([^ ]*) (-|\\[[^\\]]*\\]) ([^ \"]*|\"[^\"]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\"[^\"]*\") ([^ \"]*|\"[^\"]*\"))?",
  "output.format.string" = "%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s")
LOCATION '/data/access/'

... though Hive doesn't descend into the subfolders unless I run the following commands before running the Hive query:

set hive.input.dir.recursive=true;
set hive.mapred.supports.subdirectories=true;
set hive.supports.subdirectories=true;
set mapred.input.dir.recursive=true;

I've seen other posts set these properties at the table-level (e.g. Issue creating Hive External table using tblproperties):

TBLPROPERTIES ("hive.input.dir.recursive" = "TRUE", 
    "hive.mapred.supports.subdirectories" = "TRUE",
    "hive.supports.subdirectories" = "TRUE", 
    "mapred.input.dir.recursive" = "TRUE");

Unfortunately, this didn't work for me: the table doesn't return any records when I query it. I understand it's possible to set these properties in hive-site.xml, but I'd rather not make any changes that might impact other users if I don't need to.

Q) is there a way to create a table that descends into the subdirectories without using partitions, making site-wide changes, or running those 4 commands every time?

like image 339
Alex Woolford Avatar asked Nov 05 '14 21:11

Alex Woolford


2 Answers

Using Hive in HDInsight, I set the following properties before I create my external table in the Hive query and it works for me.

SET hive.mapred.supports.subdirectories=TRUE;
SET mapred.input.dir.recursive=TRUE;
like image 118
Chris Karpyszyn Avatar answered Oct 06 '22 00:10

Chris Karpyszyn


If you are using ambari the set the following properties to hive advanced config inside custom hive-site.xml.

**- SET hive.input.dir.recursive=TRUE

SET hive.mapred.supports.subdirectories=TRUE

SET hive.supports.subdirectories=TRUE

SET mapred.input.dir.recursive=TRUE**

And then restart the affected services. This will read all the data recursively.

like image 29
Avinav Mishra Avatar answered Oct 05 '22 23:10

Avinav Mishra