andygrove commented on code in PR #3328:
URL: https://github.com/apache/datafusion-comet/pull/3328#discussion_r2743151024


##########
spark/src/test/scala/org/apache/comet/SqlFileTestParser.scala:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.comet
+
+import java.io.File
+
+import scala.io.Source
+
+/** A record in a SQL test file: either a statement (DDL/DML) or a query 
(SELECT). */
+sealed trait SqlTestRecord
+
+/** A SQL statement to execute (CREATE TABLE, INSERT, etc.). */
+case class SqlStatement(sql: String) extends SqlTestRecord
+
+/** A SQL query whose results are compared between Spark and Comet. */
+case class SqlQuery(sql: String, mode: QueryMode = CheckOperator) extends 
SqlTestRecord
+
+sealed trait QueryMode
+case object CheckOperator extends QueryMode
+case object SparkAnswerOnly extends QueryMode
+case class WithTolerance(tol: Double) extends QueryMode
+case class ExpectFallback(reason: String) extends QueryMode
+case class Ignore(reason: String) extends QueryMode
+
+/**
+ * Parsed representation of a .sql test file.
+ *
+ * @param configs
+ *   Spark SQL configs to set for this test file.
+ * @param configMatrix
+ *   Map of config key to list of values. The test will run once per 
combination.
+ * @param records
+ *   Ordered list of statements and queries.
+ * @param tables
+ *   Table names extracted from CREATE TABLE statements (for cleanup).
+ * @param minSparkVersion
+ *   Optional minimum Spark version required to run this test (e.g. "3.5").
+ */
+case class SqlTestFile(
+    configs: Seq[(String, String)],
+    configMatrix: Seq[(String, Seq[String])],
+    records: Seq[SqlTestRecord],
+    tables: Seq[String],
+    minSparkVersion: Option[String] = None)
+
+object SqlFileTestParser {
+
+  private val ConfigPattern = """--\s*Config:\s*(.+)=(.+)""".r
+  private val ConfigMatrixPattern = """--\s*ConfigMatrix:\s*(.+)=(.+)""".r
+  private val MinSparkVersionPattern = """--\s*MinSparkVersion:\s*(.+)""".r
+  private val CreateTablePattern = 
"""(?i)CREATE\s+TABLE\s+(\w+)""".r.unanchored
+
+  def parse(file: File): SqlTestFile = {
+    val source = Source.fromFile(file, "UTF-8")
+    try {
+      parse(source.getLines().toSeq)
+    } finally {
+      source.close()
+    }
+  }
+
+  def parse(lines: Seq[String]): SqlTestFile = {
+    var configs = Seq.empty[(String, String)]
+    var configMatrix = Seq.empty[(String, Seq[String])]
+    var minSparkVersion: Option[String] = None
+    val records = Seq.newBuilder[SqlTestRecord]
+    val tables = Seq.newBuilder[String]
+
+    var i = 0

Review Comment:
   Thanks. I addressed this and your other comments



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