无法在 Spark 中读取 ORC 事务 table。看到空数据框
Can't read ORC transactional table in Spark. Seeing empty dataframe
我们有一个具有 ORC 文件格式和 ZLiB 压缩的事务性 table。这是一个内部 table。通过 Hive CLI 阅读时,我可以阅读 table。但是当通过 spark sql runnnig select 时,它显示 table 所有列和 0 行。请帮忙。
这可以使用 Hive Ware Connector 在 scala spark 中完成(我使用的是 Hortonworks)。
使用的罐子是 "hive-warehouse-connector_2.11-1.0.0.3.1.0.0-78.jar".
示例代码:
import com.hortonworks.hwc.HiveWarehouseSession
import com.hortonworks.spark.sql.hive.llap.HiveWarehouseBuilder
val conf = new SparkConf()
val spark = SparkSession.builder().appName(AppName).enableHiveSupport().getOrCreate()
spark.conf.set("spark.sql.hive.hiveserver2.jdbc.url","//your hive url")
val hive = HiveWarehouseBuilder.session(spark).build()
val res = hive.table("db.tablename")
res.show(20,False)
这也可以使用 Pyspark 实现,但您必须向其添加一些配置,下面是在 Pyspark 中执行相同操作的代码示例
from pyspark.sql import *
from pyspark_llap import HiveWarehouseSession
from pyspark.sql import SparkSession
from pyspark.sql.rdd.RDD
from pyspark.sql.types import *
from pyspark.sql import Window
from pyspark.sql.functions import *
from pyspark.sql.functions import *
spark = SparkSession.builder \
.appName("appname") \
.enableHiveSupport() \
.getOrCreate()
hive = HiveWarehouseSession.session(spark).build()
sample = hive.executeQuery("""select * from <schema.tablename>""")
sample.show()`
使用 spark-submit 执行上面的配置,添加如下配置
spark-submit --jars /usr/hdp/3.1.0.0-78/hive_warehouse_connector/hive-warehouse-connector-assembly-1.0.0.3.1.0.0-78.jar --py-files /usr/hdp/current/hive_warehouse_connector/pyspark_hwc-1.0.0.3.1.0.0-78.zip --conf spark.sql.hive.hiveserver2.jdbc.url="jdbc URL;serviceDiscoveryMode=zooKeeperHA;zooKeeperNamespace=hs2ActivePassiveHA" --conf spark.hadoop.hive.llap.daemon.service.hosts="@llap0" --conf spark.datasource.hive.warehouse.load.staging.dir="/tmp" --conf spark.hadoop.hive.zookeeper.quorum="all zookeeper urls" --conf spark.sql.hive.hiveserver2.jdbc.url.principal="url for JDBC connection" --conf spark.security.credentials.hiveserver2.enabled="true" TestPysparkJob.py
我们有一个具有 ORC 文件格式和 ZLiB 压缩的事务性 table。这是一个内部 table。通过 Hive CLI 阅读时,我可以阅读 table。但是当通过 spark sql runnnig select 时,它显示 table 所有列和 0 行。请帮忙。
这可以使用 Hive Ware Connector 在 scala spark 中完成(我使用的是 Hortonworks)。 使用的罐子是 "hive-warehouse-connector_2.11-1.0.0.3.1.0.0-78.jar".
示例代码:
import com.hortonworks.hwc.HiveWarehouseSession
import com.hortonworks.spark.sql.hive.llap.HiveWarehouseBuilder
val conf = new SparkConf()
val spark = SparkSession.builder().appName(AppName).enableHiveSupport().getOrCreate()
spark.conf.set("spark.sql.hive.hiveserver2.jdbc.url","//your hive url")
val hive = HiveWarehouseBuilder.session(spark).build()
val res = hive.table("db.tablename")
res.show(20,False)
这也可以使用 Pyspark 实现,但您必须向其添加一些配置,下面是在 Pyspark 中执行相同操作的代码示例
from pyspark.sql import *
from pyspark_llap import HiveWarehouseSession
from pyspark.sql import SparkSession
from pyspark.sql.rdd.RDD
from pyspark.sql.types import *
from pyspark.sql import Window
from pyspark.sql.functions import *
from pyspark.sql.functions import *
spark = SparkSession.builder \
.appName("appname") \
.enableHiveSupport() \
.getOrCreate()
hive = HiveWarehouseSession.session(spark).build()
sample = hive.executeQuery("""select * from <schema.tablename>""")
sample.show()`
使用 spark-submit 执行上面的配置,添加如下配置
spark-submit --jars /usr/hdp/3.1.0.0-78/hive_warehouse_connector/hive-warehouse-connector-assembly-1.0.0.3.1.0.0-78.jar --py-files /usr/hdp/current/hive_warehouse_connector/pyspark_hwc-1.0.0.3.1.0.0-78.zip --conf spark.sql.hive.hiveserver2.jdbc.url="jdbc URL;serviceDiscoveryMode=zooKeeperHA;zooKeeperNamespace=hs2ActivePassiveHA" --conf spark.hadoop.hive.llap.daemon.service.hosts="@llap0" --conf spark.datasource.hive.warehouse.load.staging.dir="/tmp" --conf spark.hadoop.hive.zookeeper.quorum="all zookeeper urls" --conf spark.sql.hive.hiveserver2.jdbc.url.principal="url for JDBC connection" --conf spark.security.credentials.hiveserver2.enabled="true" TestPysparkJob.py