You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2021/03/19 19:57:50 UTC

[GitHub] [daffodil] stevedlawrence commented on a change in pull request #516: Added test for DAFFODIL-2486 discriminator bug.

stevedlawrence commented on a change in pull request #516:
URL: https://github.com/apache/daffodil/pull/516#discussion_r597941549



##########
File path: daffodil-test/src/test/resources/org/apache/daffodil/section07/discriminators/discriminator2.tdml
##########
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<testSuite suiteName="NameDOB"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           xmlns:fn="http://www.w3.org/2005/xpath-functions"
+           xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+           xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+           xmlns:ex="http://example.com"
+           xmlns:tns="http://example.com"
+           defaultRoundTrip="onePass">
+
+  <tdml:defineSchema name="s1">
+
+    <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+    <dfdl:format
+      ref="tns:GeneralFormat"
+      representation="text"
+      encoding="ASCII"
+      lengthKind="delimited"
+      separator=""
+      separatorPosition="infix"
+    />
+
+    <!--
+    Schema for simple CSV-like file containing 4 columns, the last of which is a date.
+
+    What makes this non-trivial is use of discriminator after the first column.
+    If we can parse a first column, then the remaining columns MUST be present, and an error
+    in parsing them should be fatal.
+
+    -->
+    <xs:element name="file" dfdl:initiator="last,first,middle,DOB%NL;%WSP*;">
+      <xs:complexType>
+        <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="postfix">
+          <xs:element name="record" maxOccurs="unbounded">

Review comment:
       +1
   
   I was curious to see if the CLI debugger would help shine some light on what's going on, and it actually was somewhat helpful now that it shows PoU's! Here's what's happening at a high level:
   
   The first time a record is parsed we create a single PoU when the record element is created. The discriminator correctly resolves that PoU.
   
   For the second and subsequent records, we actually create two PoU's when a record is parsed: one is for the record, one is for the the outer sequence (maybe related to separator suppression policy?). When the disciminator evaluates to true, it resolves only the record PoU but not the the sequence PoU. The existance of that outer PoU allows the parse to succeed and results in the left over data error.
   
   So adding a second discriminator does allow this to work, though that probably shouldn't be required.
   
   It also means that if there is an error parsing the first record, then you do get the expected error because there's only a single PoU for the first record. So whatever the solution, it's probably also worth adding a test where the error is on the first record, since there clearly is some difference in behavior between first and subsequent records right now.




-- 
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:
users@infra.apache.org