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: [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]
