craiuconstantintiberiu commented on code in PR #56550:
URL: https://github.com/apache/spark/pull/56550#discussion_r3426377536


##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala:
##########
@@ -2486,6 +2488,117 @@ class JDBCSuite extends SharedSparkSession {
       )
     }
   }
+
+  test("SPARK-57471: input bytesRead metric scales with data size") {
+    // Write test data with short and long strings
+    val props = new Properties()
+    props.setProperty("user", "testUser")
+    props.setProperty("password", "testPass")
+
+    val shortStrings = (1 to 10).map(i => Row(i, "a"))
+    val longStrings = (1 to 10).map(i => Row(i, "a" * 100))
+    val schema = new StructType().add("id", IntegerType).add("data", 
StringType)
+
+    spark.createDataFrame(sparkContext.makeRDD(shortStrings), schema)
+      .write.mode(SaveMode.Overwrite).jdbc(urlWithUserAndPass, 
"TEST.BYTES_SHORT", props)
+    spark.createDataFrame(sparkContext.makeRDD(longStrings), schema)
+      .write.mode(SaveMode.Overwrite).jdbc(urlWithUserAndPass, 
"TEST.BYTES_LONG", props)
+
+    def collectBytesRead(table: String): Long = {
+      val taskMetrics = new ArrayBuffer[Long]()
+      sparkContext.listenerBus.waitUntilEmpty()
+      val listener = new SparkListener() {
+        override def onTaskEnd(taskEnd: SparkListenerTaskEnd): Unit = {
+          taskMetrics += taskEnd.taskMetrics.inputMetrics.bytesRead
+        }
+      }
+      sparkContext.addSparkListener(listener)
+      spark.read.jdbc(urlWithUserAndPass, table, props).collect()
+      sparkContext.listenerBus.waitUntilEmpty()
+      sparkContext.removeSparkListener(listener)
+      taskMetrics.sum
+    }

Review Comment:
   Could this be extractd into a helper?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to