val df_mysql = sqlContext.read.format("jdbc").option("url", "jdbc:mysql://dev-db/finance").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "(select a.*,b.productBaseDetailSeq,b.optionSrl,b.paymentSrl,b.amount,b.salesSupplyFee,b.salesSupplyFeeVat,b.paymentSupplyFee,b.paymentSupplyFeeVat,b.count from product_base a join product_base_detail b on a.productBaseSeq=b.productBaseSeq) as prbase").option("user", "ididid").option("password", "xxxxx").load()
df_mysql.registerTempTable("prbase")
val amountByOption = sqlContext.sql("select optionSrl, amountType, sum(amount) amount from prbase group by optionSrl, amountType")
amountByOption.show()
amountByOption.write.parquet("prbase.amountByOption.par")
# loading parquet
val amountByOption = sqlContext.parquetFile("prbase.amountByOption.par")
amountByOption.registerTempTable("amounts")
val amtByType = sqlContext.sql("select amountType, sum(amount) from amounts group by amountType")
amtByType.show()