You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "stefankandic (via GitHub)" <gi...@apache.org> on 2025/01/20 15:15:05 UTC
[PR] [SPARK-50895] Create common interface for expressions which produce default string type [spark]
stefankandic opened a new pull request, #49576:
URL: https://github.com/apache/spark/pull/49576
<!--
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
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
Introducing a new interface `DefaultStringProducingExpression` which should be inherited by all expressions that produce default string type as their output.
### Why are the changes needed?
Because right now all of these expressions have hardcoded data type and it will be infinitely easier to manipulate these expression if they had a common supertype.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
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'.
-->
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 a refactoring change only, so existing tests should be sufficient.
### 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.
-->
No.
--
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-50895][SQL] Create common interface for expressions which produce default string type [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on PR #49576:
URL: https://github.com/apache/spark/pull/49576#issuecomment-2605524819
+1, LGTM. Merging to master/4.0.
Thank you, @stefankandic and @stevomitric for review.
--
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-50895][SQL] Create common interface for expressions which produce default string type [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk closed pull request #49576: [SPARK-50895][SQL] Create common interface for expressions which produce default string type
URL: https://github.com/apache/spark/pull/49576
--
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-50895][SQL] Create common interface for expressions which produce default string type [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on code in PR #49576:
URL: https://github.com/apache/spark/pull/49576#discussion_r1923211274
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collationExpressions.scala:
##########
@@ -151,12 +151,15 @@ case class ResolvedCollation(collationName: String) extends LeafExpression with
group = "string_funcs")
// scalastyle:on line.contains.tab
case class Collation(child: Expression)
- extends UnaryExpression with RuntimeReplaceable with ExpectsInputTypes {
+ extends UnaryExpression
+ with RuntimeReplaceable
+ with ExpectsInputTypes
+ with DefaultStringProducingExpression {
override protected def withNewChildInternal(newChild: Expression): Collation = copy(newChild)
override lazy val replacement: Expression = {
val collationId = child.dataType.asInstanceOf[StringType].collationId
val fullyQualifiedCollationName = CollationFactory.fullyQualifiedName(collationId)
- Literal.create(fullyQualifiedCollationName, SQLConf.get.defaultStringType)
+ Literal.create(fullyQualifiedCollationName, dataType)
Review Comment:
This one is not clear to me: `RuntimeReplaceable` has `dataType` and `DefaultStringProducingExpression` has too. Do you assume `dataType` from `DefaultStringProducingExpression`?
--
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-50895][SQL] Create common interface for expressions which produce default string type [spark]
Posted by "stefankandic (via GitHub)" <gi...@apache.org>.
stefankandic commented on code in PR #49576:
URL: https://github.com/apache/spark/pull/49576#discussion_r1923877836
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collationExpressions.scala:
##########
@@ -151,12 +151,15 @@ case class ResolvedCollation(collationName: String) extends LeafExpression with
group = "string_funcs")
// scalastyle:on line.contains.tab
case class Collation(child: Expression)
- extends UnaryExpression with RuntimeReplaceable with ExpectsInputTypes {
+ extends UnaryExpression
+ with RuntimeReplaceable
+ with ExpectsInputTypes
+ with DefaultStringProducingExpression {
override protected def withNewChildInternal(newChild: Expression): Collation = copy(newChild)
override lazy val replacement: Expression = {
val collationId = child.dataType.asInstanceOf[StringType].collationId
val fullyQualifiedCollationName = CollationFactory.fullyQualifiedName(collationId)
- Literal.create(fullyQualifiedCollationName, SQLConf.get.defaultStringType)
+ Literal.create(fullyQualifiedCollationName, dataType)
Review Comment:
In scala if multiple traits have the same method defined the one that was defined last in the class definition will take precedence, so yes it will take `dataType` from `DefaultStringProducingExpression `.
--
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-50895][SQL] Create common interface for expressions which produce default string type [spark]
Posted by "stefankandic (via GitHub)" <gi...@apache.org>.
stefankandic commented on PR #49576:
URL: https://github.com/apache/spark/pull/49576#issuecomment-2604961817
@MaxGekk I have created a separate PR to unblock the test that is failing in the collation expression walker suite #49586.
--
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-50895] Create common interface for expressions which produce default string type [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on code in PR #49576:
URL: https://github.com/apache/spark/pull/49576#discussion_r1922710739
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -1462,3 +1462,11 @@ case class MultiCommutativeOp(
override protected final def otherCopyArgs: Seq[AnyRef] = originalRoot :: Nil
}
+
+/**
+ * Trait for expressions that have children that have String type but whose
Review Comment:
Could you elaborate this:
```
have children that have String type
```
for instance the expression `CurrentTimeZone` doesn't have any children of `String`
--
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-50895][SQL] Create common interface for expressions which produce default string type [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on PR #49576:
URL: https://github.com/apache/spark/pull/49576#issuecomment-2605535297
@stefankandic Could you open a PR with backport to `branch-4.0`, please.
--
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-50895] Create common interface for expressions which produce default string type [spark]
Posted by "stefankandic (via GitHub)" <gi...@apache.org>.
stefankandic commented on code in PR #49576:
URL: https://github.com/apache/spark/pull/49576#discussion_r1922732288
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -1462,3 +1462,11 @@ case class MultiCommutativeOp(
override protected final def otherCopyArgs: Seq[AnyRef] = originalRoot :: Nil
}
+
+/**
+ * Trait for expressions that have children that have String type but whose
Review Comment:
This was definitely not worded correctly. I updated the docstring a bit, but feel free to suggest something else if you think something could be improved.
--
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