[英]Python: JDBC Connection Error to Apache Drill Error with JayDeBeApi
I am trying to connect to Apache Drill from python using jaydebeapi
library.我正在尝试使用
jaydebeapi
库从 python 连接到 Apache Drill。
I have turned on drill in embedded mode via drill-embedded
, and the web ui runs correctly in port 8047. Then, I am trying to connect via JDBC through a python script:我已经通过
drill-embedded
在嵌入式模式下打开drill,并且web ui 在端口8047 中正确运行。然后,我尝试通过python 脚本通过JDBC 进行连接:
import jaydebeapi
import jpype
import os
DRILL_HOME = os.environ["DRILL_HOME"]
classpath = DRILL_HOME + "/jars/jdbc-driver/drill-jdbc-all-1.17.0.jar"
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
conn = jaydebeapi.connect(
'org.apache.drill.jdbc.Driver',
'jdbc:drill:drillbit=localhost:8047'
)
but I get this error但我收到这个错误
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Traceback (most recent call last):
File "jaydebe_drill.py", line 10, in <module>
'jdbc:drill:drillbit=localhost:8047'
File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/jaydebeapi/__init__.py", line 412,
in connect
jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/jaydebeapi/__init__.py", line 230,
in _jdbc_connect_jpype
return jpype.java.sql.DriverManager.getConnection(url, *dargs)
jpype._jexception.SQLNonTransientConnectionExceptionPyRaisable:
java.sql.SQLNonTransientConnectionException:
Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.ChannelClosedException:
Channel closed /127.0.0.1:62244 <--> localhost/127.0.0.1:8047.
Does anyone knows how to solve the issue?有谁知道如何解决这个问题?
Thanks to @Luke Woodward suggestion, the problem was the port.感谢@Luke Woodward 的建议,问题出在端口上。 For
drill-embedded
there is no port to select.对于
drill-embedded
,没有可供选择的端口。 Below a full query example下面是一个完整的查询示例
import jaydebeapi
import jpype
import os
import pandas as pd
DRILL_HOME = os.environ["DRILL_HOME"]
classpath = DRILL_HOME + "/jars/jdbc-driver/drill-jdbc-all-1.17.0.jar"
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
conn = jaydebeapi.connect(
'org.apache.drill.jdbc.Driver',
'jdbc:drill:drillbit=localhost'
)
cursor = conn.cursor()
query = """
SELECT *
FROM dfs.`/Users/user/data.parquet`
LIMIT 1
"""
cursor.execute(query)
columns = [c[0] for c in cursor.description]
data = cursor.fetchall()
df = pd.DataFrame(data, columns=columns)
df.head()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.