2017-09-04 9 views
1

フィールドが大きいintタイプのフィールドのフィールドがstringタイプのpostgresqlのデータフレームに値を挿入しようとしています。文字列をBigIntデータフレームスパークスカラーに変換する

私は大きなものとしてキャストする方法を見つけませんでした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 

はビッグのIntを使用するすべてのヘルプはappreciated.IだろうscalaビッグのIntをサポートしていることを知っているが、どのように私はそれを行うことができますか?あなたはLongType使用する必要があり、大きな整数の場合

答えて

1

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

または

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

をまたDecimalType

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

または

を使用することができます3210
関連する問題