【发布时间】:2018-08-10 12:24:37
【问题描述】:
我有下面的代码,它从我的本地驱动器中读取文件,但是我希望它从 hdfs 上的文件夹中读取文件。我想使用 sc.textfile 方法,但是我在正确初始化它时有点卡住了。你能帮忙吗?
session = SparkSession.builder.appName('myapp')
session = session.master ('local').getOrCreate()
sql_context = SQLContext(session.SparkContext)
sql_context.sql("SET spark.sql.autoBroadcastJoinThreshold=-1")
cwd=os.getcwd()
names=session.read.csv(os.path.join (cwd, 'local/path/to/file'), header=True, inferSchema=True).repartition(nameid)
classes=session.read.csv(os.path.join (cwd, 'local/path/to/file'), header=True, inferSchema=True).repartition(classid)
【问题讨论】: