我已經寫了下面的Scala代碼來創建拼花文件無法從拼花文件加載數據蜂巢外部表
scala> case class Person(name:String,age:Int,sex:String)
defined class Person
scala> val data = Seq(Person("jack",25,"m"),Person("john",26,"m"),Person("anu",27,"f"))
data: Seq[Person] = List(Person(jack,25,m), Person(john,26,m), Person(anu,27,f))
scala> import sqlContext.implicits._
import sqlContext.implicits._
scala> import org.apache.spark.sql.SaveMode
import org.apache.spark.sql.SaveMode
scala> df.select("name","age","sex").write.format("parquet").mode("overwrite").save("sparksqloutput/person")
HDFS狀態:
[[email protected] ~]$ hadoop fs -ls sparksqloutput/person
Found 4 items
-rw-r--r-- 1 cloudera cloudera 0 2017-08-14 23:03 sparksqloutput/person/_SUCCESS
-rw-r--r-- 1 cloudera cloudera 394 2017-08-14 23:03 sparksqloutput/person/_common_metadata
-rw-r--r-- 1 cloudera cloudera 721 2017-08-14 23:03 sparksqloutput/person/_metadata
-rw-r--r-- 1 cloudera cloudera 773 2017-08-14 23:03 sparksqloutput/person/part-r-00000-2dd2f334-1985-42d6-9dbf-16b0a51e53a8.gz.parquet
然後我就用創建的外部蜂巢表命令如下
hive> CREATE EXTERNAL TABLE person (name STRING,age INT,sex STRING) STORED AS PARQUET LOCATION '/sparksqlouput/person/';
OK
Time taken: 0.174 seconds
hive> select * from person
> ;
OK
Time taken: 0.125 seconds
但是,當上面運行選擇查詢沒有行返回。請有人幫忙。
創建dataframe df的scala語句缺少問題。你可以租賃嗎? – Shubhangi