You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "srielau (via GitHub)" <gi...@apache.org> on 2023/05/26 23:24:42 UTC

[GitHub] [spark] srielau opened a new pull request, #41335: [SPARK-43205] IDENTIFIER clause docs

srielau opened a new pull request, #41335:
URL: https://github.com/apache/spark/pull/41335

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


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


[GitHub] [spark] linhongliu-db commented on a diff in pull request #41335: [SPARK-43205][DOCS][SQL][FOLLOWUP] IDENTIFIER clause docs + SQL Variable Integration

Posted by "linhongliu-db (via GitHub)" <gi...@apache.org>.
linhongliu-db commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1294094715


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -305,16 +307,16 @@ trait ColumnResolutionHelper extends Logging {
         } else {
           variable
         }
-      }.map(e => Alias(e, nameParts.last)())
+      }.map(e => if (isTopLevel) Alias(e, nameParts.last)() else e )
     }
 
     e.transformWithPruning(_.containsAnyPattern(UNRESOLVED_ATTRIBUTE, TEMP_RESOLVED_COLUMN)) {

Review Comment:
   how about skip wrapping `Alias` in the `def resolve`, but check the final value after `e.tranformWithPruning`, if it's not an `Alias`, add one.



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


[GitHub] [spark] linhongliu-db commented on a diff in pull request #41335: [SPARK-43205][DOCS][SQL][FOLLOWUP] IDENTIFIER clause docs + SQL Variable Integration

Posted by "linhongliu-db (via GitHub)" <gi...@apache.org>.
linhongliu-db commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1294092609


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveIdentifierClause.scala:
##########
@@ -42,7 +42,12 @@ object ResolveIdentifierClause extends Rule[LogicalPlan] {
 
   private def evalIdentifierExpr(expr: Expression): Seq[String] = {
     expr match {
-      case e if !e.foldable => expr.failAnalysis(
+      case e: Alias if !e.child.foldable => expr.failAnalysis(
+        errorClass = "NOT_A_CONSTANT_STRING.NOT_CONSTANT",
+        messageParameters = Map(
+          "name" -> "IDENTIFIER",
+          "expr" -> expr.sql))
+      case e if !e.isInstanceOf[Alias] && !e.foldable => expr.failAnalysis(

Review Comment:
   ```
   case e if !e.foldable => expr.failAnalysis(
   ```
   equals to
   ```
   case e if !e.isInstanceOf[Alias] && !e.foldable => expr.failAnalysis(
   ```
   



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


[GitHub] [spark] srielau commented on pull request #41335: [SPARK-43205][DOCS][SQL][FOLLOWUP] IDENTIFIER clause docs

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

   @cloud-fan This is also ready I think.


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


[GitHub] [spark] gengliangwang commented on pull request #41335: [SPARK-43205] IDENTIFIER clause docs

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

   @srielau Yes, please following https://github.com/apache/spark/blob/master/docs/README.md and preview your doc change in the browser.
   (Note that the Scala/Python API Prerequisites are not required for this one.)


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


[GitHub] [spark] cloud-fan commented on pull request #41335: [SPARK-43205][DOCS][SQL][FOLLOWUP] IDENTIFIER clause docs

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

   the test failure is unrelated, 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


[GitHub] [spark] srielau commented on a diff in pull request #41335: [SPARK-43205] IDENTIFIER clause docs

Posted by "srielau (via GitHub)" <gi...@apache.org>.
srielau commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1207482519


##########
docs/sql-ref-identifier-clause.md:
##########
@@ -0,0 +1,70 @@
+---
+layout: global
+title: Identifier clause
+displayTitle: IDENTIFIER clause
+license: |
+  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.
+---
+
+### Description
+
+Convert a constant `STRING` expression into a SQL object name.
+The purpose of this clause is to allow for templating of identifiers in SQL statements without opening up the risk of SQL injection attacks.
+Typically, this clause is used with a parameter marker as argument.
+
+### Syntax
+
+```sql
+IDENTIFIER ( strExpr )
+```
+
+### Parameters
+
+- strExpr: A constant STRING expression. Typically, the expression includes a parameter marker.
+
+### Returns
+
+A (qualified) identifier which can be used as a:
+
+- qualified table name
+- namespace name
+- function name
+- qualified column or attribute reference
+
+### Examples
+
+```scala
+-- Using IDENTIFIER() on a namepace
+spark.sql("CREATE SCHEMA IDENTIFIER(:namepace)", args = Map("namespace" -> "mychema")

Review Comment:
   ```suggestion
   spark.sql("CREATE SCHEMA IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")
   ```



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


[GitHub] [spark] srielau commented on a diff in pull request #41335: [SPARK-43205][DOCS][SQL][FOLLOWUP] IDENTIFIER clause docs

Posted by "srielau (via GitHub)" <gi...@apache.org>.
srielau commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1295263767


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveIdentifierClause.scala:
##########
@@ -42,7 +42,12 @@ object ResolveIdentifierClause extends Rule[LogicalPlan] {
 
   private def evalIdentifierExpr(expr: Expression): Seq[String] = {
     expr match {
-      case e if !e.foldable => expr.failAnalysis(
+      case e: Alias if !e.child.foldable => expr.failAnalysis(
+        errorClass = "NOT_A_CONSTANT_STRING.NOT_CONSTANT",
+        messageParameters = Map(
+          "name" -> "IDENTIFIER",
+          "expr" -> expr.sql))
+      case e if !e.isInstanceOf[Alias] && !e.foldable => expr.failAnalysis(

Review Comment:
   Removed



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -305,16 +307,16 @@ trait ColumnResolutionHelper extends Logging {
         } else {
           variable
         }
-      }.map(e => Alias(e, nameParts.last)())
+      }.map(e => if (isTopLevel) Alias(e, nameParts.last)() else e )
     }
 
     e.transformWithPruning(_.containsAnyPattern(UNRESOLVED_ATTRIBUTE, TEMP_RESOLVED_COLUMN)) {

Review Comment:
   Removed



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


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #41335: [SPARK-43205][DOCS][FOLLOWUP] IDENTIFIER clause docs

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1208697481


##########
docs/sql-ref-identifier-clause.md:
##########
@@ -0,0 +1,70 @@
+---
+layout: global
+title: Identifier clause
+displayTitle: IDENTIFIER clause
+license: |
+  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.
+---
+
+### Description
+
+Convert a constant `STRING` expression into a SQL object name.
+The purpose of this clause is to allow for templating of identifiers in SQL statements without opening up the risk of SQL injection attacks.
+Typically, this clause is used with a parameter marker as argument.
+
+### Syntax
+
+```sql
+IDENTIFIER ( strExpr )
+```
+
+### Parameters
+
+- strExpr: A constant STRING expression. Typically, the expression includes a parameter marker.
+
+### Returns
+
+A (qualified) identifier which can be used as a:
+
+- qualified table name
+- namespace name
+- function name
+- qualified column or attribute reference
+
+### Examples
+
+```scala
+-- Using IDENTIFIER() on a namepace
+spark.sql("CREATE SCHEMA IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")
+
+-- Using IDENTIFIER() on table DDL
+spark.sql("CREATE TABLE IDENTIFIER('myschema.' || :tabname) (c1 INT)", args = Map("tabname" -> "mytable")
+
+-- Using IDENTIFIER() on table DML
+spark.sql("INSERT INTO IDENTIFIER(:tabname) VALUES (1)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a table reference 
+spark.sql("SELECT * FROM IDENTIFIER(:tabname)", args = Map("tabname" -> "myschema.mytable")

Review Comment:
   Could you include the output here?



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


[GitHub] [spark] srielau commented on a diff in pull request #41335: [SPARK-43205][DOCS][FOLLOWUP] IDENTIFIER clause docs

Posted by "srielau (via GitHub)" <gi...@apache.org>.
srielau commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1294084386


##########
docs/sql-ref-identifier-clause.md:
##########
@@ -0,0 +1,70 @@
+---
+layout: global
+title: Identifier clause
+displayTitle: IDENTIFIER clause
+license: |
+  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.
+---
+
+### Description
+
+Convert a constant `STRING` expression into a SQL object name.
+The purpose of this clause is to allow for templating of identifiers in SQL statements without opening up the risk of SQL injection attacks.
+Typically, this clause is used with a parameter marker as argument.
+
+### Syntax
+
+```sql
+IDENTIFIER ( strExpr )
+```
+
+### Parameters
+
+- strExpr: A constant STRING expression. Typically, the expression includes a parameter marker.
+
+### Returns
+
+A (qualified) identifier which can be used as a:
+
+- qualified table name
+- namespace name
+- function name
+- qualified column or attribute reference
+
+### Examples
+
+```scala
+-- Using IDENTIFIER() on a namepace
+spark.sql("CREATE SCHEMA IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")
+
+-- Using IDENTIFIER() on table DDL
+spark.sql("CREATE TABLE IDENTIFIER('myschema.' || :tabname) (c1 INT)", args = Map("tabname" -> "mytable")
+
+-- Using IDENTIFIER() on table DML
+spark.sql("INSERT INTO IDENTIFIER(:tabname) VALUES (1)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a table reference 
+spark.sql("SELECT * FROM IDENTIFIER(:tabname)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a column reference 
+spark.sql("SELECT IDENTIFIER(:colname) FROM mychema.mytable WHERE IDENTIFIER(:colname) IS NOT NULL", args = Map("colname" -> "`c1`")
+
+-- Using IDENTIFIER() on a function reference 
+spark.sql("SELECT IDENTIFIER(:aggFunc)(c1) FROM myschema.mytable", args = Map("aggFunc" -> "sum")
+
+-- Using IDENTIFIER() on SHOW
+spark.sql("SHOW TABLES IN IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")

Review Comment:
   Done



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


[GitHub] [spark] srielau commented on a diff in pull request #41335: [SPARK-43205][DOCS][FOLLOWUP] IDENTIFIER clause docs

Posted by "srielau (via GitHub)" <gi...@apache.org>.
srielau commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1294084247


##########
docs/sql-ref-identifier-clause.md:
##########
@@ -0,0 +1,70 @@
+---
+layout: global
+title: Identifier clause
+displayTitle: IDENTIFIER clause
+license: |
+  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.
+---
+
+### Description
+
+Convert a constant `STRING` expression into a SQL object name.
+The purpose of this clause is to allow for templating of identifiers in SQL statements without opening up the risk of SQL injection attacks.
+Typically, this clause is used with a parameter marker as argument.
+
+### Syntax
+
+```sql
+IDENTIFIER ( strExpr )
+```
+
+### Parameters
+
+- strExpr: A constant STRING expression. Typically, the expression includes a parameter marker.
+
+### Returns
+
+A (qualified) identifier which can be used as a:
+
+- qualified table name
+- namespace name
+- function name
+- qualified column or attribute reference
+
+### Examples
+
+```scala
+-- Using IDENTIFIER() on a namepace
+spark.sql("CREATE SCHEMA IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")
+
+-- Using IDENTIFIER() on table DDL
+spark.sql("CREATE TABLE IDENTIFIER('myschema.' || :tabname) (c1 INT)", args = Map("tabname" -> "mytable")
+
+-- Using IDENTIFIER() on table DML
+spark.sql("INSERT INTO IDENTIFIER(:tabname) VALUES (1)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a table reference 
+spark.sql("SELECT * FROM IDENTIFIER(:tabname)", args = Map("tabname" -> "myschema.mytable")

Review Comment:
   Done



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


[GitHub] [spark] cloud-fan closed pull request #41335: [SPARK-43205][DOCS][SQL][FOLLOWUP] IDENTIFIER clause docs

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #41335: [SPARK-43205][DOCS][SQL][FOLLOWUP] IDENTIFIER clause docs
URL: https://github.com/apache/spark/pull/41335


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


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #41335: [SPARK-43205][DOCS][FOLLOWUP] IDENTIFIER clause docs

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1208697563


##########
docs/sql-ref-identifier-clause.md:
##########
@@ -0,0 +1,70 @@
+---
+layout: global
+title: Identifier clause
+displayTitle: IDENTIFIER clause
+license: |
+  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.
+---
+
+### Description
+
+Convert a constant `STRING` expression into a SQL object name.
+The purpose of this clause is to allow for templating of identifiers in SQL statements without opening up the risk of SQL injection attacks.
+Typically, this clause is used with a parameter marker as argument.
+
+### Syntax
+
+```sql
+IDENTIFIER ( strExpr )
+```
+
+### Parameters
+
+- strExpr: A constant STRING expression. Typically, the expression includes a parameter marker.
+
+### Returns
+
+A (qualified) identifier which can be used as a:
+
+- qualified table name
+- namespace name
+- function name
+- qualified column or attribute reference
+
+### Examples
+
+```scala
+-- Using IDENTIFIER() on a namepace
+spark.sql("CREATE SCHEMA IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")
+
+-- Using IDENTIFIER() on table DDL
+spark.sql("CREATE TABLE IDENTIFIER('myschema.' || :tabname) (c1 INT)", args = Map("tabname" -> "mytable")
+
+-- Using IDENTIFIER() on table DML
+spark.sql("INSERT INTO IDENTIFIER(:tabname) VALUES (1)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a table reference 
+spark.sql("SELECT * FROM IDENTIFIER(:tabname)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a column reference 
+spark.sql("SELECT IDENTIFIER(:colname) FROM mychema.mytable WHERE IDENTIFIER(:colname) IS NOT NULL", args = Map("colname" -> "`c1`")
+
+-- Using IDENTIFIER() on a function reference 
+spark.sql("SELECT IDENTIFIER(:aggFunc)(c1) FROM myschema.mytable", args = Map("aggFunc" -> "sum")
+
+-- Using IDENTIFIER() on SHOW
+spark.sql("SHOW TABLES IN IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")

Review Comment:
   ditto. Please include output too



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


[GitHub] [spark] srielau commented on a diff in pull request #41335: [SPARK-43205] IDENTIFIER clause docs

Posted by "srielau (via GitHub)" <gi...@apache.org>.
srielau commented on code in PR #41335:
URL: https://github.com/apache/spark/pull/41335#discussion_r1207482382


##########
docs/sql-ref-identifier-clause.md:
##########
@@ -0,0 +1,70 @@
+---
+layout: global
+title: Identifier clause
+displayTitle: IDENTIFIER clause
+license: |
+  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.
+---
+
+### Description
+
+Convert a constant `STRING` expression into a SQL object name.
+The purpose of this clause is to allow for templating of identifiers in SQL statements without opening up the risk of SQL injection attacks.
+Typically, this clause is used with a parameter marker as argument.
+
+### Syntax
+
+```sql
+IDENTIFIER ( strExpr )
+```
+
+### Parameters
+
+- strExpr: A constant STRING expression. Typically, the expression includes a parameter marker.
+
+### Returns
+
+A (qualified) identifier which can be used as a:
+
+- qualified table name
+- namespace name
+- function name
+- qualified column or attribute reference
+
+### Examples
+
+```scala
+-- Using IDENTIFIER() on a namepace
+spark.sql("CREATE SCHEMA IDENTIFIER(:namepace)", args = Map("namespace" -> "mychema")
+
+-- Using IDENTIFIER() on table DDL
+spark.sql("CREATE TABLE IDENTIFIER('myschema.' || :tabname) (c1 INT)", args = Map("tabname" -> "mytable")
+
+-- Using IDENTIFIER() on table DML
+spark.sql("INSERT INTO IDENTIFIER(:tabname) VALUES (1)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a table reference 
+spark.sql("SELECT * FROM IDENTIFIER(:tabname)", args = Map("tabname" -> "myschema.mytable")
+
+-- Using IDENTIFIER() on a column reference 
+spark.sql("SELECT IDENTIFIER(:colname) FROM mychema.mytable WHERE IDENTIFIER(:colname) IS NOT NULL", args = Map("colname" -> "`c1`")
+
+-- Using IDENTIFIER() on a function reference 
+spark.sql("SELECT IDENTIFIER(:aggFunc)(c1) FROM myschema.mytable", args = Map("aggFunc" -> "sum")
+
+-- Using IDENTIFIER() on SHOW
+spark.sql("SHOW TABLES IN IDENTIFIER(:namepace)", args = Map("namespace" -> "mychema")

Review Comment:
   ```suggestion
   spark.sql("SHOW TABLES IN IDENTIFIER(:namespace)", args = Map("namespace" -> "mychema")
   ```



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


[GitHub] [spark] srielau commented on pull request #41335: [SPARK-43205] IDENTIFIER clause docs

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

   @gengliangwang how do we test doc changes?


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