-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReader.py
More file actions
35 lines (29 loc) · 967 Bytes
/
Reader.py
File metadata and controls
35 lines (29 loc) · 967 Bytes
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
31
32
33
34
35
'''
Created on Nov 17, 2020
@author: Vignesh.Asokan
'''
from pyspark.sql.types import *
from pyspark import HiveContext,SparkContext
from pyspark.sql.functions import *
from pyspark.sql.types import *
from pyspark.sql.window import *
class Reader(object):
def __init__(self, filePath,sparkSession):
'''
Constructor
'''
self.filePath=filePath
self.sparkSession=sparkSession
def read_csv(self,fileName):
print (self.filePath)
wandRawDf=self.sparkSession.read.csv(self.filePath+"/"+fileName,, header='true')
return wandRawDf
def read_df_data(self,sql):
df = self.sparkSession.sql(sql)
df.show()
return df
def prep_data(self, sqltext, tablename):
df = self.sparkSession.sql(sqltext)
df.registerTempTable(tablename)
print("Temporary spark table registered as %s" % tablename)
return df