从 sql 服务器读取数据并在 PySpark 中使用特殊字符传递我的密码
Reading data from sql server and passing my password with special char in PySpark
我正在尝试使用 PySpark 从 sql 服务器读取 table,我正在使用特殊字符传递我的密码,它在我的密码中抛出一个错误
from pyspark.sql import SparkSession
Spark = SparkSession.builder.appName("readdata").config("spark.driver.extraClassPath","/home/user/sqljdbc42.jar").enableHiveSupport().getOrCreate()
jdbcDF = Spark.read.format("jdbc") \
.option("url","jdbc:sqlserver://SVKSVP1234\SVLSQL908:1451\host;databaseName=NLX") \
.option("dbtable", "customers") \
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") \
.option("user", "admin") \
.option("password", "admin@123") \
.load()
jdbcDF.show()
我遇到了错误
文件 "filesystem.py",第 8 行,位于
.option("password", "admin@123")
我试过 r"admin@123" 但它对我不起作用
我得到的错误
文件 "filesystem.py",第 21 行,位于
.option("password", "admin@123") \
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/pyspark.zip/pyspark/sql/readwriter.py”,第 172 行,加载中
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py”,第 1257 行,在 打电话
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/pyspark.zip/pyspark/sql/utils.py”,第 63 行,deco
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py”,第 328 行,在 get_return_value
server_name = "<ServerName>"
database_name = "<DatabaseName>"
port = 1433
properties ={
"user": "<user>",
"password": "<password>"
}
url = "jdbc:sqlserver://{}:{};database={}".format(server_name, port, database_name)
spark.read.jdbc(url=url, table="dbo.tablename", properties=properties)
我正在尝试使用 PySpark 从 sql 服务器读取 table,我正在使用特殊字符传递我的密码,它在我的密码中抛出一个错误
from pyspark.sql import SparkSession
Spark = SparkSession.builder.appName("readdata").config("spark.driver.extraClassPath","/home/user/sqljdbc42.jar").enableHiveSupport().getOrCreate()
jdbcDF = Spark.read.format("jdbc") \
.option("url","jdbc:sqlserver://SVKSVP1234\SVLSQL908:1451\host;databaseName=NLX") \
.option("dbtable", "customers") \
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") \
.option("user", "admin") \
.option("password", "admin@123") \
.load()
jdbcDF.show()
我遇到了错误 文件 "filesystem.py",第 8 行,位于 .option("password", "admin@123")
我试过 r"admin@123" 但它对我不起作用
我得到的错误
文件 "filesystem.py",第 21 行,位于
.option("password", "admin@123") \
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/pyspark.zip/pyspark/sql/readwriter.py”,第 172 行,加载中
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py”,第 1257 行,在 打电话
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/pyspark.zip/pyspark/sql/utils.py”,第 63 行,deco
文件“/opt/cloudera/parcels/SPARK2-2.4.0.cloudera1-1.cdh5.13.3.p0.1007356/lib/spark2/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py”,第 328 行,在 get_return_value
server_name = "<ServerName>"
database_name = "<DatabaseName>"
port = 1433
properties ={
"user": "<user>",
"password": "<password>"
}
url = "jdbc:sqlserver://{}:{};database={}".format(server_name, port, database_name)
spark.read.jdbc(url=url, table="dbo.tablename", properties=properties)