Skip to content

Conversation

@beliefer
Copy link
Contributor

@beliefer beliefer commented Apr 9, 2020

What changes were proposed in this pull request?

Some alias of expression can not display correctly in schema. This PR will fix them.

  • TimeWindow
  • MaxBy
  • MinBy
  • UnaryMinus
  • BitwiseCount

This PR also fix a typo issue, please look at

s"<!-- Automatically generated by${getClass.getSimpleName} -->\n" +

Note:

  1. MaxBy and MinBy extends MaxMinBy and the latter add a method funcName not needed. We can reuse prettyName to replace funcName.
  2. Spark SQL exists some function no elegant implementation.For example: BitwiseCount override the sql method show below:
    override def sql: String = s"bit_count(${child.sql})"
    I don't think it's elegant enough. Because Expression gives the following definitions.
  def sql: String = {
    val childrenSQL = children.map(_.sql).mkString(", ")
    s"$prettyName($childrenSQL)"
  }

By this definition, BitwiseCount should override prettyName method.

Why are the changes needed?

Improve the implement of some expression.

Does this PR introduce any user-facing change?

'Yes'. This PR will let user see the correct alias in schema.

How was this patch tested?

Jenkins test.

@SparkQA
Copy link

SparkQA commented Apr 9, 2020

Test build #121013 has finished for PR 28164 at commit 08f0906.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Apr 9, 2020

Test build #121019 has finished for PR 28164 at commit 7b7f8bf.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Apr 9, 2020

Test build #121036 has finished for PR 28164 at commit 67c868b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@beliefer
Copy link
Contributor Author

cc @HyukjinKwon


override def toString: String = s"-$child"

override def prettyName: String = "-"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HyukjinKwon Should we change "-" to "negative" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be negative but should show - when it's used as the sql operator. You should be able to do this with if-else. e.g.)

getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("-")

You might need to override sql IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@SparkQA
Copy link

SparkQA commented Apr 12, 2020

Test build #121142 has finished for PR 28164 at commit 43beb20.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@beliefer beliefer force-pushed the elegant-pretty-name-for-function branch from 43beb20 to 67c868b Compare April 12, 2020 08:47
@SparkQA
Copy link

SparkQA commented Apr 12, 2020

Test build #121144 has finished for PR 28164 at commit 67c868b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.


override def prettyName: String = "max_by"

override protected def funcName: String = "max_by"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you can remove this and replace it to prettyName.

Copy link
Contributor Author

@beliefer beliefer Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I will replace it.
But wait for #28194 merged.
Then I could update golden file.

@SparkQA
Copy link

SparkQA commented Apr 30, 2020

Test build #122129 has finished for PR 28164 at commit d549c3c.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class AuthRpcHandler extends AbstractAuthRpcHandler
  • public class SaslRpcHandler extends AbstractAuthRpcHandler
  • public abstract class AbstractAuthRpcHandler extends RpcHandler
  • class AbortableRpcFuture[T: ClassTag](val future: Future[T], onAbort: Throwable => Unit)
  • public class JavaUserDefinedScalar
  • public class SparkAvroKeyOutputFormat extends AvroKeyOutputFormat<GenericRecord>
  • static class SparkRecordWriterFactory extends RecordWriterFactory<GenericRecord>
  • class AvroDeserializer(rootAvroType: Schema, rootCatalystType: DataType, rebaseDateTime: Boolean)
  • class AvroSerializer(
  • class FMClassifierWrapperWriter(instance: FMClassifierWrapper) extends MLWriter
  • class FMClassifierWrapperReader extends MLReader[FMClassifierWrapper]
  • class FMRegressorWrapperWriter(instance: FMRegressorWrapper) extends MLWriter
  • class FMRegressorWrapperReader extends MLReader[FMRegressorWrapper]
  • class LinearRegressionWrapperWriter(instance: LinearRegressionWrapper) extends MLWriter
  • class LinearRegressionWrapperReader extends MLReader[LinearRegressionWrapper]
  • class ExecutorResourceRequest(object):
  • class ExecutorResourceRequests(object):
  • class ResourceProfile(object):
  • class ResourceProfileBuilder(object):
  • class TaskResourceRequest(object):
  • class TaskResourceRequests(object):
  • case class AggregateWithHaving(
  • abstract class CurrentTimestampLike() extends LeafExpression with CodegenFallback
  • case class CurrentTimestamp() extends CurrentTimestampLike
  • case class Now() extends CurrentTimestampLike
  • case class YearOfWeek(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
  • case class DatetimeSub(
  • case class DateAddInterval(
  • case class Extract(field: Expression, source: Expression, child: Expression)
  • case class LengthOfJsonArray(child: Expression) extends UnaryExpression
  • case class JsonObjectKeys(child: Expression) extends UnaryExpression with CodegenFallback
  • case class Rand(child: Expression, hideSeed: Boolean = false)
  • case class Randn(child: Expression, hideSeed: Boolean = false)
  • case class ShowViews(
  • class CacheManager extends Logging with AdaptiveSparkPlanHelper
  • case class AdaptiveExecutionContext(session: SparkSession, qe: QueryExecution)
  • case class ShowViewsCommand(
  • class JDBCConfiguration(
  • class ParquetReadSupport(

@SparkQA
Copy link

SparkQA commented May 1, 2020

Test build #122154 has finished for PR 28164 at commit 2cd091e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@beliefer beliefer changed the title [SPARK-31393][SQL] Show the correct alias in a more elegant way that override the prettyName [SPARK-31393][SQL] Show the correct alias in schema for expression May 1, 2020
@SparkQA
Copy link

SparkQA commented May 1, 2020

Test build #122159 has finished for PR 28164 at commit f048601.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented May 5, 2020

Test build #122300 has finished for PR 28164 at commit cc4ee4c.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • public class JavaFValueTestExample

@beliefer
Copy link
Contributor Author

beliefer commented May 5, 2020

retest this please

@SparkQA
Copy link

SparkQA commented May 5, 2020

Test build #122309 has finished for PR 28164 at commit cc4ee4c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • public class JavaFValueTestExample

@beliefer
Copy link
Contributor Author

beliefer commented May 6, 2020

cc @HyukjinKwon

@beliefer
Copy link
Contributor Author

cc @gatorsmile

@HyukjinKwon
Copy link
Member

Merged to master and branch-3.0.

HyukjinKwon pushed a commit that referenced this pull request May 12, 2020
### What changes were proposed in this pull request?
Some alias of expression can not display correctly in schema. This PR will fix them.
- `TimeWindow`
- `MaxBy`
- `MinBy`
- `UnaryMinus`
- `BitwiseCount`

This PR also fix a typo issue, please look at https://github.com/apache/spark/blob/b7cde42b04b21c9bfee6535199cf385855c15853/sql/core/src/test/scala/org/apache/spark/sql/ExpressionsSchemaSuite.scala#L142

Note:

1. `MaxBy` and `MinBy` extends `MaxMinBy` and the latter add a method `funcName` not needed.  We can reuse `prettyName` to replace `funcName`.
2. Spark SQL exists some function no elegant implementation.For example: `BitwiseCount` override the sql method show below:
`override def sql: String = s"bit_count(${child.sql})"`
I don't think it's elegant enough. Because `Expression` gives the following definitions.
```
  def sql: String = {
    val childrenSQL = children.map(_.sql).mkString(", ")
    s"$prettyName($childrenSQL)"
  }
```
By this definition, `BitwiseCount` should override `prettyName` method.

### Why are the changes needed?
Improve the implement of some expression.

### Does this PR introduce any user-facing change?
 'Yes'. This PR will let user see the correct alias in schema.

### How was this patch tested?
Jenkins test.

Closes #28164 from beliefer/elegant-pretty-name-for-function.

Lead-authored-by: beliefer <[email protected]>
Co-authored-by: gengjiaan <[email protected]>
Signed-off-by: HyukjinKwon <[email protected]>
(cherry picked from commit a89006a)
Signed-off-by: HyukjinKwon <[email protected]>
@beliefer
Copy link
Contributor Author

@HyukjinKwon Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants