Skip to content

Conversation

@samelamin
Copy link
Contributor

What changes were proposed in this pull request?

Range in SQL should be case insensitive

How was this patch tested?

unit test

@samelamin samelamin changed the title [Spark-20145] Make range case insensitive [Spark-20145] Fix range case insensitive bug in SQL Mar 30, 2017
override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
case u: UnresolvedTableValuedFunction if u.functionArgs.forall(_.resolved) =>
builtinFunctions.get(u.functionName) match {
builtinFunctions.get(u.functionName.toLowerCase) match {
Copy link
Member

Choose a reason for hiding this comment

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

Does the function name is case sensitive in Hive?

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean? There are no table valued functions in Hive.

Copy link
Contributor

Choose a reason for hiding this comment

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

@samelamin you have to make this dependent on the case sensitivity setting of the analyzer. This means you will have to turn this object into case class that takes a SQLConf as its argument.

Copy link
Contributor Author

@samelamin samelamin Mar 31, 2017

Choose a reason for hiding this comment

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

ok cool thanks @hvanhovell ill amend it over the weekend. Do you know how I can run a specific set of tests on SBT?

im getting garbage collection errors when I try to run using sbt test-only form http://spark.apache.org/developer-tools.html

Copy link
Member

Choose a reason for hiding this comment

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

For example,

build/sbt "catalyst/test-only org.apache.spark.sql.catalyst.optimizer.ColumnPruningSuite"
build/sbt -Phive "hive/test-only org.apache.spark.sql.hive.execution.SQLQuerySuite"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hvanhovell instead of creating a new case class, is there a way I can reuse the UnresolvedTableValuedFunction case class and just add in the SQLConf class?

Copy link
Contributor

@hvanhovell hvanhovell Apr 2, 2017

Choose a reason for hiding this comment

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

Yeah, @gatorsmile is right. We don't do case sensitive resolution for functions. So you can ignore my comment, and undo the last change you have made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So would you like me to revert the change to the case class?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, sorry about that!

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 I can revert but how will we test it since the apply method isn't being called by the tests. They new up an unresolvedTableValuedFunction? Unless we hardcore it in unresolvedTableValuedFunction to always be case insensitive then I don't know how else to do it?

@hvanhovell
Copy link
Contributor

ok to test

@SparkQA
Copy link

SparkQA commented Mar 31, 2017

Test build #75426 has finished for PR 17487 at commit ee15dc0.

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

@samelamin samelamin changed the title [Spark-20145] Fix range case insensitive bug in SQL [Spark-20145] [WIP] Fix range case insensitive bug in SQL Mar 31, 2017
@samelamin samelamin changed the title [Spark-20145] [WIP] Fix range case insensitive bug in SQL [Spark-20145] Fix range case insensitive bug in SQL Apr 2, 2017
@samelamin
Copy link
Contributor Author

based on comments from @hvanhovell I am depending on the case sensitivity setting of the analyser. That said I had to make the functionName a var to change the value to lower case which feels like a code smell to me. I am happy with suggestions to how I can improve on it

@SparkQA
Copy link

SparkQA commented Apr 2, 2017

Test build #75453 has finished for PR 17487 at commit 407bdbf.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class UnresolvedTableValuedFunction(conf: SQLConf,

* }}}
*/
case class UnresolvedTableValuedFunction(functionName: String, functionArgs: Seq[Expression])
case class UnresolvedTableValuedFunction(conf: SQLConf,
Copy link
Contributor

Choose a reason for hiding this comment

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

@samelamin this is a moot point now, but try to avoid mutable state as much as you can. In this case it would have been better to pass the SQLConf class as a parameter to the ResolveTableValuedFunction, and deal with case-sensitivity there.

@samelamin
Copy link
Contributor Author

Ok I was planning on doing that but unfortunately all the tests don't go through the resolveTableValuedFuntion but new up an UnTableValued. I totally agree with you with regards to state. What we can do is create a method that calculates the function name inside the unresolvedTableValuedFunction which then has the dependency on the conf. How does that sound?

@SparkQA
Copy link

SparkQA commented Apr 2, 2017

Test build #75460 has finished for PR 17487 at commit ccbfcb3.

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

@samelamin
Copy link
Contributor Author

Maybe @gatorsmile or @srowen have an idea. How can I test the case insensitive unresolvedTableValuedFunction without using a var for the functionName. I'm open to all ideas folks! introducing a var just for the tests feels inheritely incorrect.

@samelamin
Copy link
Contributor Author

FYI I can squash these commits to clean up the history once we agree on how best to approach the testing

@SparkQA
Copy link

SparkQA commented Apr 2, 2017

Test build #75462 has finished for PR 17487 at commit 8bce1da.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class UnresolvedTableValuedFunction(var functionName: String, functionArgs: Seq[Expression])

@SparkQA
Copy link

SparkQA commented Apr 2, 2017

Test build #75463 has finished for PR 17487 at commit 6efb254.

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

@gatorsmile
Copy link
Member

gatorsmile commented Apr 3, 2017

@samelamin IMHO, you do not need a unit test case. We can just add end-to-end test cases. See the code changes I made in my private branch. (BTW, it would be better if you add concise comments above the code change)

To generate the new result file after you add the new queries into the .sql files, you need to run the following command.

SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "sql/test-only *SQLQueryTestSuite"

@selamin
Copy link

selamin commented Apr 3, 2017

@gatorsmile thanks so much for that, i spent over 2 hours getting that sql file correct manually! what was frustrating was after all that i had to revert my changes 😢

Atleast I know this now so it wasnt a complete waste! Anyways I updated the code to remove the vars

How does it look now folks
cc @hvanhovell

@SparkQA
Copy link

SparkQA commented Apr 3, 2017

Test build #75480 has finished for PR 17487 at commit a01aba6.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class UnresolvedTableValuedFunction(functionName: String, functionArgs: Seq[Expression])

@SparkQA
Copy link

SparkQA commented Apr 3, 2017

Test build #75481 has finished for PR 17487 at commit 406eba8.

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

@gatorsmile
Copy link
Member

LGTM cc @hvanhovell @cloud-fan

@cloud-fan
Copy link
Contributor

LGTM

@samelamin
Copy link
Contributor Author

perfect! Can it be merged then?

@rxin
Copy link
Contributor

rxin commented Apr 4, 2017

Merging in master.

@asfgit asfgit closed this in 58c9e6e Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants