spark不显示驻留在配置单元表中的数据

thigvfpy  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(635)

假设我使用spark创建下表:

  1. df = spark.createDataFrame([(1, 4), (2, 5), (3, 6)], ["A", "B"])
  2. df.write.mode("overwrite").saveAsTable("hivedb.mwe")

现在,如果我尝试计算这个表中的数据:

  1. > spark.sql("SELECT count(*) FROM hivedb.mwe").show()
  2. +--------+
  3. |count(1)|
  4. +--------+
  5. | 0|
  6. +--------+

但是,如果我使用hive(或impala,它给出相同的结果)计算数据

  1. jdbc:hive2:...> SELECT count(*) FROM hivedb.mwe
  2. +------+--+
  3. | _c0 |
  4. +------+--+
  5. | 3 |
  6. +------+--+

这里可能发生了什么,spark似乎看不到mwe中的数据?
作为一个插件,spark非常了解表:

  1. > spark.sql("DESCRIBE hivedb.mwe").show()
  2. +--------+---------+-------+
  3. |col_name|data_type|comment|
  4. +--------+---------+-------+
  5. | A| bigint| null|
  6. | B| bigint| null|
  7. +--------+---------+-------+

为了完整起见:
spark版本:v2.2.0.cloudera1
hivedb是使用非标准位置参数创建的配置单元数据库
集群完全煤化
hdfs包含:

  1. [myuser@cluster~]$ hdfs dfs -ls /path/to/hivedb/mwe
  2. Found 3 items
  3. -rw-r--r-- 3 myuser somegroup 0 2018-02-09 13:29 /path/to/hivedb/mwe/_SUCCESS
  4. -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
  5. -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
velaa5lx

velaa5lx1#

这似乎是Cloudera2.2中的一个已知问题。
https://www.cloudera.com/documentation/spark2/latest/topics/spark2_known_issues.html#spark-21994
最好的替代解决方案是提供给你看上面的链接,并执行周围的工作,看看解决方案是可能的。
这些都是解决方案

  1. val options = Map("path" -> "/path/to/hdfs/directory/containing/table")
  2. df.write.options(options).saveAsTable("db_name.table_name")
  3. spark.sql("alter table db_name.table_name set SERDEPROPERTIES ('path'='hdfs://host.example.com:8020/warehouse/path/db_name.db/table_name')")
  4. spark.catalog.refreshTable("db_name.table_name")

相关问题