在AWS EMR 7.0(Spark3.5)配置SQLServer JDBC驱动遇类缺失错误求助
PySpark EMR部署时SQL Server驱动类找不到问题
问题现象
本地以local模式运行PySpark ETL管道(用于与Microsoft SQL Server交互)一切正常,但部署到AWS EMR集群执行步骤时,抛出如下错误:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
已尝试的解决方式
我原本通过在SparkSession创建代码中指定Maven坐标引入驱动包,代码如下:
def get_spark_session( run_local: bool = False, app_name: str = "ETL Pipeline", worker_threads: int = 8, jars_packages: str = "com.microsoft.sqlserver:mssql-jdbc:12.6.1.jre11", ) -> SparkSession: """ Helper function to get a SparkSession object. :param run_local: Whether to run the SparkSession locally (typically only for debugging). Defaults to False. :param app_name: Name of the Spark application. Defaults to "WCV". :param worker_threads: Number of worker threads. Defaults to 8. :param jars_packages: Comma-separated list of Maven coordinates for the jars to include on the driver and executor :return: the SparkSession object """ # build the SparkSession builder = SparkSession.builder.appName(app_name) if run_local: # set up a local SparkSession builder with the specified number of worker threads builder = builder.master(f"local[{worker_threads}]") logger.info("Running Spark locally") else: logger.info("Running Spark on a cluster") # configure the SparkSession builder = ( builder.config("spark.jars.packages", jars_packages) ) return builder.getOrCreate()
环境详情
- AWS EMR版本:7.0.0(内置Spark 3.5.0)
- 使用的SQL Server JDBC驱动版本:
12.6.1.jre11(本地运行正常) - EMR集群默认Java版本:17
疑问点
- 无法找到版本兼容表,不确定
12.6.1版本的SQL Server驱动是否适配EMR 7.0.0 - 根据官方文档说明:
12.6是最新的正式版(GA)驱动,支持Java 8、11、17和21。
带jre8的JAR包支持Java 8,带jre11的JAR包支持Java 11及以上版本。
按此说明驱动版本应该适配,但集群仍报错。
内容的提问来源于stack exchange,提问作者James Adams
相关产品推荐
相关产品推荐

