Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14235#discussion_r71094937
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/catalyst/LogicalPlanToSQLSuite.scala
 ---
    @@ -76,22 +85,51 @@ class LogicalPlanToSQLSuite extends SQLBuilderTest with 
SQLTestUtils {
         }
       }
     
    -  private def checkHiveQl(hiveQl: String): Unit = {
    -    val df = sql(hiveQl)
    +  // Used for generating new query answer files by saving
    +  private val saveQuery = false
    +
    +  /**
    +   * Compare the generated SQL with the expected answer string.
    +   * Note that there exists a normalization for both arguments for the 
convenience.
    +   * - Remove the id from the generated attributes, e.g., `gen_attr_1` -> 
`gen_attr`.
    +   */
    +  private def checkSQLStructure(originalSQL: String, convertedSQL: String, 
answerFile: String) = {
    +    val normalizedGenSQL = convertedSQL.replaceAll("`gen_attr_\\d+`", 
"`gen_attr`")
    +    if (answerFile != null) {
    +      val path = s"src/test/resources/sqlgen/$answerFile.sql"
    +      val separator = "-" * 80
    +      if (saveQuery) {
    +        val answerText = 
s"${originalSQL.trim()}\n${separator}\n$normalizedGenSQL\n"
    +        Files.write(Paths.get(path), 
answerText.getBytes(StandardCharsets.UTF_8))
    +      } else {
    +        val answerText = new String(Files.readAllBytes(Paths.get(path)), 
StandardCharsets.UTF_8)
    +        val sqls = answerText.split(separator)
    +        if (sqls.length == 2) {
    +          val normalizedExpectSQL = sqls(1).trim()
    +          assert(normalizedGenSQL == normalizedExpectSQL)
    +        }
    +      }
    +    }
    +  }
    +
    +  private def checkSQL(sqlString: String, answerFile: String = null): Unit 
= {
    --- End diff --
    
    When is answerFile null? You should document this. Also why does it default 
to null?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to