我正在尝试在pyspark数据帧(2.0.0)上定义sql视图并获取“Table or View Not found”之类的错误。我正在做的事情:1。创建一个空的数据帧2.将来自不同位置的数据加载到临时数据帧中3.将临时数据帧附加到主数据帧(空数据帧)4。在数据帧上定义一个sql视图(这是先前空了。)
spark = SparkSession.builder.config(conf=SparkConf()).appName("mydailyjob").getOrCreate()
sc = spark.sparkContext
schema = StructType([StructField('vdna_id', StringType(), True),
StructField('miq_id', LongType(), True),
StructField('tags', IntegerType(), True),
StructField('dateserial', DateType(), True),
StructField('date_time', TimestampType(), True),
StructField('survey_id', StringType(), True),
StructField('ip', StringType(), True)])
brandsurvey_feed = sqlContext.createDataFrame(sc.emptyRDD(), schema)
# load brandsurvey feed data for each date in date_list
for loc in all_loc:
# load file from different location
bs_tmp = spark.read.csv(loc, schema=schema, sep='\t', header=True)
brandsurvey_feed = brandsurvey_feed.union(bs_tmp)
brandsurvey_feed.createOrReplaceTempView("brandsurvey_feed")
print(spark.sql("select * from brandsurvey_feed").show())
答案 0 :(得分:0)