学习Spark遇到的问题

1.【报错】AttributeError: ‘SparkContext’ object has no attribute ‘setcheckpointDir’

本人传参:

    conf = SparkConf().setAppName("test").setMaster("local[*]")
    sc = SparkContext(conf=conf)
    # 1.告知spark,开启CheckPoint功能
    sc.setcheckpointDir("hdfs://node1:8020/output/ckp")

分析:SparkContext找不到setcheckpointDir方法,参数传参错误

解决:将setcheckpointDir改成setCheckpointDir,其中c字母大写。是因为两个方法的传参不同导致

2.【报错】Spark on Hive:Table or view ‘xxx’ already exists in database ‘default’

确认是有创建的table,但是show tables;的时候不展示

分析:没有建立Spark和Hive之间的连接

解决:建立连接

  1. 进入spark的配置(/export/server/spark/conf),编辑hive-site.xml文件

  
    hive.metastore.warehouse.dir
    /user/hive/warehouse
  
    hive.metastore.local
    false
  

  
    hive.metastore.uris
    thrift://node1:9083
  

  1. 进入hive的配置(/export/server/hive/conf),编辑hive-site.xml文件
  
    javax.jdo.option.ConnectionURL
    jdbc:mysql://node1:3306/hive?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8
  

  
    javax.jdo.option.ConnectionDriverName
    com.mysql.jdbc.Driver
  

  
    javax.jdo.option.ConnectionUserName
    root
  

  
    javax.jdo.option.ConnectionPassword
    你设置数据库的密码
  

  
    hive.server2.thrift.bind.host
    node1
  

  
    hive.metastore.uris
    thrift://node1:9083
  

  
    hive.metastore.event.db.notification.api.auth
    false
  


  1. 执行show tables;后可以看到创建的表格了

updateTime:2024-02-08

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/c618154ba3.html