は私のコードであるためにデータフレーム空白のレコードを置き換える - >スパークScalaの私はここに「0」</p> <p>私のデータフレームのフィールドの空白のレコードを交換する必要が「0」
import sqlContext.implicits._
case class CInspections (business_id:Int, score:String, date:String, type1:String)
val baseDir = "/FileStore/tables/484qrxx21488929011080/"
val raw_inspections = sc.textFile (s"$baseDir/inspections_plus.txt")
val raw_inspectionsmap = raw_inspections.map (line => line.split ("\t"))
val raw_inspectionsRDD = raw_inspectionsmap.map (raw_inspections => CInspections (raw_inspections(0).toInt,raw_inspections(1), raw_inspections(2),raw_inspections(3)))
val raw_inspectionsDF = raw_inspectionsRDD.toDF
raw_inspectionsDF.createOrReplaceTempView ("Inspections")
raw_inspectionsDF.printSchema
raw_inspectionsDF.show()
私はケースクラスを使用していますし、 Dataframeに変換します。しかし、私はいくつかの操作を実行し、ソートする必要があるので、Intとして "スコア"が必要です。 しかし、それをスコアとして宣言すれば、Intは空白の値にエラーが発生します。
java.lang.NumberFormatException:入力文字列の場合:以下のクエリのために、それは一種の文字列としてint型と間違った結果に
sqlContext.sql("""select raw_inspectionsDF.score from raw_inspectionsDF where score <>"" order by score""").show()
+-----+
|score|
+-----+
| 100|
| 100|
| 100|
+-----+
を与えていないので、「」
+-----------+-----+--------+--------------------+
|business_id|score| date| type1|
+-----------+-----+--------+--------------------+
| 10| |20140807|Reinspection/Foll...|
| 10| 94|20140729|Routine - Unsched...|
| 10| |20140124|Reinspection/Foll...|
| 10| 92|20140114|Routine - Unsched...|
| 10| 98|20121114|Routine - Unsched...|
| 10| |20120920|Reinspection/Foll...|
| 17| |20140425|Reinspection/Foll...|
+-----------+-----+--------+--------------------+
私はint型としてフィールドをスコア必要
はあなたの返事のためにどうもありがとうございます!今働いている。 :) –
sqlContext.sqlの中に以下のようにsqlクエリを書くことはできますか?私は以下のクエリでエラーが発生しています - > sqlContext.sql( "" "select" CBusinesses.BUSINESS_ID、CBusinesses.name、CBusinesses.address、CBusinesses.city、CBusinesses.postal_code、CBusinesses.latitude、CBusinesses.longitude、Inspections_notnull.score " –
は本当に答えを知ってはいけないInspections_notnull.score <> 0とCBusinesses.BUSINESS_ID = Inspections_notnull.BUSINESS_ID """:入力文字列の場合).SHOW() はjava.lang.NumberFormatException" CBusinesses、Inspections_notnullからしかし、あなたは2つのテーブルを結合しようとしているようです。 – Psidom