Why Spark JDBC infers table schema even when schema is specified?

937 Views Asked by At

I'm using spark.read.format("jdbc").option("query", tmpSql) to load a table from Mysql, and I can see a query select * from (xxx) where 1=0 from database monitor, later I know this query is used for inferring table schema in Spark. However when I use spark.read.format("jdbc").option("query", tmpSql).schema(xxx), the table schema inferring query is still there. Why Spark still need to infer table schema when customSchema is already specified?

1

There are 1 best solutions below

1
过过招 On

Try to use the customSchema parameter of spark jdbc.

.option("customSchema", schema_str)