Skip to content

Conversation

@imback82
Copy link
Contributor

@imback82 imback82 commented Jul 23, 2020

What changes were proposed in this pull request?

This PR proposes to migrate the following function related commands to use UnresolvedFunc to resolve function identifier:

  • DROP FUNCTION
  • DESCRIBE FUNCTION
  • SHOW FUNCTIONS

DropFunctionStatement, DescribeFunctionStatement and ShowFunctionsStatement logical plans are replaced with DropFunction, DescribeFunction and ShowFunctions logical plans respectively, and each contains UnresolvedFunc as its child so that it can be resolved in Analyzer.

Why are the changes needed?

Migrating to the new resolution framework, which resolves UnresolvedFunc in Analyzer.

Does this PR introduce any user-facing change?

The message of exception thrown when a catalog is resolved to v2 has been merged to:
function is only supported in v1 catalog

Previously, it printed out the command used. E.g.,:
CREATE FUNCTION is only supported in v1 catalog

How was this patch tested?

Updated existing tests.

@SparkQA
Copy link

SparkQA commented Jul 23, 2020

Test build #126377 has finished for PR 29198 at commit 38756fc.

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

val pattern = Option(ctx.pattern).map(string(_))
val functionName = Option(ctx.multipartIdentifier).map(visitMultipartIdentifier)
ShowFunctionsStatement(userScope, systemScope, pattern, functionName)
val functionName = Option(ctx.multipartIdentifier)
Copy link
Contributor

@cloud-fan cloud-fan Jul 24, 2020

Choose a reason for hiding this comment

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

nit: maybe unresolvedFunc? it's not a name anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

or keep it functionName, and do

ShowFunctions(UnresolvedFunc(functionName), userScope, systemScope, pattern)

Copy link
Contributor Author

@imback82 imback82 Jul 24, 2020

Choose a reason for hiding this comment

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

Changed it to unresolvedFuncOpt since functionName in the second suggestion will be Option[Seq[String]].

}

CreateFunction(
func,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how to deal with CREATE commands yet. For now, CREATE TABLE and VIEW still use statement plans. We don't need to do lookup for CREATE commands, so UnresolvedFunnc looks weird here.

Can we keep it unchanged?

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. Will revert this change.

@SparkQA
Copy link

SparkQA commented Jul 24, 2020

Test build #126511 has finished for PR 29198 at commit 27f2fb1.

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

Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

Would it be better to briefly describe "the new resolution framework" so the reviewers can look at this quickly?

}

case _ => throw new AnalysisException(s"$sql is only supported in v1 catalog")
case _ => throw new AnalysisException("function is only supported in v1 catalog")
Copy link
Member

Choose a reason for hiding this comment

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

function -> function command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called from Analyzer.scala except for CREATE FUNCTION, so I thought more general name would be better here. But if you think function command is better here, I am happy to change it. Please let me know!

@imback82 imback82 changed the title [SPARK-32401][SQL] Migrate function related commands to new resolution framework [SPARK-32401][SQL] Migrate function related commands to use UnresolvedFunc to resolve function identifier Jul 27, 2020
@imback82
Copy link
Contributor Author

Would it be better to briefly describe "the new resolution framework" so the reviewers can look at this quickly?

Updated.

userScope: Boolean,
systemScope: Boolean,
pattern: Option[String]) extends Command {
override def children: Seq[LogicalPlan] = if (child.isDefined) { child.get :: Nil } else { Nil }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: child.toSeq

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

DropFunctionStatement(
functionName,
DropFunction(
UnresolvedFunc(functionName),
Copy link
Contributor

Choose a reason for hiding this comment

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

will analyzer give a nice error if UnresolvedFunc is left to CheckAnalysis?

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, this won't happen for now.

@cloud-fan
Copy link
Contributor

The PR itself LGTM. @viirya the new framework is to resolve SQL objects (table, view, function, etc.) in the analyzer, not at runtime in RunnableCommand.run. See v2ResolutionPlans.scala.

@SparkQA
Copy link

SparkQA commented Jul 28, 2020

Test build #126725 has finished for PR 29198 at commit c662619.

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

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 45b7212 Jul 29, 2020
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.

4 participants