【发布时间】:2017-06-09 20:35:26
【问题描述】:
我是 Big Insights 的新手。我正在研究 Cloud 4.1、Ambari 2.2.0 和 Spark 1.6.1 上的 BigInsigths 连接是用scala还是python没关系,但我需要用spark做数据处理,然后把它持久化到BigSql中。这可能吗?提前致谢。
【问题讨论】:
标签: apache-spark pyspark biginsights bigsql bigdata
我是 Big Insights 的新手。我正在研究 Cloud 4.1、Ambari 2.2.0 和 Spark 1.6.1 上的 BigInsigths 连接是用scala还是python没关系,但我需要用spark做数据处理,然后把它持久化到BigSql中。这可能吗?提前致谢。
【问题讨论】:
标签: apache-spark pyspark biginsights bigsql bigdata
检查 syshadoop.execspark 以了解如何执行 Spark Jobs 并以表格式返回输出,之后您可以插入表或与其他表连接。
SELECT *
FROM TABLE(SYSHADOOP.EXECSPARK(
class => 'DataSource',
format => 'json',
uriload => 'hdfs://host.port.com:8020/user/bigsql/demo.json'
)
) AS doc
WHERE doc.country IS NOT NULL
LIMIT 5
【讨论】:
以下是在 BigInsights 中使用 jdbc 通过 PySpark 连接 BigSQL 的步骤 --
1.将db2jcc4.jar(IBM驱动连接BigSQL,可以从http://www-01.ibm.com/support/docview.wss?uid=swg21363866下载)放到python库中。
2.在 spark-defaults.conf 文件中添加 jar 文件路径(位于您的 spark 安装的 conf 文件夹中) spark.driver.extraClassPath /usr/lib/spark/python/lib/db2jcc4.jar spark.executor.extraClassPath /usr/lib/spark/python/lib/db2jcc4.jar
或
使用jar路径启动Spark Shell -- pyspark --jars /usr/lib/spark/python/lib/db2jcc4.jar
3.使用sqlContext.read.format指定JDBC URL等驱动信息--
从 pyspark.sql 导入 SQLContext
sqlContext=SQLContext(sc)
df = sqlContext.read.format("jdbc").option(url="jdbc:db2://hostname:port/bigsql",driver="com.ibm.db2.jcc.DB2Driver",dbtable= "tablename", user="username", password="password").load()
df.show()
【讨论】: