[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-17 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/spark/pull/14620


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-17 Thread hvanhovell
Github user hvanhovell commented on a diff in the pull request:

https://github.com/apache/spark/pull/14620#discussion_r75091055
  
--- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala
 ---
@@ -61,5 +102,88 @@ class ParserUtilsSuite extends SparkFunSuite {
 // scalastyle:on nonascii
   }
 
-  // TODO: Add test cases for other methods in ParserUtils
+  test("command") {
+assert(command(setConfContext) == "set 
example.setting.name=setting.value")
+assert(command(showFuncContext) == "show functions foo.bar")
+assert(command(descFuncContext) == "describe function extended bar")
+assert(command(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("operationNotAllowed") {
+val errorMessage = "parse.fail.operation.not.allowed.error.message"
+val e = intercept[ParseException] {
+  operationNotAllowed(errorMessage, showFuncContext)
+}.getMessage
+assert(e.contains("Operation not allowed"))
+assert(e.contains(errorMessage))
+  }
+
+  test("checkDuplicateKeys") {
+val properties = Seq(("a", "a"), ("b", "b"), ("c", "c"))
+checkDuplicateKeys[String](properties, createDbContext)
+
+val properties2 = Seq(("a", "a"), ("b", "b"), ("a", "c"))
+val e = intercept[ParseException] {
+  checkDuplicateKeys(properties2, createDbContext)
+}.getMessage
+assert(e.contains("Found duplicate keys"))
+  }
+
+  test("source") {
+assert(source(setConfContext) == "set 
example.setting.name=setting.value")
+assert(source(showFuncContext) == "show functions foo.bar")
+assert(source(descFuncContext) == "describe function extended bar")
+assert(source(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("remainder") {
+assert(remainder(setConfContext) == "")
+assert(remainder(showFuncContext) == "")
+assert(remainder(descFuncContext) == "")
+assert(remainder(showDbsContext) == "")
+
+assert(remainder(setConfContext.SET.getSymbol) == " 
example.setting.name=setting.value")
+assert(remainder(showFuncContext.FUNCTIONS.getSymbol) == " foo.bar")
+assert(remainder(descFuncContext.EXTENDED.getSymbol) == " bar")
+assert(remainder(showDbsContext.LIKE.getSymbol) == " 
'identifier_with_wildcards'")
+  }
+
+  test("string") {
+assert(string(showDbsContext.pattern) == "identifier_with_wildcards")
+assert(string(createDbContext.comment) == "database_comment")
+
+assert(string(createDbContext.locationSpec.STRING) == "/home/user/db")
+  }
+
+  test("position") {
+assert(position(setConfContext.start) == Origin(Some(1), Some(0)))
+assert(position(showFuncContext.stop) == Origin(Some(1), Some(19)))
+assert(position(descFuncContext.describeFuncName.start) == 
Origin(Some(1), Some(27)))
+assert(position(createDbContext.locationSpec.start) == Origin(Some(3), 
Some(27)))
+assert(position(emptyContext.stop) == Origin(None, None))
+  }
+
+  test("assert") {
--- End diff --

We renamed assert into validate. So you will have to update. Sorry about 
that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-16 Thread hvanhovell
Github user hvanhovell commented on a diff in the pull request:

https://github.com/apache/spark/pull/14620#discussion_r75004875
  
--- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala
 ---
@@ -61,5 +102,87 @@ class ParserUtilsSuite extends SparkFunSuite {
 // scalastyle:on nonascii
   }
 
-  // TODO: Add test cases for other methods in ParserUtils
+  test("command") {
+assert(command(setConfContext) == "set 
example.setting.name=setting.value")
+assert(command(showFuncContext) == "show functions foo.bar")
+assert(command(descFuncContext) == "describe function extended bar")
+assert(command(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("operationNotAllowed") {
+val errorMessage = "parse.fail.operation.not.allowed.error.message"
+val e = intercept[ParseException] {
+  operationNotAllowed(errorMessage, showFuncContext)
+}.getMessage
+assert(e.contains("Operation not allowed"))
+assert(e.contains(errorMessage))
+  }
+
+  test("checkDuplicateKeys") {
+val properties = Seq(("a", "a"), ("b", "b"), ("c", "c"))
+checkDuplicateKeys[String](properties, createDbContext)
+
+val properties2 = Seq(("a", "a"), ("b", "b"), ("a", "c"))
+val e = intercept[ParseException] {
+  checkDuplicateKeys(properties2, createDbContext)
+}.getMessage
+assert(e.contains("Found duplicate keys"))
+  }
+
+  test("source") {
+assert(source(setConfContext) == "set 
example.setting.name=setting.value")
+assert(source(showFuncContext) == "show functions foo.bar")
+assert(source(descFuncContext) == "describe function extended bar")
+assert(source(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("remainder") {
+assert(remainder(setConfContext) == "")
+assert(remainder(showFuncContext) == "")
+assert(remainder(descFuncContext) == "")
+assert(remainder(showDbsContext) == "")
+
+assert(remainder(setConfContext.SET.getSymbol) == " 
example.setting.name=setting.value")
+assert(remainder(showFuncContext.FUNCTIONS.getSymbol) == " foo.bar")
+assert(remainder(descFuncContext.EXTENDED.getSymbol) == " bar")
+assert(remainder(showDbsContext.LIKE.getSymbol) == " 
'identifier_with_wildcards'")
+  }
+
+  test("string") {
+assert(string(showDbsContext.pattern) == "identifier_with_wildcards")
+assert(string(createDbContext.comment) == "database_comment")
+
+assert(string(createDbContext.locationSpec.STRING) == "/home/user/db")
+  }
+
+  test("position") {
+assert(position(setConfContext.start) == Origin(Some(1), Some(0)))
+assert(position(showFuncContext.stop) == Origin(Some(1), Some(19)))
+assert(position(descFuncContext.describeFuncName.start) == 
Origin(Some(1), Some(27)))
+assert(position(createDbContext.locationSpec.start) == Origin(Some(3), 
Some(27)))
+assert(position(emptyContext.stop) == Origin(None, None))
+  }
+
+  test("assert") {
+val f1 = { ctx: ParserRuleContext =>
+  ctx.children != null && !ctx.children.isEmpty
+}
+val message = "ParserRuleContext should not be empty."
+ParserUtils.assert(f1(showFuncContext), message, showFuncContext)
+
+val e = intercept[ParseException] {
+  ParserUtils.assert(f1(emptyContext), message, emptyContext)
+}.getMessage
+assert(e.contains(message))
+  }
+
+  test("withOrigin") {
+val ctx = createDbContext.locationSpec
+val current = CurrentOrigin.get
+val location = withOrigin(ctx) {
--- End diff --

you also need to check if the origin of location to make this a complete 
tests, e.g.:
```scala
val (location, origin) = withOrigin(ctx) {
  (string(ctx.string), CurrentOrigin.get)
}
assert(origin, Origin(Some(2), Some(37)))
```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-16 Thread hvanhovell
Github user hvanhovell commented on a diff in the pull request:

https://github.com/apache/spark/pull/14620#discussion_r75004387
  
--- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParserUtils.scala
 ---
@@ -74,7 +70,11 @@ object ParserUtils {
 
   /** Get the origin (line and position) of the token. */
   def position(token: Token): Origin = {
-Origin(Option(token.getLine), Option(token.getCharPositionInLine))
+if (token != null) {
--- End diff --

how about:
```scala
val opt = Option(token)
Origin(opt.map(_.getLine), opt.map(_.getCharPositionInLine))
```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-16 Thread hvanhovell
Github user hvanhovell commented on a diff in the pull request:

https://github.com/apache/spark/pull/14620#discussion_r74909202
  
--- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala
 ---
@@ -61,5 +102,84 @@ class ParserUtilsSuite extends SparkFunSuite {
 // scalastyle:on nonascii
   }
 
-  // TODO: Add test cases for other methods in ParserUtils
+  test("command") {
+assert(command(setConfContext) == "set 
example.setting.name=setting.value")
+assert(command(showFuncContext) == "show functions foo.bar")
+assert(command(descFuncContext) == "describe function extended bar")
+assert(command(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("operationNotAllowed") {
+val errorMessage = "parse.fail.operation.not.allowed.error.message"
+val e = intercept[ParseException] {
+  operationNotAllowed(errorMessage, showFuncContext)
+}.getMessage
+assert(e.contains("Operation not allowed"))
+assert(e.contains(errorMessage))
+  }
+
+  test("checkDuplicateKeys") {
+val properties = Seq(("a", "a"), ("b", "b"), ("c", "c"))
+checkDuplicateKeys[String](properties, createDbContext)
+
+val properties2 = Seq(("a", "a"), ("b", "b"), ("a", "c"))
+val e = intercept[ParseException] {
+  checkDuplicateKeys(properties2, createDbContext)
+}.getMessage
+assert(e.contains("Found duplicate keys"))
+  }
+
+  test("source") {
+assert(source(setConfContext) == "set 
example.setting.name=setting.value")
+assert(source(showFuncContext) == "show functions foo.bar")
+assert(source(descFuncContext) == "describe function extended bar")
+assert(source(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("remainder") {
+assert(remainder(setConfContext) == "")
+assert(remainder(showFuncContext) == "")
+assert(remainder(descFuncContext) == "")
+assert(remainder(showDbsContext) == "")
+
+assert(remainder(setConfContext.SET.getSymbol) == " 
example.setting.name=setting.value")
+assert(remainder(showFuncContext.FUNCTIONS.getSymbol) == " foo.bar")
+assert(remainder(descFuncContext.EXTENDED.getSymbol) == " bar")
+assert(remainder(showDbsContext.LIKE.getSymbol) == " 
'identifier_with_wildcards'")
+  }
+
+  test("string") {
+assert(string(showDbsContext.pattern) == "identifier_with_wildcards")
+assert(string(createDbContext.comment) == "database_comment")
+
+assert(string(createDbContext.locationSpec.STRING) == "/home/user/db")
+  }
+
+  test("position") {
+assert(position(setConfContext.start) == Origin(Some(1), Some(0)))
+assert(position(showFuncContext.stop) == Origin(Some(1), Some(19)))
+assert(position(descFuncContext.describeFuncName.start) == 
Origin(Some(1), Some(27)))
+assert(position(emptyContext.stop) == Origin(None, None))
+  }
+
+  test("assert") {
+val f1 = { ctx: ParserRuleContext =>
+  ctx.children != null && !ctx.children.isEmpty
+}
+val message = "ParserRuleContext should not be empty."
+ParserUtils.assert(f1(showFuncContext), message, showFuncContext)
+
+val e = intercept[ParseException] {
+  ParserUtils.assert(f1(emptyContext), message, emptyContext)
+}.getMessage
+assert(e.contains(message))
+  }
+
+  test("withOrigin") {
+val ctx = createDbContext.locationSpec
+val location = withOrigin(ctx) {
--- End diff --

You also need to test the actual origin, use 
`org.apache.spark.sql.catalyst.trees.CurrentOrigin.get()` for this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-15 Thread jiangxb1987
Github user jiangxb1987 commented on a diff in the pull request:

https://github.com/apache/spark/pull/14620#discussion_r74725943
  
--- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala
 ---
@@ -61,5 +88,39 @@ class ParserUtilsSuite extends SparkFunSuite {
 // scalastyle:on nonascii
   }
 
-  // TODO: Add test cases for other methods in ParserUtils
+  test("command") {
+assert(command(setConfContext) == "set 
example.setting.name=setting.value")
--- End diff --

I searched and found the function `command(stream: CharStream)` was never 
used, so I simply removed it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-12 Thread hvanhovell
Github user hvanhovell commented on a diff in the pull request:

https://github.com/apache/spark/pull/14620#discussion_r74621766
  
--- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala
 ---
@@ -61,5 +88,39 @@ class ParserUtilsSuite extends SparkFunSuite {
 // scalastyle:on nonascii
   }
 
-  // TODO: Add test cases for other methods in ParserUtils
+  test("command") {
+assert(command(setConfContext) == "set 
example.setting.name=setting.value")
--- End diff --

We can merge the both the command(..) functions in ParserUtils. Could you 
do this as part of this PR?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #14620: [SPARK-17032][SQL] Add test cases for methods in ...

2016-08-12 Thread hvanhovell
Github user hvanhovell commented on a diff in the pull request:

https://github.com/apache/spark/pull/14620#discussion_r74621246
  
--- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala
 ---
@@ -61,5 +88,39 @@ class ParserUtilsSuite extends SparkFunSuite {
 // scalastyle:on nonascii
   }
 
-  // TODO: Add test cases for other methods in ParserUtils
+  test("command") {
+assert(command(setConfContext) == "set 
example.setting.name=setting.value")
+assert(command(showFuncContext) == "show functions foo.bar")
+assert(command(descFuncContext) == "describe function extended bar")
+assert(command(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("source") {
+assert(source(setConfContext) == "set 
example.setting.name=setting.value")
+assert(source(showFuncContext) == "show functions foo.bar")
+assert(source(descFuncContext) == "describe function extended bar")
+assert(source(showDbsContext) == "show databases like 
'identifier_with_wildcards'")
+  }
+
+  test("remainder") {
+assert(remainder(setConfContext) == "")
+assert(remainder(showFuncContext) == "")
+assert(remainder(descFuncContext) == "")
+assert(remainder(showDbsContext) == "")
+
+assert(remainder(setConfContext.SET.getSymbol) == " 
example.setting.name=setting.value")
+assert(remainder(showFuncContext.FUNCTIONS.getSymbol) == " foo.bar")
+assert(remainder(descFuncContext.EXTENDED.getSymbol) == " bar")
+assert(remainder(showDbsContext.LIKE.getSymbol) == " 
'identifier_with_wildcards'")
+  }
+
+  test("string") {
+assert(string(showDbsContext.pattern) == "identifier_with_wildcards")
--- End diff --

Could you also add a test for the other `string(node: TerminalNode)` code 
path?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org