gpt4 book ai didi

python - 使用 Phoenix 4.x 和 Python 2.x 从 Hbase 1.1 获取数据时出错

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:53 25 4
gpt4 key购买 nike

我是 Phoenix、HBase 和 Python 的初学者,正在使用 Pyspark 编写一个小型 POC,以使用 Phoenix 从 HBase DB 检索一些基本信息。

这是我的代码片段。

query = 'select count(PK) from A_Model.TableA'
jdbc_url = 'jdbc:phoenix:..xxx/hbase-secure'
df_records = sparkConfig.getSqlContext().read.format('jdbc')\
.options(driver='org.apache.phoenix.jdbc.PhoenixDriver', url=jdbc_url, dbtable=query).load()

当尝试使用spark-submit运行它时,我收到以下错误

`
Traceback (most recent call last):
File "/users/s190641/Tejas_Test/ahi_rpt_test.py", line 54, in <module>
main()
...
...
.options(driver='org.apache.phoenix.jdbc.PhoenixDriver', url=jdbc_url, dbtable=query).load()
File "/usr/hdp/current/spark-client/python/lib/pyspark.zip/pyspark/sql/readwriter.py", line 139, in load
File "/usr/hdp/current/spark-client/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py", line 813, in __call__
File "/usr/hdp/current/spark-client/python/lib/pyspark.zip/pyspark/sql/utils.py", line 45, in deco
File "/usr/hdp/current/spark-client/python/lib/py4j-0.9-src.zip/py4j/protocol.py", line 308, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o62.load.
: org.apache.phoenix.exception.PhoenixParserException: ERROR 601 (42P00): Syntax error. Encountered "select" at line 1, column 15.
at org.apache.phoenix.exception.PhoenixParserException.newException(PhoenixParserException.java:33)
at org.apache.phoenix.parse.SQLParser.parseStatement(SQLParser.java:111)
at org.apache.phoenix.jdbc.PhoenixStatement$PhoenixStatementParser.parseStatement(PhoenixStatement.java:1280)
at org.apache.phoenix.jdbc.PhoenixStatement.parseStatement(PhoenixStatement.java:1363)
at org.apache.phoenix.jdbc.PhoenixPreparedStatement.<init>(PhoenixPreparedStatement.java:94)
at org.apache.phoenix.jdbc.PhoenixConnection.prepareStatement(PhoenixConnection.java:723)
at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:122)
at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation.<init>(JDBCRelation.scala:91)
at org.apache.spark.sql.execution.datasources.jdbc.DefaultSource.createRelation(DefaultSource.scala:57)
at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:158)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381)
at py4j.Gateway.invoke(Gateway.java:259)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:209)
at java.lang.Thread.run(Thread.java:745)
Caused by: NoViableAltException(133@[])
at org.apache.phoenix.parse.PhoenixSQLParser.table_factor(PhoenixSQLParser.java:6195)
at org.apache.phoenix.parse.PhoenixSQLParser.table_ref(PhoenixSQLParser.java:6083)
at org.apache.phoenix.parse.PhoenixSQLParser.table_list(PhoenixSQLParser.java:6019)
at org.apache.phoenix.parse.PhoenixSQLParser.parseFrom(PhoenixSQLParser.java:5984)
at org.apache.phoenix.parse.PhoenixSQLParser.single_select(PhoenixSQLParser.java:4612)
at org.apache.phoenix.parse.PhoenixSQLParser.unioned_selects(PhoenixSQLParser.java:4714)
at org.apache.phoenix.parse.PhoenixSQLParser.select_node(PhoenixSQLParser.java:4780)
at org.apache.phoenix.parse.PhoenixSQLParser.oneStatement(PhoenixSQLParser.java:789)
at org.apache.phoenix.parse.PhoenixSQLParser.statement(PhoenixSQLParser.java:508)
at org.apache.phoenix.parse.SQLParser.parseStatement(SQLParser.java:108)
... 20 more
`

最佳答案

Spark SQL - load data with JDBC using SQL statement, not table name 中所述,你应该使用子查询:

query = '(select count(PK) from A_Model.TableA) AS some_name'

但在实践中it is recommended to use connector, not JDBC :

Although Spark supports connecting directly to JDBC databases, it’s only able to parallelize queries by partioning on a numeric column. It also requires a known lower bound, upper bound and partition count in order to create split queries.

In contrast, the phoenix-spark integration is able to leverage the underlying splits provided by Phoenix in order to retrieve and save data across multiple workers. All that’s required is a database URL and a table name. Optional SELECT columns can be given, as well as pushdown predicates for efficient filtering.

关于python - 使用 Phoenix 4.x 和 Python 2.x 从 Hbase 1.1 获取数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48505638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com