I sqooped data from Oracle and the table had a column with CLOB DataType, I made it String to get the data in HDFS. Now I have to dismantle the CLOB Data and create a separate table for that in Hive.
I have the HDFS file in txt format. I can segregate the CLOB data and be hoping to make DataFrame for CLOB
The CLOB is in the following format :
[name] Bob [Age] 21 [City] London [work] No,
[name] Steve [Age] 51 [City] London [work] Yes,
.....
around a million rows like this
sc.setLogLevel("WARN")
log_txt=sc.textFile("/path/to/data/sample_data.txt")
header = log_txt.first()
log_txt = log_txt.filter(lambda line: line != header)
log_txt.take(10)
[u'0\\tdog\\t20160906182001\\tgoogle.com', u'1\\tcat\\t20151231120504\\tgoogle.com']
temp_var = log_txt.map(lambda k: k.split("\\t"))
log_df=temp_var.toDF(header.split("\\t"))
log_df = log_df.withColumn("field1Int", log_df["field1"].cast(IntegerType()))
log_df = log_df.withColumn("field3TimeStamp", log_df["field1"].cast(TimestampType()))
log_df.schema
StructType(List(StructField(field1,StringType,true),StructField(field2,StringType,true),StructField(field3,StringType,true),StructField(field4,StringType,true),StructField(field1Int,IntegerType,true),StructField(field3TimeStamp,TimestampType,true)))
This is how I have created DataFrame.
I need your help to figure out how to dismantle the CLOB, Which is in the form of String Data Type. and Create a table on top of that.
After dismantling, I expect the Table to have following Columns like:
+---------+---------------+----------+-----+
|Name |Age | City | Work|
+---------+---------------+----------+-----+
| Bob| 21 |London | No |
| Steve| 51 |London |Yes |
+---------+---------------+----------+-----+
Any help would be appreciated.