【问题标题】:How to connect from spark 1.6 to bigsql如何从 spark 1.6 连接到 bigsql
【发布时间】: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


    【解决方案1】:

    检查 syshadoop.execspark 以了解如何执行 Spark Jobs 并以表格式返回输出,之后您可以插入表或与其他表连接。

    https://www.ibm.com/support/knowledgecenter/en/SSPT3X_4.3.0/com.ibm.swg.im.infosphere.biginsights.db2biga.doc/doc/biga_execspark.html

    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
    

    【讨论】:

    • 感谢您的大力支持,但我在云端使用 Big Insight 4.1 :( SYSHADOOP.EXECSPARK 可用于 4.2 和 4.3 版本。您知道尝试这样做的其他方法吗?谢谢!
    【解决方案2】:

    以下是在 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()

    【讨论】:

      猜你喜欢
      • 2019-02-10
      • 2019-10-16
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      • 2015-05-28
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多