This is an automated email from the ASF dual-hosted git repository.
olabusayo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new 252f17c60 Add tunable to control UpStep resolving to arrays
252f17c60 is described below
commit 252f17c60d334b68f1036c126033823400aaeff5
Author: olabusayoT <[email protected]>
AuthorDate: Tue Nov 5 13:30:17 2024 -0500
Add tunable to control UpStep resolving to arrays
- Introduced `allowLastUpStepToResolveToArray` tunable and
deprecatedLastUpStepToResolveToArray warning
- Deprecated behavior of `UpStep` resolving to an array, SDWs if used; SDE
is tunable is false
- refactor UpStepExpression.compiledDPath for simplicity and clarity
- move checkIfTargetIsLastStepAndArray to UpStepExpression, as it's only
relevant to ..
- Updated related tests
DAFFODIL-2939
---
.../org/apache/daffodil/core/dpath/Expression.scala | 21 +++++++++++++++++----
.../daffodil/runtime1/dpath/UpDownMoves.scala | 5 +++++
.../resources/org/apache/daffodil/xsd/dafext.xsd | 10 ++++++++++
.../tresys-contributed/bitFlagExpression.tdml | 3 +--
.../section15/choice_groups/choice-unparse2.tdml | 5 +++++
.../section23/dfdl_functions/Functions.tdml | 2 +-
6 files changed, 39 insertions(+), 7 deletions(-)
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
index a8634c116..408cb9a10 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
@@ -1015,17 +1015,30 @@ sealed abstract class UpStepExpression(s: String,
predArg: Option[PredicateExpre
extends StepExpression(s, predArg) {
final override lazy val compiledDPath = {
- val areAllArrays = isLastStep && stepElements.forall {
- _.isArray
- } && targetType == NodeInfo.Array
checkIfNodeIndexedLikeArray()
- if (areAllArrays) {
+ checkIfTargetIsLastStepAndArray()
+ if (isLastStep && isArray && targetType == NodeInfo.Array) {
new CompiledDPath(UpMoveArray)
} else {
new CompiledDPath(UpMove)
}
}
+ def checkIfTargetIsLastStepAndArray(): Unit = {
+ if (isLastStep && isArray) {
+ if (tunable.allowLastUpStepToResolveToArray) {
+ SDW(
+ WarnID.DeprecatedLastUpStepToResolveToArray,
+ "Last step path '..' resolving to an array is deprecated. Try
../../<array_name> instead."
+ )
+ } else {
+ SDE(
+ "Last step path '..' cannot resolve to an array. Try
../../<array_name> instead."
+ )
+ }
+ }
+ }
+
protected def stepElementDefs: Seq[DPathElementCompileInfo] = {
val res =
if (isFirstStep) {
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/dpath/UpDownMoves.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/dpath/UpDownMoves.scala
index b23d90de5..d64cff1f6 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/dpath/UpDownMoves.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/dpath/UpDownMoves.scala
@@ -50,6 +50,11 @@ case object UpMove extends RecipeOp {
}
}
+/**
+ * Deprecated; UpStep should only return a single node
+ * not an array, we're keeping it, but use of it is gated by
+ * tunable.allowLastUpStepToResolveToArray
+ */
case object UpMoveArray extends RecipeOp {
override def run(dstate: DState): Unit = {
val now = dstate.currentElement
diff --git
a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
index f82ea9b06..4b481906d 100644
--- a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
+++ b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
@@ -137,6 +137,15 @@
</xs:documentation>
</xs:annotation>
</xs:element>
+ <xs:element name="allowLastUpStepToResolveToArray" type="xs:boolean"
default="true" minOccurs="0">
+ <xs:annotation>
+ <xs:documentation>
+ When .. (UpStep) is the last step in an expression, it should
only ever return a single node,
+ not an array. If true, allow this but issue a warning. If false,
issue an SDE. Note, the value
+ of true is deprecated, and it might be ignored in future
versions.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
<xs:element name="allowSignedIntegerLength1Bit" type="xs:boolean"
default="true" minOccurs="0">
<xs:annotation>
<xs:documentation>
@@ -718,6 +727,7 @@
<xs:enumeration value="deprecatedEncodingNameUSASCII7BitPacked" />
<xs:enumeration value="deprecatedExpressionResultCoercion" />
<xs:enumeration value="deprecatedFunctionDAFError" />
+ <xs:enumeration value="deprecatedLastUpStepToResolveToArray" />
<xs:enumeration value="deprecatedPropertyDAFError" />
<xs:enumeration value="deprecatedPropertyDFDLXError" />
<xs:enumeration value="deprecatedPropertyDFDLError" />
diff --git
a/daffodil-test-ibm1/src/test/resources/test-suite/tresys-contributed/bitFlagExpression.tdml
b/daffodil-test-ibm1/src/test/resources/test-suite/tresys-contributed/bitFlagExpression.tdml
index 3cd1149e9..c50439089 100644
---
a/daffodil-test-ibm1/src/test/resources/test-suite/tresys-contributed/bitFlagExpression.tdml
+++
b/daffodil-test-ibm1/src/test/resources/test-suite/tresys-contributed/bitFlagExpression.tdml
@@ -64,7 +64,7 @@
else fn:true()
}]]></dfdl:discriminator>
<dfdl:element
- outputValueCalc='{ if (dfdl:occursIndex() eq fn:count(..)) then 0
else 1}' />
+ outputValueCalc='{ if (dfdl:occursIndex() eq
fn:count(../../ex:A1)) then 0 else 1}' />
</xs:appinfo>
</xs:annotation>
</xs:element>
@@ -191,4 +191,3 @@
</tdml:parserTestCase>
</tdml:testSuite>
-
\ No newline at end of file
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice-unparse2.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice-unparse2.tdml
index abc8eb6ff..71e486fde 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice-unparse2.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/choice-unparse2.tdml
@@ -214,6 +214,11 @@
</ex:r>
</tdml:dfdlInfoset>
</tdml:infoset>
+
+ <tdml:warnings>
+ <tdml:warning>deprecatedLastUpStepToResolveToArray</tdml:warning>
+ <tdml:warning>resolving to an array is deprecated</tdml:warning>
+ </tdml:warnings>
</tdml:unparserTestCase>
<tdml:defineSchema name="c3" elementFormDefault="unqualified">
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
index 28d26da5a..659135850 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
@@ -229,7 +229,7 @@
<xs:complexType>
<xs:sequence>
<xs:element name="i1" type="xs:int" dfdl:initiator="#:" />
- <xs:element name="count" type="xs:int" dfdl:inputValueCalc="{
fn:count(..) }"/>
+ <xs:element name="count" type="xs:int" dfdl:inputValueCalc="{
fn:count(../../ex:array) }" />
</xs:sequence>
</xs:complexType>
</xs:element>