【发布时间】:2019-05-15 01:17:14
【问题描述】:
我正在尝试创建一个数据管道,其中传入的数据存储到 parquet 中,我创建和外部 hive 表,用户可以查询 hive 表并检索数据。我能够保存 parquet 数据并直接检索它但是当我查询配置单元表它没有返回任何行。我做了以下测试设置
--创建外部蜂巢表 创建外部表 emp ( 身份证双倍, hir_dt 时间戳, 用户字符串 ) 存储为镶木地板 位置'/test/emp';
现在在一些数据上创建了数据框并保存到 parquet。
---创建数据框并插入数据
val employeeDf = Seq(("1", "2018-01-01","John"),("2","2018-12-01", "Adam")).toDF("id","hire_dt","user")
val schema = List(("id", "double"), ("hire_dt", "date"), ("user", "string"))
val newCols= schema.map ( x => col(x._1).cast(x._2))
val newDf = employeeDf.select(newCols:_*)
newDf.write.mode("append").parquet("/test/emp")
newDf.show
--read the contents directly from parquet
val sqlcontext=new org.apache.spark.sql.SQLContext(sc)
sqlcontext.read.parquet("/test/emp").show
+---+----------+----+
| id| hire_dt|user|
+---+----------+----+
|1.0|2018-01-01|John|
|2.0|2018-12-01|Adam|
+---+----------+----+
--read from the external hive table
spark.sql("select id,hire_dt,user from emp").show(false)
+---+-------+----+
|id |hire_dt|user|
+---+-------+----+
+---+-------+----+
如上所示,如果我直接从镶木地板而不是从蜂巢读取数据,我可以看到数据。问题是我在这里做错了什么?我做错了什么,蜂巢没有获取数据。我认为 msck repair 可能是一个原因,但如果我尝试执行 msck repair table 说 table not partitioned,我会出错。
【问题讨论】:
标签: apache-spark hive apache-spark-sql hiveql parquet