デフォルトでは、データをロードするときに、すべてのカラムがストリング型と見なされます。スパークRDDのカラムのデータ型を変更し、それに照会します
temp.printSchema
|-- firstName: string (nullable = true)
|-- lastName: string (nullable = true)
|-- age: string (nullable = true)
|-- doj: date (nullable = true)
は一時テーブルを登録し、それ
temp.registerTempTable("temptable");
val temp1 = sqlContext.sql("select * from temptable")
temp1.show()
+---------+--------+---+----------+
|firstName|lastName|age| doj|
+---------+--------+---+----------+
| dileep| gog| 21|2016-01-01|
| avishek| ganguly| 21|2016-01-02|
| shreyas| t| 20|2016-01-03|
+---------+--------+---+----------+
val temp2 = sqlContext.sql("select * from temptable where doj > cast('2016-01-02' as date)")
に照会しかし、私がしようとしているときのように見えるRDD
のスキーマを更新した後
firstName,lastName,age,doj
dileep,gog,21,2016-01-01
avishek,ganguly,21,2016-01-02
shreyas,t,20,2016-01-03
:データは次のようになりますそれが私に与えている結果を見てください:
temp2: org.apache.spark.sql.DataFrame = [firstName: string, lastName: string, age: string, doj: date]
私は
temp2.show()
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
「スキーマを更新する」正確な方法は? –
var x = tempSchema.toArray; val y = StructField( "dob"、DateType、true); x.update(3、y) \t tempSchema = StructType(x); val temp = sqlContext.applySchema(tempSchemaRDD、tempSchema) ; – Dileep