Dea*_*nLa 4 hive apache-spark parquet apache-spark-sql apache-spark-ml
我有一个 Spark DataFrame,其中一列作为Vector类型。当我在它上面创建一个蜂巢表时,我不知道它相当于哪种类型
CREATE EXTERNAL TABLE mix (
topicdist ARRAY<DOUBLE>
)
STORED AS PARQUET
LOCATION 's3://path/to/file.parquet'
Run Code Online (Sandbox Code Playgroud)
表创建似乎工作并返回 OK,但是当我尝试
select topicdist from mix limit 1
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
Failed with exception java.io.IOException:java.lang.RuntimeException: Unknown hive type info array<double> when searching for field type
Run Code Online (Sandbox Code Playgroud)
Vector 是 Spark 用户定义的类型,它在内部存储为
StructType(Seq(
StructField("type", ShortType, true),
StructField("size",IntegerType, true),
StructField("indices", ArrayType(IntegerType, true), true),
StructField("values",ArrayType(DoubleType, true), true)
))
Run Code Online (Sandbox Code Playgroud)
所以你需要:
CREATE EXTERNAL TABLE mix (
topicdist struct<type:tinyint,size:int,indices:array<int>,values:array<double>>
)
STORED AS PARQUET
LOCATION 's3://path/to/file.parquet'
Run Code Online (Sandbox Code Playgroud)
请记住,结果列不会被解释为 Spark Vector。
| 归档时间: |
|
| 查看次数: |
1643 次 |
| 最近记录: |