mattyb149 commented on a change in pull request #3253: NIFI-5938: Added ability 
to infer record schema on read from JsonTree…
URL: https://github.com/apache/nifi/pull/3253#discussion_r251552380
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/CSVReader.java
 ##########
 @@ -126,33 +131,27 @@ public void storeCsvFormat(final ConfigurationContext 
context) {
     @Override
     public RecordReader createRecordReader(final Map<String, String> 
variables, final InputStream in, final ComponentLog logger) throws IOException, 
SchemaNotFoundException {
         // Use Mark/Reset of a BufferedInputStream in case we read from the 
Input Stream for the header.
-        final BufferedInputStream bufferedIn = new BufferedInputStream(in);
-        bufferedIn.mark(1024 * 1024);
-        final RecordSchema schema = getSchema(variables, new 
NonCloseableInputStream(bufferedIn), null);
-        bufferedIn.reset();
+        in.mark(1024 * 1024);
+        final RecordSchema schema = getSchema(variables, new 
NonCloseableInputStream(in), null);
+        in.reset();
 
 Review comment:
   Looks like something funky is going on with the mark/reset. If I use the 
defaults for CSVReader (Infer Schema, don't treat first line as header), I get 
the following exception:
   
   ```
   org.apache.nifi.processor.exception.FlowFileAccessException: Could not reset 
stream from 
StandardFlowFileRecord[uuid=fb0648ce-7fc2-4507-8ecf-458fa57c03c4,claim=StandardContentClaim
 [resourceClaim=StandardResourceClaim[id=1548696073224-179, container=default, 
section=179], offset=115599, 
length=33],offset=0,name=fb0648ce-7fc2-4507-8ecf-458fa57c03c4,size=33]
        at 
org.apache.nifi.controller.repository.io.FlowFileAccessInputStream.reset(FlowFileAccessInputStream.java:153)
        at 
org.apache.nifi.controller.repository.io.TaskTerminationInputStream.reset(TaskTerminationInputStream.java:86)
        at org.apache.nifi.csv.CSVReader.createRecordReader(CSVReader.java:136)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.apache.nifi.controller.service.StandardControllerServiceInvocationHandler.invoke(StandardControllerServiceInvocationHandler.java:87)
        at com.sun.proxy.$Proxy232.createRecordReader(Unknown Source)
        at 
org.apache.nifi.processors.standard.AbstractRecordProcessor$1.process(AbstractRecordProcessor.java:126)
        at 
org.apache.nifi.controller.repository.StandardProcessSession.write(StandardProcessSession.java:2897)
        at 
org.apache.nifi.processors.standard.AbstractRecordProcessor.onTrigger(AbstractRecordProcessor.java:122)
        at 
org.apache.nifi.processor.AbstractProcessor.onTrigger(AbstractProcessor.java:27)
        at 
org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1162)
        at 
org.apache.nifi.controller.tasks.ConnectableTask.invoke(ConnectableTask.java:205)
        at 
org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:117)
        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
   Caused by: java.io.IOException: Stream has not been marked
        at 
org.apache.nifi.controller.repository.io.ContentClaimInputStream.reset(ContentClaimInputStream.java:131)
        at 
org.apache.nifi.controller.repository.io.DisableOnCloseInputStream.reset(DisableOnCloseInputStream.java:84)
        at 
org.apache.nifi.controller.repository.io.LimitedInputStream.reset(LimitedInputStream.java:123)
        at 
org.apache.nifi.controller.repository.io.DisableOnCloseInputStream.reset(DisableOnCloseInputStream.java:84)
        at 
org.apache.nifi.stream.io.ByteCountingInputStream.reset(ByteCountingInputStream.java:101)
        at java.io.FilterInputStream.reset(FilterInputStream.java:226)
        at 
org.apache.nifi.controller.repository.io.FlowFileAccessInputStream.reset(FlowFileAccessInputStream.java:151)
        ... 22 common frames omitted
   ```

----------------------------------------------------------------
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

Reply via email to