从 pyspark 访问 cassandra

2023-12-30

我正在开发 Azure Datalake。 我想从我的 pyspark 脚本访问 cassandra。我试过 :

> pyspark --packages anguenot/pyspark-cassandra:0.7.0 --conf spark.cassandra.connection.host=12.34.56.78
SPARK_MAJOR_VERSION is set to 2, using Spark2
Python 2.7.12 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
Ivy Default Cache set to: /home/opnf/.ivy2/cache
The jars for the packages stored in: /home/opnf/.ivy2/jars
:: loading settings :: url = jar:file:/usr/hdp/2.5.5.0-157/spark2/jars/ivy-2.4.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
anguenot#pyspark-cassandra added as a dependency
:: resolving dependencies :: org.apache.spark#spark-submit-parent;1.0
        confs: [default]
        found anguenot#pyspark-cassandra;0.7.0 in spark-packages
        found com.datastax.spark#spark-cassandra-connector_2.11;2.0.6 in central
        found org.joda#joda-convert;1.2 in central
        found commons-beanutils#commons-beanutils;1.9.3 in central
        found commons-collections#commons-collections;3.2.2 in central
        found com.twitter#jsr166e;1.1.0 in central
        found io.netty#netty-all;4.0.33.Final in central
        found joda-time#joda-time;2.3 in central
        found org.scala-lang#scala-reflect;2.11.8 in central
        found net.razorvine#pyrolite;4.10 in central
        found net.razorvine#serpent;1.12 in central
:: resolution report :: resolve 710ms :: artifacts dl 33ms
        :: modules in use:
        anguenot#pyspark-cassandra;0.7.0 from spark-packages in [default]
        com.datastax.spark#spark-cassandra-connector_2.11;2.0.6 from central in [default]
        com.twitter#jsr166e;1.1.0 from central in [default]
        commons-beanutils#commons-beanutils;1.9.3 from central in [default]
        commons-collections#commons-collections;3.2.2 from central in [default]
        io.netty#netty-all;4.0.33.Final from central in [default]
        joda-time#joda-time;2.3 from central in [default]
        net.razorvine#pyrolite;4.10 from central in [default]
        net.razorvine#serpent;1.12 from central in [default]
        org.joda#joda-convert;1.2 from central in [default]
        org.scala-lang#scala-reflect;2.11.8 from central in [default]
        ---------------------------------------------------------------------
        |                  |            modules            ||   artifacts   |
        |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
        ---------------------------------------------------------------------
        |      default     |   11  |   0   |   0   |   0   ||   11  |   0   |
        ---------------------------------------------------------------------
:: retrieving :: org.apache.spark#spark-submit-parent
        confs: [default]
        0 artifacts copied, 11 already retrieved (0kB/40ms)
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel).
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/anguenot_pyspark-cassandra-0.7.0.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/com.datastax.spark_spark-cassandra-connector_2.11-2.0.6.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/net.razorvine_pyrolite-4.10.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/org.joda_joda-convert-1.2.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/commons-beanutils_commons-beanutils-1.9.3.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/com.twitter_jsr166e-1.1.0.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/io.netty_netty-all-4.0.33.Final.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/joda-time_joda-time-2.3.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/org.scala-lang_scala-reflect-2.11.8.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/commons-collections_commons-collections-3.2.2.jar added multiple times to distributed cache.
18/04/17 14:52:39 WARN Client: Same path resource file:/home/opnf/.ivy2/jars/net.razorvine_serpent-1.12.jar added multiple times to distributed cache.
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /__ / .__/\_,_/_/ /_/\_\   version 2.0.2.2.5.5.0-157
      /_/

Using Python version 2.7.12 (default, Jul  2 2016 17:42:40)
SparkSession available as 'spark'.
>>> import pyspark_cassandra
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pyspark_cassandra

显然,加载过程中没有问题,但最后我仍然无法导入包。可能是什么原因 ?


该包的使用与文档中描述的略有不同。

无需导入包。 相反,如果您想读取数据帧,请使用:

sqlContext.read\
    .format("org.apache.spark.sql.cassandra")\
    .options(table="my_table", keyspace="my_keyspace")\
    .load()

如果你想写,请使用:

df.write\
    .format("org.apache.spark.sql.cassandra")\
    .mode('append')\
    .options(
        table="my_table", 
        keyspace="my_keyspace",
    )\
    .save()

(with mode('overwrite'),您可能需要添加该方法.option('confirm.truncate',True))

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 pyspark 访问 cassandra 的相关文章

随机推荐

  • 是否可以使 bash shell 脚本与另一个命令行程序交互?

    我在运行 bash shell 的 Linux 终端中使用交互式命令行程序 我有一个明确的命令序列输入到 shell 程序中 程序将其输出写入标准输出 其中一个命令是 保存 命令 它将前一个运行的命令的输出写入磁盘的文件中 一个典型的循环是
  • if else 在列表理解中[重复]

    这个问题在这里已经有答案了 我有一个清单l l 22 13 45 50 98 69 43 44 1 对于45以上的数字 我想加1 对于小于它的数字 5 I tried x 1 for x in l if x gt 45 else x 5 但
  • Jupyter 的 Octave 内核无法在 Windows 10 上运行

    我尝试使用 pip 为 jupyter 安装八度内核 如此处建议的https github com calysto octave kernel https github com calysto octave kernel 但我在创建新笔记本
  • 根据 Firebase 中的子项过滤产品

    我试图弄清楚如何根据 Firebase 中的子子节点来过滤产品 我的设置如下 products product1 author 12345 title Awesome description more awesome product2 au
  • 验证 RSA 签名 iOS

    在我的静态库中 我有一个许可证文件 我想确保它是由我自己生成的 并且没有被更改 所以我的想法是使用我读过的 RSA 签名 我在网上查了一下 这就是我想到的 第一 使用我找到的信息生成私钥和自签名证书here https github com
  • 在 Sybase 过程中从表中选择 TOP 1 * 失败

    我尝试在不使用 RowCount 函数的情况下从 Sybase 表中仅获取一条记录 即使 WHERE 条件 返回多个结果 SELECT TOP 1 EMPLOYEE NAME FROM EMPLOYEES WHERE EMPLOYEEID
  • 无效的堆地址和致命信号 11

    我的应用程序经常会崩溃 我的日志将显示 ABORTING INVALID HEAP ADDRESS IN dlfree Fatal signal 11 SIGSEGV at 0xdeadbaad code 1 有时code 2 但总是Fat
  • PUT/同步所需的 s3cmd S3 权限

    在迁移到 AWS EC2 时 我有充分的理由希望限制实例的用户权限 实例需要做的一件事是访问 S3 上的文件并在那里写入文件 然而 如果不向该用户授予所有权限 我找不到任何方法来实现此目的 s3cmd 允许我在我授予策略权限的 s3 存储桶
  • 如何将字符串字段句子拆分为单词并将它们插入到具有相同键 id 的新表中?

    我有一个名为 Pads 的表 其中有一个名为 keywords 的字段 它有一个单词列表 也称为句子 e g Pad ID 1 Keywords red brown green ID 2 keywords green orange blue
  • OpenGL ES:围绕自身旋转 3d 模型

    我正在 iPhone 上使用 OpenGL ES 并尝试通过用手指平移来旋转模型 我发现了开源应用程序 Molecules 可以让你做到这一点 我正在查看该代码 但是当涉及到旋转我的模型时 我只能围绕空间中远处的一个点旋转它 就像它一样 作
  • 如何使用for循环画不同角度的圆线

    我使用下面的代码在圆圈中画一条线 现在我想以相同的间距以不同的角度绘制12条线 并且线应该接触到圆圈
  • 跨平台 Flash Player 嵌入

    我需要以跨平台方式 至少 Windows 和 Mac OSX 将 Flash 播放器嵌入本机应用程序 C 中 我需要允许 Flash gui 回调本机应用程序来执行 Flash 通常无法执行的操作 例如写入文件系统 与设备通信 加载本机图像
  • Jquery 手风琴关闭然后打开

    我使用 jquery 手风琴插件在页面上设置了多个手风琴 这样我就可以实现全部展开和折叠所有功能 每个 ID 元素都是它自己的手风琴 下面的代码可以将它们全部关闭 无论哪些元素已经打开 contact address email sales
  • Xcode 14 - 无法在此文件中预览,无法连接到 iPhone 14 | FailedToConnectToDTServiceHubError:无法连接到 iPhone 14

    在探索 swiftUI 并在 Xcode 中创建我的第一个 swiftUI 应用程序时 它抛出预览错误 提示 无法在此文件中预览 无法连接到 设备名称 虽然它在模拟器中运行良好 为了排除故障 我已经尝试了所有基本技巧 例如 删除派生数据 取
  • 谷歌地球热图

    有没有办法在谷歌地球中创建热图 以便具有较高值 某些指定参数 例如人口 的区域显示为热点 这似乎是可能的 例如 看一下这几个链接 免责声明 我没有尝试过这些 HeatMapAPI com http www heatmapapi com An
  • 部分合并两个数据集并在R中填充NA

    我有两个数据集 a 包含数千个不同天气事件观测结果的原始数据集 STATE EVTYPE 1 AL WINTER STORM 2 AL TORNADO 3 AL TSTM WIND 4 AL TSTM WIND 5 AL TSTM WIND
  • 我可以用 sum() 连接列表吗?

    使用Pythonic吗sum 用于列表串联 gt gt gt sum n n for n in range 1 5 1 2 2 3 3 3 4 4 4 4 不 不是 实际上是Shlemiel 画家算法 http en wikichip or
  • Visual Studio 2010 与 SQL Server 2008 和 Office 2007 的正确安装顺序?

    我想创建一个 Windows 7 64 位 旗舰版 虚拟机 Visual Studio 2010 终极版 Office 2007 企业版 带有 Visio 2007 SQL Server 2008 带有 SSIS 和 SSRS 但我不确定是
  • 如何使用 Javascript 替换 DOM 元素?

    我正在寻找替换 DOM 中的元素 例如 有一个 a 我想用 a 替换的元素 span 反而 我该怎么做呢 通过使用替换子对象 https developer mozilla org en US docs Web API Node repla
  • 从 pyspark 访问 cassandra

    我正在开发 Azure Datalake 我想从我的 pyspark 脚本访问 cassandra 我试过 gt pyspark packages anguenot pyspark cassandra 0 7 0 conf spark ca