Este problema se ha tratado varias veces en StackOverflow:
- ¿Cómo mejorar el rendimiento para trabajos lentos de Spark usando DataFrame y conexión JDBC?
- spark jdbc df limit... ¿qué está haciendo?
- ¿Cómo usar la fuente JDBC para escribir y leer datos en (Py)Spark?
y en fuentes externas:
así que solo para reiterar - por defecto DataFrameReader.jdbc
no distribuye datos ni lee. Utiliza hilo único, ejecutor único.
Para distribuir lecturas:
-
usar rangos con
lowerBound
/upperBound
:Properties properties; Lower Dataset<Row> set = sc .read() .option("partitionColumn", "foo") .option("numPartitions", "3") .option("lowerBound", 0) .option("upperBound", 30) .option("url", url) .option("dbtable", this.tableName) .option("driver","com.mysql.jdbc.Driver") .format("jdbc") .load();
-
predicates
Properties properties; Dataset<Row> set = sc .read() .jdbc( url, this.tableName, {"foo < 10", "foo BETWWEN 10 and 20", "foo > 20"}, properties )