You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "andylam-db (via GitHub)" <gi...@apache.org> on 2024/01/04 21:28:37 UTC

[PR] Generate subqueries for correctness testing [spark]

andylam-db opened a new pull request, #44599:
URL: https://github.com/apache/spark/pull/44599

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46683] Write a subquery generator that generates subqueries permutations to increase testing coverage [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #44599:
URL: https://github.com/apache/spark/pull/44599#discussion_r1461366253


##########
sql/core/src/test/scala/org/apache/spark/sql/QueryGeneratorHelper.scala:
##########
@@ -0,0 +1,224 @@
+/*
+ * 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.spark.sql
+
+/**
+ * Simple implementation of Expressions and Operators that can be used to generate SQL for testing.
+ * For example, to construct a simple SELECT query using the defined classes, follow these steps:
+ *
+ * 1. Define a table name, and some column names for your table.
+ * {{{
+ *   val tableName = "t1"
+ *   val col1 = "col1"
+ *   val col2 = "col2"
+ * }}}
+ * 2. Define named expressions representing the columns to select using the Attribute class, and
+ *    define the table relation with TableRelation.
+ * {{{
+ *   val col1Attr = Attribute("column1", qualifier = Some(tableName))
+ *   val col2Attr = Attribute("column2", qualifier = Some(tableName))
+ *   val table = TableRelation(tableName, Seq(col1Attr, col2Attr))
+ * }}}
+ * 3. Create a SELECT clause using the SelectClause class, and specify the FROM clause with the
+ *    table relations using the FromClause class.
+ * {{{
+ *   val selectClause = SelectClause(Seq(col1Attr))
+ *   val fromClause = FromClause(Seq(table))
+ * }}}
+ * 4. (Optional) Add a WHERE clause using the WhereClause class for predicates. The OrderBy, Limit
+ * clauses are also optional.
+ * {{{
+ *   val condition = Equals(col1Attr, col2Attr)
+ *   val whereClause = WhereClause(Seq(condition))
+ * }}}
+ * 5. Construct the final query using the Query class:
+ * {{{
+ *   val myQuery = Query(selectClause, fromClause, Some(whereClause))()
+ * }}}
+ * 6. Print or use the generated SQL query:
+ * {{{
+ *   println(myQuery.toString)
+ * }}}
+ *
+ * Output: SELECT t1.column1 FROM t1 WHERE t1.column1 = t1.column2

Review Comment:
   col1 or column1?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46683] Write a subquery generator that generates subqueries permutations to increase testing coverage [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #44599: [SPARK-46683] Write a subquery generator that generates subqueries permutations to increase testing coverage
URL: https://github.com/apache/spark/pull/44599


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46683] Write a subquery generator that generates subqueries permutations to increase testing coverage [spark]

Posted by "andylam-db (via GitHub)" <gi...@apache.org>.
andylam-db commented on PR #44599:
URL: https://github.com/apache/spark/pull/44599#issuecomment-1894968921

   @cloud-fan @jchen5 Changed it to not produce golden files instead, just a normal test suite. 


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46683] Write a subquery generator that generates subqueries permutations to increase testing coverage [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #44599:
URL: https://github.com/apache/spark/pull/44599#discussion_r1461365725


##########
sql/core/src/test/scala/org/apache/spark/sql/QueryGeneratorHelper.scala:
##########
@@ -0,0 +1,224 @@
+/*
+ * 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.spark.sql
+
+/**
+ * Simple implementation of Expressions and Operators that can be used to generate SQL for testing.
+ * For example, to construct a simple SELECT query using the defined classes, follow these steps:
+ *
+ * 1. Define a table name, and some column names for your table.
+ * {{{
+ *   val tableName = "t1"
+ *   val col1 = "col1"
+ *   val col2 = "col2"
+ * }}}
+ * 2. Define named expressions representing the columns to select using the Attribute class, and
+ *    define the table relation with TableRelation.
+ * {{{
+ *   val col1Attr = Attribute("column1", qualifier = Some(tableName))

Review Comment:
   ```suggestion
    *   val col1Attr = Attribute(col1, qualifier = Some(tableName))
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/QueryGeneratorHelper.scala:
##########
@@ -0,0 +1,224 @@
+/*
+ * 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.spark.sql
+
+/**
+ * Simple implementation of Expressions and Operators that can be used to generate SQL for testing.
+ * For example, to construct a simple SELECT query using the defined classes, follow these steps:
+ *
+ * 1. Define a table name, and some column names for your table.
+ * {{{
+ *   val tableName = "t1"
+ *   val col1 = "col1"
+ *   val col2 = "col2"
+ * }}}
+ * 2. Define named expressions representing the columns to select using the Attribute class, and
+ *    define the table relation with TableRelation.
+ * {{{
+ *   val col1Attr = Attribute("column1", qualifier = Some(tableName))
+ *   val col2Attr = Attribute("column2", qualifier = Some(tableName))

Review Comment:
   ```suggestion
    *   val col2Attr = Attribute(col2, qualifier = Some(tableName))
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46683] Write a subquery generator that generates subqueries permutations to increase testing coverage [spark]

Posted by "andylam-db (via GitHub)" <gi...@apache.org>.
andylam-db commented on PR #44599:
URL: https://github.com/apache/spark/pull/44599#issuecomment-1905348381

   @cloud-fan Can we merge? Thanks!


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46683] Write a subquery generator that generates subqueries of different variations to increase testing coverage [spark]

Posted by "andylam-db (via GitHub)" <gi...@apache.org>.
andylam-db commented on PR #44599:
URL: https://github.com/apache/spark/pull/44599#issuecomment-1888079179

   @cloud-fan @jchen5 Open for reviews! I listed some potential issues in the PR description:
   
   > 1. There are a lot of queries. There are 14 files, each containing ~300 queries. Adding more variations (such as new operators like WINDOW, OFFSET) would only increase the number of queries. This might slow down tests significantly.
   > 2. A small change in the SubquerySQLGeneratorSuite might introduce a lot of golden file changes. This makes this potentially very difficult to maintain.
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46683] Write a subquery generator that generates subqueries permutations to increase testing coverage [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #44599:
URL: https://github.com/apache/spark/pull/44599#issuecomment-1905678695

   thanks, merging to master!


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org