You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by mattl156 <ma...@gmail.com> on 2018/06/20 04:39:52 UTC
[Spark SQL]: How to read Hive tables with Sub directories - is this
supported?
Hello,
We have a number of Hive tables (non partitioned) that are populated with
subdirectories. (result of tez execution engine union queries)
E.g. Table location: “s3://table1/” With the actual data residing in:
s3://table1/1/data1
s3://table1/2/data2
s3://table1/3/data3
When using SparkSession (sql/hiveContext has the same behavior) and
spark.sql to query the data, no records are displayed due to these
subdirectories.
e.g
val df = spark.sql("select * from db.table1").show()
I’ve tried a number of setConf properties e.g.
spark.hive.mapred.supports.subdirectories=true,
mapreduce.input.fileinputformat.input.dir.recursive=true but it does not
look like any of these properties are supported.
Has anyone run into similar problems or ways to resolve it? Our current
alternatives are reading the input path directory directly e.g.:
spark.read.csv("s3://bucket-name/table1/bullseye_segments/*/*")
But this requires prior knowledge of the path or an extra step to determine
it.
Thanks,
Matt
--
Sent from: http://apache-spark-user-list.1001560.n3.nabble.com/
---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscribe@spark.apache.org
Re: [Spark SQL]: How to read Hive tables with Sub directories - is
this supported?
Posted by Daniel Pires <dp...@gilt.com>.
Thanks for coming back with the solution!
Sorry my suggestion did not help
Daniel
On Wed, 20 Jun 2018, 21:46 mattl156, <ma...@gmail.com> wrote:
> Alright so I figured it out.
>
> When reading from and writing to Hive metastore Parquet tables, Spark SQL
> will try to use its own Parquet support instead of Hive SerDe for better
> performance.
>
> And so setting things like the below have no impact.
>
> sqlContext.setConf("mapred.input.dir.recursive","true");
> sqlContext.setConf("spark.sql.parquet.binaryAsString", "true")
>
> The Default Parquet Support also does not read recursive directories.
>
> The using of spark default serde vs hive serde is controlled by:
> spark.sql.hive.convertMetastoreParquet configuration, and is turned on by
> default
>
> After setting this to false "
> sqlContext.setConf("spark.sql.hive.convertMetastoreParquet", "false") "
>
> I can set the other 2 properties above and query my parquet table with sub
> directories.
>
> -Matt
>
>
>
>
>
> --
> Sent from:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__apache-2Dspark-2Duser-2Dlist.1001560.n3.nabble.com_&d=DwICAg&c=T4LuzJg_R6QwRnqJoo4xTCUXoKbdWTdhZj7r4OYEklY&r=jiwJwiY6eWNA-UciMYI1Iw&m=vDKanQpl6_Oxjiexu1ybjELUTvIsAHVt69RaZ9GKFx4&s=g6UtmolMtdTJCjOWQgptVrav_W7Ona0LD3sHAWrVsw4&e=
>
> ---------------------------------------------------------------------
> To unsubscribe e-mail: user-unsubscribe@spark.apache.org
>
>
Re: [Spark SQL]: How to read Hive tables with Sub directories - is
this supported?
Posted by mattl156 <ma...@gmail.com>.
Alright so I figured it out.
When reading from and writing to Hive metastore Parquet tables, Spark SQL
will try to use its own Parquet support instead of Hive SerDe for better
performance.
And so setting things like the below have no impact.
sqlContext.setConf("mapred.input.dir.recursive","true");
sqlContext.setConf("spark.sql.parquet.binaryAsString", "true")
The Default Parquet Support also does not read recursive directories.
The using of spark default serde vs hive serde is controlled by:
spark.sql.hive.convertMetastoreParquet configuration, and is turned on by
default
After setting this to false "
sqlContext.setConf("spark.sql.hive.convertMetastoreParquet", "false") "
I can set the other 2 properties above and query my parquet table with sub
directories.
-Matt
--
Sent from: http://apache-spark-user-list.1001560.n3.nabble.com/
---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscribe@spark.apache.org
Re: [Spark SQL]: How to read Hive tables with Sub directories - is
this supported?
Posted by mattl156 <ma...@gmail.com>.
Thanks. Unfortunately I dont have control over how data is inserted and the
table is not partitioned.
The reason the sub directories are being created is because when Tez does an
INSERT into a table from a UNION query it creates sub directories so that it
can write in parallel.
I've also realized that its only with Parquet ... csv works fine
--
Sent from: http://apache-spark-user-list.1001560.n3.nabble.com/
---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscribe@spark.apache.org
Re: [Spark SQL]: How to read Hive tables with Sub directories - is
this supported?
Posted by Daniel Pires <dp...@gilt.com>.
Hi Matt,
What I tend to do is partition by date in the following way:
s3://data-lake/pipeline1/extract_year=2018/extract_month=06/extract_day=20/file1.json
See the pattern is key=value for physical partitions
When you read that like this:
spark.read.json("s3://data-lake/pipeline1/")
It will bring you the data with the schema inferred from the JSON + 3
fields : extract_year, extract_month, extract_day
I was looking for the documentation that described this way of partitioning
but could not find it, I can reply with the link once I do
Hope that helps,
---
Daniel Mateus Pires
Data Engineer
Hudson's Bay Company
On Wed, Jun 20, 2018 at 5:39 AM, mattl156 <ma...@gmail.com> wrote:
> Hello,
>
>
>
> We have a number of Hive tables (non partitioned) that are populated with
> subdirectories. (result of tez execution engine union queries)
>
>
>
> E.g. Table location: “s3://table1/” With the actual data residing in:
>
>
>
> s3://table1/1/data1
>
> s3://table1/2/data2
>
> s3://table1/3/data3
>
>
>
> When using SparkSession (sql/hiveContext has the same behavior) and
> spark.sql to query the data, no records are displayed due to these
> subdirectories.
>
>
>
> e.g
>
> val df = spark.sql("select * from db.table1").show()
>
>
>
> I’ve tried a number of setConf properties e.g.
> spark.hive.mapred.supports.subdirectories=true,
> mapreduce.input.fileinputformat.input.dir.recursive=true but it does not
> look like any of these properties are supported.
>
>
>
> Has anyone run into similar problems or ways to resolve it? Our current
> alternatives are reading the input path directory directly e.g.:
>
>
>
>
> spark.read.csv("s3://bucket-name/table1/bullseye_segments/*/*")
>
>
> But this requires prior knowledge of the path or an extra step to determine
> it.
>
>
> Thanks,
>
> Matt
>
>
>
>
>
> --
> Sent from: https://urldefense.proofpoint.com/v2/url?u=http-3A__apache-
> 2Dspark-2Duser-2Dlist.1001560.n3.nabble.com_&d=DwIFaQ&c=T4LuzJg_
> R6QwRnqJoo4xTCUXoKbdWTdhZj7r4OYEklY&r=jiwJwiY6eWNA-
> UciMYI1Iw&m=SDQ6bALTDqRwG-TQZ1-xlEaHQDddyTn38FcaOmp8dDk&s=
> ZvFFhUgiKT1JC1NMH6hI44Gx8pp3OwXHcrhbTUISvHg&e=
>
> ---------------------------------------------------------------------
> To unsubscribe e-mail: user-unsubscribe@spark.apache.org
>
>