无法使用Spark SQL创建表:创建Hive TABLE(AS SELECT)需要Hive支持; [英] Cannot Create table with spark SQL : Hive support is required to CREATE Hive TABLE (AS SELECT);

查看:747
本文介绍了无法使用Spark SQL创建表:创建Hive TABLE(AS SELECT)需要Hive支持;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在spark(scala)中创建一个表,然后从两个现有数据框中插入值,但是我得到了这个例子:

I'm trying to create a table in spark (scala) and then insert values from two existing dataframes but I got this exeption:

Exception in thread "main" org.apache.spark.sql.AnalysisException: Hive support is required to CREATE Hive TABLE (AS SELECT);;
'CreateTable `stat_type_predicate_percentage`, ErrorIfExists 

这是代码:

case class stat_type_predicate_percentage (type1: Option[String], predicate: Option[String], outin: Option[INT], percentage: Option[FLOAT])
object LoadFiles1 {

 def main(args: Array[String]) {
    val sc = new SparkContext("local[*]", "LoadFiles1") 
    val sqlContext = new org.apache.spark.sql.SQLContext(sc)
    val warehouseLocation = new File("spark-warehouse").getAbsolutePath
    val spark = SparkSession
        .builder()
        .appName("Spark Hive Example")
        .config("spark.sql.warehouse.dir", warehouseLocation)
        .enableHiveSupport()
        .getOrCreate()       

import sqlContext.implicits._    
import org.apache.spark.sql._       
import org.apache.spark.sql.Row;
import org.apache.spark.sql.types.{StructType,StructField,StringType};

//statistics 
val create = spark.sql("CREATE TABLE stat_type_predicate_percentage (type1 String, predicate String, outin INT, percentage FLOAT) USING hive")
val insert1 = spark.sql("INSERT INTO stat_type_predicate_percentage SELECT types.type, res.predicate, 0, 1.0*COUNT(subject)/(SELECT COUNT(subject) FROM MappingBasedProperties AS resinner WHERE res.predicate = resinner.predicate) FROM MappingBasedProperties AS res, MappingBasedTypes AS types WHERE res.subject = types.resource GROUP BY res.predicate,types.type")

val select = spark.sql("SELECT * from stat_type_predicate_percentage" ) 
  }

我应该如何解决?

推荐答案

---您必须在sparksession中启用蜂巢支持

--- Yo have to enable hive support in you sparksession

val spark = new SparkSession
    .Builder()
      .appName("JOB2")
      .master("local")
      .enableHiveSupport()
      .getOrCreate()

这篇关于无法使用Spark SQL创建表:创建Hive TABLE(AS SELECT)需要Hive支持;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆