yikf commented on code in PR #8188:
URL: https://github.com/apache/incubator-gluten/pull/8188#discussion_r1875864786


##########
backends-velox/src/test/scala/org/apache/gluten/execution/VeloxCacheSuite.scala:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.execution
+
+import org.apache.gluten.GlutenConfig
+
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
+
+import org.scalatest.funsuite.AnyFunSuite
+
+class VeloxCacheSuite extends AnyFunSuite with AdaptiveSparkPlanHelper {
+
+  /**
+   * Velox cache is controlled by static configuration, this method is used to 
create a new
+   * SparkSession.
+   */
+  def withSparkSession(f: SparkSession => Unit, cacheEnabled: Boolean): Unit = 
{
+    val spark = SparkSession
+      .builder()
+      .master("local[1]")
+      .appName(s"test-veloxCache_$cacheEnabled")
+      .config(GlutenConfig.COLUMNAR_VELOX_CACHE_ENABLED.key, 
cacheEnabled.toString)
+      .config(GlutenConfig.COLUMNAR_VELOX_FILE_HANDLE_CACHE_ENABLED.key, 
cacheEnabled.toString)
+      .config(GlutenConfig.LOAD_QUANTUM.key, "8MB")
+      .config("spark.plugins", "org.apache.gluten.GlutenPlugin")
+      .config("spark.default.parallelism", "1")
+      .config("spark.memory.offHeap.enabled", "true")
+      .config("spark.memory.offHeap.size", "1024MB")
+      .config("spark.ui.enabled", "false")
+      .config("spark.gluten.ui.enabled", "false")
+      .getOrCreate()
+    try f(spark)
+    finally {
+      spark.stop()
+    }
+  }
+
+  test("Velox cache metrics") {
+    def test(cacheEnabled: Boolean)(spark: SparkSession): Unit = {
+      val table = s"metrics_t1_$cacheEnabled"
+      try {
+        spark.range(10).write.saveAsTable(table)
+
+        // first scan, read from storage.
+        val df = spark.sql(s"SELECT * FROM $table")
+        val scans = collect(df.queryExecution.executedPlan) {
+          case scan: FileSourceScanExecTransformer => scan
+        }
+        df.collect()
+        assert(scans.length === 1)
+        val metrics = scans.head.metrics
+        assert(metrics("storageReadBytes").value > 0)
+        assert(metrics("ramReadBytes").value == 0)
+
+        // second scan, read from cache if cache enabled.
+        val df2 = spark.sql(s"SELECT * FROM $table")
+        val scans2 = collect(df2.queryExecution.executedPlan) {
+          case scan: FileSourceScanExecTransformer => scan
+        }
+        df2.collect()
+        assert(scans2.length === 1)
+        val metrics2 = scans2.head.metrics
+        if (cacheEnabled) {
+          assert(metrics2("storageReadBytes").value == 0)
+          assert(metrics2("ramReadBytes").value > 0)
+        } else {
+          assert(metrics2("storageReadBytes").value > 0)
+          assert(metrics2("ramReadBytes").value == 0)
+        }
+      } finally {
+        spark.sql(s"DROP TABLE IF EXISTS $table")
+      }
+    }
+
+    Seq("true", "false").foreach(

Review Comment:
   this UT will fail due to the current lack of a shutdown, which will be fixed 
in another PR.



-- 
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