Spark 不显示驻留在配置单元中的数据 table
Spark does not show data residing in a hive table
假设我使用 Spark 创建以下 table:
df = spark.createDataFrame([(1, 4), (2, 5), (3, 6)], ["A", "B"])
df.write.mode("overwrite").saveAsTable("hivedb.mwe")
现在,如果我尝试计算此 table 中的数据:
> spark.sql("SELECT count(*) FROM hivedb.mwe").show()
+--------+
|count(1)|
+--------+
| 0|
+--------+
但是,如果我使用 Hive(或 Impala 计算数据,结果相同)
jdbc:hive2:...> SELECT count(*) FROM hivedb.mwe
+------+--+
| _c0 |
+------+--+
| 3 |
+------+--+
这里可能发生了什么,spark 似乎没有看到 mwe 中的数据?
作为插件,Spark 非常了解 table:
> spark.sql("DESCRIBE hivedb.mwe").show()
+--------+---------+-------+
|col_name|data_type|comment|
+--------+---------+-------+
| A| bigint| null|
| B| bigint| null|
+--------+---------+-------+
为了完整起见:
- Spark 版本:v2.2.0.cloudera1
- hivedb 是一个使用非标准位置参数创建的配置单元数据库
- 集群是
完全 Kerberized
HDFS 包含:
[myuser@cluster~]$ hdfs dfs -ls /path/to/hivedb/mwe
Found 3 items
-rw-r--r-- 3 myuser somegroup 0 2018-02-09 13:29 /path/to/hivedb/mwe/_SUCCESS
-rw-r--r-- 3 myuser somegroup 526 2018-02-09 13:29 /path/to/hivedb/mwe/part-00000-f1e79c0d-fca5-4a46-aa70-3651baa96a90-c000.snappy.parquet
-rw-r--r-- 3 myuser somegroup 545 2018-02-09 13:29 /path/to/hivedb/mwe/part-00001-f1e79c0d-fca5-4a46-aa70-3651baa96a90-c000.snappy.parquet
这似乎是 cloudera 2.2 中的一个已知问题。
https://www.cloudera.com/documentation/spark2/latest/topics/spark2_known_issues.html#SPARK-21994
已提供最佳替代解决方案,您能否查看以上内容 link 并执行解决方案并查看可行的解决方案。
这些是解决方案
val options = Map("path" -> "/path/to/hdfs/directory/containing/table")
df.write.options(options).saveAsTable("db_name.table_name")
spark.sql("alter table db_name.table_name set SERDEPROPERTIES ('path'='hdfs://host.example.com:8020/warehouse/path/db_name.db/table_name')")
spark.catalog.refreshTable("db_name.table_name")
假设我使用 Spark 创建以下 table:
df = spark.createDataFrame([(1, 4), (2, 5), (3, 6)], ["A", "B"])
df.write.mode("overwrite").saveAsTable("hivedb.mwe")
现在,如果我尝试计算此 table 中的数据:
> spark.sql("SELECT count(*) FROM hivedb.mwe").show()
+--------+
|count(1)|
+--------+
| 0|
+--------+
但是,如果我使用 Hive(或 Impala 计算数据,结果相同)
jdbc:hive2:...> SELECT count(*) FROM hivedb.mwe
+------+--+
| _c0 |
+------+--+
| 3 |
+------+--+
这里可能发生了什么,spark 似乎没有看到 mwe 中的数据?
作为插件,Spark 非常了解 table:
> spark.sql("DESCRIBE hivedb.mwe").show()
+--------+---------+-------+
|col_name|data_type|comment|
+--------+---------+-------+
| A| bigint| null|
| B| bigint| null|
+--------+---------+-------+
为了完整起见:
- Spark 版本:v2.2.0.cloudera1
- hivedb 是一个使用非标准位置参数创建的配置单元数据库
- 集群是 完全 Kerberized
HDFS 包含:
[myuser@cluster~]$ hdfs dfs -ls /path/to/hivedb/mwe Found 3 items -rw-r--r-- 3 myuser somegroup 0 2018-02-09 13:29 /path/to/hivedb/mwe/_SUCCESS -rw-r--r-- 3 myuser somegroup 526 2018-02-09 13:29 /path/to/hivedb/mwe/part-00000-f1e79c0d-fca5-4a46-aa70-3651baa96a90-c000.snappy.parquet -rw-r--r-- 3 myuser somegroup 545 2018-02-09 13:29 /path/to/hivedb/mwe/part-00001-f1e79c0d-fca5-4a46-aa70-3651baa96a90-c000.snappy.parquet
这似乎是 cloudera 2.2 中的一个已知问题。
https://www.cloudera.com/documentation/spark2/latest/topics/spark2_known_issues.html#SPARK-21994
已提供最佳替代解决方案,您能否查看以上内容 link 并执行解决方案并查看可行的解决方案。
这些是解决方案
val options = Map("path" -> "/path/to/hdfs/directory/containing/table")
df.write.options(options).saveAsTable("db_name.table_name")
spark.sql("alter table db_name.table_name set SERDEPROPERTIES ('path'='hdfs://host.example.com:8020/warehouse/path/db_name.db/table_name')")
spark.catalog.refreshTable("db_name.table_name")