[GitHub] maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip empty lines in JSON-derived DataFrames when skipParsing optimization in effect

2019-01-27 Thread GitBox
maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip 
empty lines in JSON-derived DataFrames when skipParsing optimization in effect
URL: https://github.com/apache/spark/pull/23665#discussion_r251281725
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/FailureSafeParser.scala
 ##
 @@ -55,11 +56,15 @@ class FailureSafeParser[IN](
 
   def parse(input: IN): Iterator[InternalRow] = {
 try {
- if (skipParsing) {
-   Iterator.single(InternalRow.empty)
- } else {
-   rawParser.apply(input).toIterator.map(row => toResultRow(Some(row), () 
=> null))
- }
+  if (skipParsing) {
+if (unparsedRecordIsNonEmpty(input)) {
+  Iterator.single(InternalRow.empty)
+} else {
+  Iterator.empty
+}
+  } else {
+rawParser.apply(input).toIterator.map(row => toResultRow(Some(row), () 
=> null))
+  }
 
 Review comment:
   I thought this: 
https://github.com/maropu/spark/commit/f4df9074619e6cafff679c5f22fa153727be1079
   But, you should follow other guys who are familiar this part, @HyukjinKwon 
and @MaxGekk 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip empty lines in JSON-derived DataFrames when skipParsing optimization in effect

2019-01-27 Thread GitBox
maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip 
empty lines in JSON-derived DataFrames when skipParsing optimization in effect
URL: https://github.com/apache/spark/pull/23665#discussion_r251271104
 
 

 ##
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
 ##
 @@ -2426,6 +2426,23 @@ class JsonSuite extends QueryTest with SharedSQLContext 
with TestJsonData {
 countForMalformedJSON(0, Seq(""))
   }
 
+  test("count() for non-multiline input with empty lines") {
+val withEmptyLineData = Array(Map("a" -> 1, "b" -> 2, "c" -> 3),
+  Map("a" -> 4, "b" -> 5, "c" -> 6),
+  Map("a" -> 7, "b" -> 8, "c" -> 9))
+val df = 
spark.read.json("src/test/resources/test-data/with-empty-line.json")
+// important to do this .count() first, prior to 
caching/persisting/computing/collecting, to
+// test the non-parsed-count pathway
+assert(df.count() === withEmptyLineData.length,
+   "JSON DataFrame unparsed-count should exclude whitespace-only 
lines")
+// cache and collect to check that count stays stable under those 
operations
+df.cache()
+assert(df.count() === withEmptyLineData.length,
+   "JSON DataFrame parsed-count should exclude whitespace-only lines")
+val collected = df.collect().map(_.getValuesMap(Seq("a", "b", "c")))
+assert(collected === withEmptyLineData)
 
 Review comment:
   plz check `checkAnswer`.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip empty lines in JSON-derived DataFrames when skipParsing optimization in effect

2019-01-27 Thread GitBox
maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip 
empty lines in JSON-derived DataFrames when skipParsing optimization in effect
URL: https://github.com/apache/spark/pull/23665#discussion_r251271148
 
 

 ##
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
 ##
 @@ -2426,6 +2426,23 @@ class JsonSuite extends QueryTest with SharedSQLContext 
with TestJsonData {
 countForMalformedJSON(0, Seq(""))
   }
 
+  test("count() for non-multiline input with empty lines") {
+val withEmptyLineData = Array(Map("a" -> 1, "b" -> 2, "c" -> 3),
+  Map("a" -> 4, "b" -> 5, "c" -> 6),
+  Map("a" -> 7, "b" -> 8, "c" -> 9))
+val df = 
spark.read.json("src/test/resources/test-data/with-empty-line.json")
+// important to do this .count() first, prior to 
caching/persisting/computing/collecting, to
+// test the non-parsed-count pathway
+assert(df.count() === withEmptyLineData.length,
+   "JSON DataFrame unparsed-count should exclude whitespace-only 
lines")
+// cache and collect to check that count stays stable under those 
operations
+df.cache()
 
 Review comment:
   we dont need this cache.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip empty lines in JSON-derived DataFrames when skipParsing optimization in effect

2019-01-27 Thread GitBox
maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip 
empty lines in JSON-derived DataFrames when skipParsing optimization in effect
URL: https://github.com/apache/spark/pull/23665#discussion_r251271052
 
 

 ##
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
 ##
 @@ -2426,6 +2426,23 @@ class JsonSuite extends QueryTest with SharedSQLContext 
with TestJsonData {
 countForMalformedJSON(0, Seq(""))
   }
 
+  test("count() for non-multiline input with empty lines") {
+val withEmptyLineData = Array(Map("a" -> 1, "b" -> 2, "c" -> 3),
+  Map("a" -> 4, "b" -> 5, "c" -> 6),
+  Map("a" -> 7, "b" -> 8, "c" -> 9))
+val df = 
spark.read.json("src/test/resources/test-data/with-empty-line.json")
 
 Review comment:
   plz use `testFile`. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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



[GitHub] maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip empty lines in JSON-derived DataFrames when skipParsing optimization in effect

2019-01-27 Thread GitBox
maropu commented on a change in pull request #23665: [SPARK-26745][SQL] Skip 
empty lines in JSON-derived DataFrames when skipParsing optimization in effect
URL: https://github.com/apache/spark/pull/23665#discussion_r251270647
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/FailureSafeParser.scala
 ##
 @@ -55,11 +56,15 @@ class FailureSafeParser[IN](
 
   def parse(input: IN): Iterator[InternalRow] = {
 try {
- if (skipParsing) {
-   Iterator.single(InternalRow.empty)
- } else {
-   rawParser.apply(input).toIterator.map(row => toResultRow(Some(row), () 
=> null))
- }
+  if (skipParsing) {
+if (unparsedRecordIsNonEmpty(input)) {
+  Iterator.single(InternalRow.empty)
+} else {
+  Iterator.empty
+}
+  } else {
+rawParser.apply(input).toIterator.map(row => toResultRow(Some(row), () 
=> null))
+  }
 
 Review comment:
   We need to modify this file? Since this is a issue in json stuffs, I think 
its better to handle this case in the json parser side. Can't we do handle this 
in the same way with CSV one?, e.g., 
   
https://github.com/apache/spark/blob/3a17c6a06bc4e8a6cae506a61d3d83696d378607/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/UnivocityParser.scala#L333


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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