[spark] requirement failed: Currently correlation calculation for columns with dataType string not supported. 해결하기;
scala 2019. 2. 25. 17:20Spark에서 DataFrame으로 장난치다가
requirement failed: Currently correlation calculation for columns with dataType string not supported.라는 에러를 만날 수 있다.
이는 데이터 타입을 inferScheme을 통해 추론하는데 데이터 타입이 Long/Int로 변환되야 하는데 String 타입으로 변환된 컬럼 데이터를 corr라는 sql 함수로 계산하다가 에러가 발생한 것이다.
이럴 때는 명시적으로 StructType을 사용해 스키마를 지원하는 것이 좋다.
import org.apache.spark.sql.types.{StructType, StructField, StringType, LongType}
val myManualSchema = StructType(Array(
StructField("InvoiceNo", LongType, true),
StructField("StockCode", StringType, true),
StructField("Description", StringType, true),
StructField("Quantity", LongType, true),
StructField("InvoiceDate", StringType, true),
StructField("UnitPrice", LongType, true),
StructField("CustomerID", StringType, true),
StructField("Country", StringType, true)
))
val df = spark.read.format("csv")
.option("header", true)
.schema(myManualSchema)
.load("origin-source/data/retail-data/by-day/2010-12-01.csv")
'scala' 카테고리의 다른 글
[spark] Malformed class name 에러 해결하기 (0) | 2019.02.27 |
---|---|
[spark] monotonically_increasing_id 예시 (0) | 2019.02.25 |
[spark] .java.net.BindException: Can't assign requested address: Service 'sparkDriver' failed after 16 retries! (0) | 2019.02.22 |
[spark] Unable to find encoder for type XXX 해결하기 (0) | 2019.02.20 |
[scala] scala-guice/quill를 사용한 inject 예제 (0) | 2019.02.04 |