我正在使用HDP 3.X集群并使用spark_llap运行Spark sql,有没有办法使用hive.createTable创建外部hive表,因为Hortonworks网站中提供的示例是使用以下代码,而此代码将创建托管表,但我需要外部表。
hive.createTable("web_sales").ifNotExists().column("sold_time_sk", "bigint").column("ws_ship_date_sk", "bigint").create()
可以直接使用 Spark 会话来创建表。
示例 1 :
//drop the table if already created
spark.sql("drop table if exists my_table");
//create the table using the dataframe schema
spark.sql("create table my_table(....
") row format delimited fields terminated by '|' location '/my/hdfs/location'");
示例 2:
spark.sql('create table movies
(movieId int,title string,genres string)
row format delimited fields terminated by ","
stored as textfile') # in textfile format
spark.sql("create table ratings
(userId int,movieId int,rating float,timestamp string)
stored as ORC" )