[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-09-07 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16925035#comment-16925035
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

gparai commented on pull request #1849: DRILL-7362: COUNT(*) on JSON with outer 
list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849
 
 
   
 

This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


> COUNT(*) on JSON with outer list results in JsonParse error
> ---
>
> Key: DRILL-7362
> URL: https://issues.apache.org/jira/browse/DRILL-7362
> Project: Apache Drill
>  Issue Type: Bug
>Affects Versions: 1.16.0
>Reporter: Oleg Zinoviev
>Assignee: Oleg Zinoviev
>Priority: Major
>  Labels: ready-to-commit
> Fix For: 1.17.0
>
>
> Count from a JSON file with a outer array results in JsonParseException: 
> Cannot read from the middle of a record. Current token was START_ARRAY.
> P.S. A simple select from such file works normally.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)


[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-09-03 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16921603#comment-16921603
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

vvysotskyi commented on pull request #1849: DRILL-7362: COUNT(*) on JSON with 
outer list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849#discussion_r320344193
 
 

 ##
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/json/reader/BaseJsonReader.java
 ##
 @@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.store.easy.json.reader;
+
+import com.fasterxml.jackson.core.JsonToken;
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter;
+
+import java.io.IOException;
+
+/**
+ * Basic reader implementation for json documents.
+ */
+public abstract class BaseJsonReader extends BaseJsonProcessor {
+
+  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(BaseJsonReader.class);
+
+  /**
+   * Describes whether or not this reader can unwrap a single root array record
+   * and treat it like a set of distinct records.
+   */
+  private final boolean skipOuterList;
+
+  /**
+   * Whether the reader is currently in a situation where we are unwrapping an
+   * outer list.
+   */
+  private boolean inOuterList;
+
+  public BaseJsonReader(DrillBuf workBuf, boolean enableNanInf, boolean 
enableEscapeAnyChar, boolean skipOuterList) {
+super(workBuf, enableNanInf, enableEscapeAnyChar);
+this.skipOuterList = skipOuterList;
+  }
+
+  @Override
+  public ReadState write(ComplexWriter writer) throws IOException {
+
+ReadState readState = null;
 
 Review comment:
   This variable may be moved inside try block to the place where it is 
assigned.
 

This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


> COUNT(*) on JSON with outer list results in JsonParse error
> ---
>
> Key: DRILL-7362
> URL: https://issues.apache.org/jira/browse/DRILL-7362
> Project: Apache Drill
>  Issue Type: Bug
>Affects Versions: 1.16.0
>Reporter: Oleg Zinoviev
>Assignee: Oleg Zinoviev
>Priority: Major
> Fix For: 1.17.0
>
>
> Count from a JSON file with a outer array results in JsonParseException: 
> Cannot read from the middle of a record. Current token was START_ARRAY.
> P.S. A simple select from such file works normally.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)


[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-09-03 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16921605#comment-16921605
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

vvysotskyi commented on pull request #1849: DRILL-7362: COUNT(*) on JSON with 
outer list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849#discussion_r320351497
 
 

 ##
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/json/reader/BaseJsonReader.java
 ##
 @@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.store.easy.json.reader;
+
+import com.fasterxml.jackson.core.JsonToken;
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter;
+
+import java.io.IOException;
+
+/**
+ * Basic reader implementation for json documents.
+ */
+public abstract class BaseJsonReader extends BaseJsonProcessor {
+
+  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(BaseJsonReader.class);
+
+  /**
+   * Describes whether or not this reader can unwrap a single root array record
+   * and treat it like a set of distinct records.
+   */
+  private final boolean skipOuterList;
+
+  /**
+   * Whether the reader is currently in a situation where we are unwrapping an
+   * outer list.
+   */
+  private boolean inOuterList;
+
+  public BaseJsonReader(DrillBuf workBuf, boolean enableNanInf, boolean 
enableEscapeAnyChar, boolean skipOuterList) {
+super(workBuf, enableNanInf, enableEscapeAnyChar);
+this.skipOuterList = skipOuterList;
+  }
+
+  @Override
+  public ReadState write(ComplexWriter writer) throws IOException {
+
+ReadState readState = null;
+try {
+  JsonToken t = lastSeenJsonToken;
+  if (t == null || t == JsonToken.END_OBJECT) {
+t = parser.nextToken();
+  }
+  while (!parser.hasCurrentToken() && !parser.isClosed()) {
+t = parser.nextToken();
+  }
+  lastSeenJsonToken = null;
+
+  if (parser.isClosed()) {
+return ReadState.END_OF_STREAM;
+  }
+
+  readState = writeToVector(writer, t);
+
+  switch (readState) {
+case END_OF_STREAM:
+  break;
+case WRITE_SUCCEED:
+  break;
+default:
+  throw getExceptionWithContext(UserException.dataReadError(), 
null).message(
+"Failure while reading JSON. (Got an invalid read state %s )", 
readState.toString())
+.build(logger);
+  }
+} catch (com.fasterxml.jackson.core.JsonParseException ex) {
+  if (ignoreJSONParseError()) {
+if (processJSONException() == 
JsonExceptionProcessingState.END_OF_STREAM) {
+  return ReadState.JSON_RECORD_PARSE_EOF_ERROR;
+} else {
+  return ReadState.JSON_RECORD_PARSE_ERROR;
+}
+  } else {
+throw ex;
+  }
+}
+return readState;
+  }
+
+
+  private ReadState writeToVector(ComplexWriter writer, JsonToken t)
+throws IOException {
+
+switch (t) {
+  case START_OBJECT:
+writeDocument(writer, t);
+break;
+  case START_ARRAY:
+if (inOuterList) {
+  throw createDocumentTopLevelException();
+}
+
+if (skipOuterList) {
+  t = parser.nextToken();
+  if (t == JsonToken.START_OBJECT) {
+inOuterList = true;
+writeDocument(writer, t);
+  } else {
+throw createDocumentTopLevelException();
+  }
+
+} else {
+  writeDocument(writer, t);
+}
+break;
+  case END_ARRAY:
+
+if (inOuterList) {
+  confirmLast();
+  return ReadState.END_OF_STREAM;
+} else {
+  throw getExceptionWithContext(UserException.dataReadError(), 
null).message(
+"Failure while parsing JSON.  Ran across unexpected %s.", 
JsonToken.END_ARRAY).build(logger);
+}
+
+  case NOT_AVAILABLE:
+return ReadState.END_OF_STREAM;
+  default:
+throw getExceptionWithContext(UserException.dataReadError(), null)
+

[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-09-03 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16921606#comment-16921606
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

vvysotskyi commented on pull request #1849: DRILL-7362: COUNT(*) on JSON with 
outer list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849#discussion_r320269096
 
 

 ##
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/json/reader/BaseJsonReader.java
 ##
 @@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.store.easy.json.reader;
+
+import com.fasterxml.jackson.core.JsonToken;
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter;
+
+import java.io.IOException;
+
+/**
+ * Basic reader implementation for json documents.
+ */
+public abstract class BaseJsonReader extends BaseJsonProcessor {
+
+  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(BaseJsonReader.class);
 
 Review comment:
   Please use imports instead of fully qualifying classes.
 

This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


> COUNT(*) on JSON with outer list results in JsonParse error
> ---
>
> Key: DRILL-7362
> URL: https://issues.apache.org/jira/browse/DRILL-7362
> Project: Apache Drill
>  Issue Type: Bug
>Affects Versions: 1.16.0
>Reporter: Oleg Zinoviev
>Assignee: Oleg Zinoviev
>Priority: Major
> Fix For: 1.17.0
>
>
> Count from a JSON file with a outer array results in JsonParseException: 
> Cannot read from the middle of a record. Current token was START_ARRAY.
> P.S. A simple select from such file works normally.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)


[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-09-03 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16921604#comment-16921604
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

vvysotskyi commented on pull request #1849: DRILL-7362: COUNT(*) on JSON with 
outer list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849#discussion_r320397567
 
 

 ##
 File path: 
exec/java-exec/src/test/java/org/apache/drill/exec/store/json/TestJsonRecordReader.java
 ##
 @@ -261,4 +261,18 @@ public void 
testNotCountingQueryNotSkippingInvalidJSONRecords()
 }
 throw new Exception("testNotCountingQueryNotSkippingInvalidJSONRecords");
   }
+
+  @Test
+  @Category(UnlikelyTest.class)
+  // See DRILL-7362
+  /* Test for CountingJSONReader */
+  public void testContainingArrayCount() throws Exception {
+testBuilder()
+  .sqlQuery("select count(*) as cnt from cp.`store/json/listdoc.json`")
+  .unOrdered()
+  .baselineColumns("cnt")
+  .baselineValues(2L)
+.build()
 
 Review comment:
   Please fix formatting and use `.go()` instead of `.build().run();`.
 

This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


> COUNT(*) on JSON with outer list results in JsonParse error
> ---
>
> Key: DRILL-7362
> URL: https://issues.apache.org/jira/browse/DRILL-7362
> Project: Apache Drill
>  Issue Type: Bug
>Affects Versions: 1.16.0
>Reporter: Oleg Zinoviev
>Assignee: Oleg Zinoviev
>Priority: Major
> Fix For: 1.17.0
>
>
> Count from a JSON file with a outer array results in JsonParseException: 
> Cannot read from the middle of a record. Current token was START_ARRAY.
> P.S. A simple select from such file works normally.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)


[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-09-03 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16921305#comment-16921305
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

oleg-zinovev commented on issue #1849: DRILL-7362: COUNT(*) on JSON with outer 
list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849#issuecomment-527395687
 
 
   @vvysotskyi 
   Can you review, please?  I tried to fix your comments.
   
   Also, thank you for the information on task management in jira - it looks 
like the last time I didn’t read the guidelines to the end (Also thanks to the 
@arina-ielchiieva for fixing jira task for me)
 

This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


> COUNT(*) on JSON with outer list results in JsonParse error
> ---
>
> Key: DRILL-7362
> URL: https://issues.apache.org/jira/browse/DRILL-7362
> Project: Apache Drill
>  Issue Type: Bug
>Affects Versions: 1.16.0
>Reporter: Oleg Zinoviev
>Assignee: Oleg Zinoviev
>Priority: Major
> Fix For: 1.17.0
>
>
> Count from a JSON file with a outer array results in JsonParseException: 
> Cannot read from the middle of a record. Current token was START_ARRAY.
> P.S. A simple select from such file works normally.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)


[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-08-29 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16918636#comment-16918636
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

vvysotskyi commented on issue #1849: DRILL-7362: COUNT(*) on JSON with outer 
list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849#issuecomment-526189826
 
 
   @oleg-zinovev, thanks for fixing this issue! 
   Could you please reuse code from `JsonReader` class - for example, move 
required code to the parent class and extend classes which share the code. 
Also, you have added some additional parameters to the constructor, which may 
be omitted since they always have the same value.
   Please update the test case to check the returned result.
   
   One more thing - please assign Jira to yourself and mark it as "In progress" 
when you are starting working on it, and change its state to "Reviewable" when 
PR is opened (Thanks to @arina-ielchiieva  for doing these things for you).
   
   For more details, connected with the development process, please refer to 
https://drill.apache.org/docs/apache-drill-contribution-guidelines/.
 

This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


> COUNT(*) on JSON with outer list results in JsonParse error
> ---
>
> Key: DRILL-7362
> URL: https://issues.apache.org/jira/browse/DRILL-7362
> Project: Apache Drill
>  Issue Type: Bug
>Affects Versions: 1.16.0
>Reporter: Oleg Zinoviev
>Assignee: Oleg Zinoviev
>Priority: Major
> Fix For: 1.17.0
>
>
> Count from a JSON file with a outer array results in JsonParseException: 
> Cannot read from the middle of a record. Current token was START_ARRAY.
> P.S. A simple select from such file works normally.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)


[jira] [Commented] (DRILL-7362) COUNT(*) on JSON with outer list results in JsonParse error

2019-08-29 Thread ASF GitHub Bot (Jira)


[ 
https://issues.apache.org/jira/browse/DRILL-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16918550#comment-16918550
 ] 

ASF GitHub Bot commented on DRILL-7362:
---

oleg-zinovev commented on pull request #1849: DRILL-7362: COUNT(*) on JSON with 
outer list results in JsonParse error
URL: https://github.com/apache/drill/pull/1849
 
 
   Fix for CountingJsonReader to support json file with list in content.
   
   P.S. At the moment, it contains a lot of C from JsonReader class. I can 
provide another solution that adds a counting mode to the JsonReader itself.
 

This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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


> COUNT(*) on JSON with outer list results in JsonParse error
> ---
>
> Key: DRILL-7362
> URL: https://issues.apache.org/jira/browse/DRILL-7362
> Project: Apache Drill
>  Issue Type: Bug
>Reporter: Oleg Zinoviev
>Priority: Major
>
> Count from a JSON file with a outer array results in JsonParseException: 
> Cannot read from the middle of a record. Current token was START_ARRAY.
> P.S. A simple select from such file works normally.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)