-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspark_resource.py
30 lines (24 loc) · 1.04 KB
/
spark_resource.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# coding: utf-8
from spark_sql import SparkSql
class SparkResource(object):
def __init__(self):
self.spark_sql = SparkSql()
self.question_df = self.spark_sql.load_table_df('question')
self.paper_sub_q_df = self.spark_sql.load_table_df(
'paper_subtype_question'
)
self.question_cog_map_df = self.spark_sql.load_table_df(
'question_cognition_map'
)
def init_temp_view(self):
"""
SQL版本先加载表用的,但是SQL版本速度一般,先不调用
:return:
"""
# 读取表的dataframe
question_df = self.spark_sql.load_table_df('question')
question_df.createOrReplaceTempView("tmp_question")
sub_q_df = self.spark_sql.load_table_df('paper_subtype_question')
sub_q_df.createOrReplaceTempView("tmp_paper_subtype_question")
cog_map_df = self.spark_sql.load_table_df('question_cognition_map')
cog_map_df.createOrReplaceTempView("tmp_question_cognition_map")