当前位置:   article > 正文

Pycharm通过SFTP远程连接Spark_pycharm连接spark集群

pycharm连接spark集群

参考:https://daniel.blog.csdn.net/article/details/107415130

1.添加SFTP连接

选择 Tools =>  Deploment => Configuration。

 2. 在Deployment界面中,设置Connection、Mapping的配置。

Connection 配置:

 Mapping配置:

 2.添加SSH Interpreter

 3.Project Structure

 4.启动设置

点击右上角的三角形,然后删除working directory里面的路径,并更改Environment variables。

 5.WordCount.py代码

  1. # coding=UTF-8
  2. import sys
  3. # 设置服务器上py4j库所在的路径
  4. sys.path.append('/export/servers/spark/python/lib/py4j-0.10.4-src.zip')
  5. from pyspark.sql import SparkSession
  6. if __name__ == "__main__":
  7. # 如果spark配置了yarn集群,这里的master可以修改为yarn
  8. spark = SparkSession.builder \
  9. .master('local') \
  10. .appName('Pycharm Connection') \
  11. .getOrCreate()
  12. # wordcount操作,这里文件为hdfs的路径
  13. words = spark.sparkContext \
  14. .textFile("hdfs:/data/words") \
  15. .flatMap(lambda line: line.split(" ")) \
  16. .map(lambda word: (word, 1)) \
  17. .reduceByKey(lambda a, b: a + b) \
  18. .collect()
  19. for word in words:
  20. print(word)
  21. spark.stop()
  22. # spark = SparkSession.builder\
  23. # .master('local[6]')\
  24. # .appName('Course_Test') \
  25. # .config("hive.metastore.uris", "thrift://node03:9083")\
  26. # .enableHiveSupport()\
  27. # .getOrCreate()
  28. # # 方式一:
  29. # sql = "select * from course.SCORE"
  30. # spark.sql("use course")
  31. # queryResult = spark.sql(sql)
  32. # spark.sql("drop table if exists course.score_test")
  33. # queryResult.write.format("hive").mode("overwrite").saveAsTable('course.score_test')
  34. # spark.stop()
  35. # 方式二:
  36. # sql = "select * from course.SCORE"
  37. # queryResult = spark.sql(sql)
  38. # queryResult.registerTempTable('temp_table')
  39. # spark.sql("truncate table course.score_test")
  40. # spark.sql("insert into course.score_test select * from temp_table")
  41. # spark.stop()

6.右键 => Run "WordCount"

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/190253
推荐阅读
相关标签
  

闽ICP备14008679号