기본적으로 데이터를로드 할 때 모든 열은 문자열 유형으로 간주됩니다. 내가하려고 할 때스파크의 열의 데이터 유형을 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