2017-09-04 38 views
1

我試圖插入值到數據框中的字段是string鍵入postgresql數據庫中字段很大int類型。將字符串轉換爲BigInt數據框spark scala

我沒有找到如何將它們鑄造成大int。我用IntegerType之前,我沒有問題。但有了這個數據幀中投使我負整數

val sparkSession = SparkSession.builder.master("local").appName("spark session example").getOrCreate() 

    val cabArticleGold = sparkSession.sqlContext.load("jdbc", Map("url" -> "jdbc:oracle:thin:System/[email protected]//localhost:1521/XE", "dbtable" -> "IPTECH.TMP_ARTCAB")).select("CODEART", "CAB").limit(10) 
import sparkSession.sqlContext.implicits._ 
cabArticleGold.show() 
cabArticleGold.withColumn("CAB",'CAB.cast(IntegerType)).foreach(row=>println(row(1))) 

232524399 
-1613725482 
232524423 
-1613725465 
232524437 
-1191331072 
3486 
-1639094853 
232524461 
1564177573 

任何幫助使用大詮釋將appreciated.I知道scala支持大詮釋,但我該怎麼辦呢?

回答

1

對於大的整數,你應該使用LongType

cabArticleGold.withColumn("CAB", 'CAB.cast(LongType)) 

cabArticleGold.withColumn("CAB", 'CAB.cast("long")) 

您還可以使用DecimalType

cabArticleGold.withColumn("CAB", 'CAB.cast(DecimalType(38, 0))) 

cabArticleGold.withColumn("CAB", 'CAB.cast("decimal(38, 0)")) 
相關問題