尝试使用 Python 连接到 Databricks 下的 Redshift 时出现 Java 错误。据我所知,所提供的所有信息都是正确的。甚至不知道在哪里以及如何解决问题。任何建议都将不胜感激!
我已附加 RedshiftJDBC42_1_2_10_1009.jar。我还测试了使用 key 访问 s3 存储桶。
如果我不添加选项(“forward_spark_s3_credentials”,“true”),系统会告诉我添加指定选项。如果我更改存储桶名称,我会收到消息说该存储桶不存在。
Py4JJavaError Traceback (most recent call last)
<ipython-input-22-12ce019dbd97> in <module>()
10 #df = spark.read \
11
---> 12 df = sql_context.read .format("com.databricks.spark.redshift")
.option("forward_spark_s3_credentials", "true") .option("url",
"jdbc:redshift://XXX:5439/oobe?user=XXX&password=XXX") .option("query",
"select * from steps") .option("tempdir", "s3n://bucketName") .load()
/databricks/spark/python/pyspark/sql/readwriter.py in load(self, path, format, schema, **options)
153 return
self._df(self._jreader.load(self._spark._sc._jvm.PythonUtils.toSeq(path)))
154 else:
--> 155 return self._df(self._jreader.load())
156
157 @since(1.4)
/databricks/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py in __call__(self, *args)
1131 answer = self.gateway_client.send_command(command)
1132 return_value = get_return_value(
-> 1133 answer, self.gateway_client, self.target_id, self.name)
1134
1135 for temp_arg in temp_args:
/databricks/spark/python/pyspark/sql/utils.py in deco(*a, **kw)
61 def deco(*a, **kw):
62 try:
---> 63 return f(*a, **kw)
64 except py4j.protocol.Py4JJavaError as e:
65 s = e.java_exception.toString()
/databricks/spark/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
317 raise Py4JJavaError(
318 "An error occurred while calling {0}{1}{2}.\n".
--> 319 format(target_id, ".", name), value)
320 else:
321 raise Py4JError(
Py4JJavaError: An error occurred while calling o998.load.
: java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
at java.util.regex.Matcher.reset(Matcher.java:309)
at java.util.regex.Matcher.<init>(Matcher.java:229)
at java.util.regex.Pattern.matcher(Pattern.java:1093)
at scala.util.matching.Regex$MatchIterator.<init>(Regex.scala:742)
at scala.util.matching.Regex.findAllIn(Regex.scala:360)
at com.databricks.spark.redshift.Utils$.compareVersions(Utils.scala:344)
at com.databricks.spark.redshift.JDBCWrapper.getConnector(RedshiftJDBCWrapper.scala:260)
at com.databricks.spark.redshift.JDBCWrapper.getConnector(RedshiftJDBCWrapper.scala:307)
at com.databricks.spark.redshift.RedshiftRelation$$anonfun$schema$1.apply(RedshiftRelation.scala:64)
at com.databricks.spark.redshift.RedshiftRelation$$anonfun$schema$1.apply(RedshiftRelation.scala:61)
at scala.Option.getOrElse(Option.scala:121)
at com.databricks.spark.redshift.RedshiftRelation.schema$lzycompute(RedshiftRelation.scala:61)
at com.databricks.spark.redshift.RedshiftRelation.schema(RedshiftRelation.scala:60)
at org.apache.spark.sql.execution.datasources.LogicalRelation.<init>(LogicalRelation.scala:40)
at org.apache.spark.sql.SparkSession.baseRelationToDataFrame(SparkSession.scala:396)
at org.apache.spark.sql.DataFrameReader$$anonfun$load$1.apply(DataFrameReader.scala:148)
at org.apache.spark.sql.DataFrameReader$$anonfun$load$1.apply(DataFrameReader.scala:148)
at org.apache.spark.sql.execution.SQLExecution$.withFileAccessAudit(SQLExecution.scala:53)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:147)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:126)
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:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:280)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Thread.java:745)`
解决了!!!问题是
我使用的是 RedshiftJDBC42-1.2.10.1009.jar —— 不好。尝试使用早期版本。我切换到 RedshiftJDBC41-1.1.10.1010.jar。
无需替换 key 中的/s。
祝你好运!
我是一名优秀的程序员,十分优秀!