AngersZhuuuu commented on a change in pull request #31679:
URL: https://github.com/apache/spark/pull/31679#discussion_r587273419
##########
File path:
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLMetricsSuite.scala
##########
@@ -34,4 +36,30 @@ class SQLMetricsSuite extends SQLMetricsTestUtils with
TestHiveSingleton
testMetricsDynamicPartition("hive", "hive", "t1")
}
}
+
+ test("SPARK-34567: Add metrics for CreateTableAsSelectCommand") {
+ Seq(false, true).foreach { canOptimized =>
+ withSQLConf(HiveUtils.CONVERT_METASTORE_CTAS.key ->
canOptimized.toString) {
+ withTable("t") {
+ val df = sql(s"CREATE TABLE t STORED AS PARQUET AS SELECT 1 as a")
+ val dataWritingCommandExec =
+ df.queryExecution.executedPlan.asInstanceOf[DataWritingCommandExec]
+ dataWritingCommandExec.executeCollect()
+ val createTableAsSelect = dataWritingCommandExec.cmd
+ if (canOptimized) {
+
assert(createTableAsSelect.isInstanceOf[OptimizedCreateHiveTableAsSelectCommand])
+ } else {
+
assert(createTableAsSelect.isInstanceOf[CreateHiveTableAsSelectCommand])
+ }
+ assert(createTableAsSelect.metrics.contains("numFiles"))
+ assert(createTableAsSelect.metrics("numFiles").value == 1)
+ assert(createTableAsSelect.metrics.contains("numOutputBytes"))
+ val outputSize = if (canOptimized) 437 else 272
+ assert(createTableAsSelect.metrics("numOutputBytes").value ==
outputSize)
Review comment:
Done
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/metric/SQLMetricsSuite.scala
##########
@@ -782,4 +783,20 @@ class SQLMetricsSuite extends SharedSparkSession with
SQLMetricsTestUtils
}
}
}
+
+ test("SPARK-34567: Add metrics for CreateTableAsSelectCommand") {
+ withTable("t") {
+ val df = sql("CREATE TABLE t USING PARQUET AS SELECT 1 as a")
+ val dataWritingCommandExec =
+ df.queryExecution.executedPlan.asInstanceOf[DataWritingCommandExec]
+ dataWritingCommandExec.executeCollect()
+ val createTableAsSelect = dataWritingCommandExec.cmd
+ assert(createTableAsSelect.metrics.contains("numFiles"))
+ assert(createTableAsSelect.metrics("numFiles").value == 1)
+ assert(createTableAsSelect.metrics.contains("numOutputBytes"))
+ assert(createTableAsSelect.metrics("numOutputBytes").value == 437)
Review comment:
Done
##########
File path:
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLMetricsSuite.scala
##########
@@ -34,4 +36,30 @@ class SQLMetricsSuite extends SQLMetricsTestUtils with
TestHiveSingleton
testMetricsDynamicPartition("hive", "hive", "t1")
}
}
+
+ test("SPARK-34567: Add metrics for CreateTableAsSelectCommand") {
Review comment:
Done
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/metric/SQLMetricsSuite.scala
##########
@@ -782,4 +783,20 @@ class SQLMetricsSuite extends SharedSparkSession with
SQLMetricsTestUtils
}
}
}
+
+ test("SPARK-34567: Add metrics for CreateTableAsSelectCommand") {
Review comment:
Done
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/DataWritingCommand.scala
##########
@@ -73,4 +74,14 @@ object DataWritingCommand {
attr.withName(outputName)
}
}
+
+ def updateMetrics(
Review comment:
Done
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]