Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary truncation code #1341

Merged

Conversation

olabusayoT
Copy link
Contributor

@olabusayoT olabusayoT commented Oct 15, 2024

  • we were truncating and overwriting value, but we didn't actually need to since we ended up truncating again right after. Removed the unnecessary and buggy code which changed the dataValue. StringMaybeTruncateBitsUnparser.unparse does not change the dataValue, instead it changes the DOS, resulting in the value getting truncated but string-length returning the untruncated length when it's called
  • add tests

DAFFODIL-1592

@olabusayoT olabusayoT force-pushed the daf-1592-unparsingStringTruncation branch 2 times, most recently from 83893ee to 6e52733 Compare October 15, 2024 23:58
// variable-width encodings and lengthUnits characters, and lengthKind explicit
// is not supported (currently) for complex types
//
state.schemaDefinitionUnless(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to remember, is it still an SDE if it is something that just isn't supported yet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I think we usually use subset/subsetError, which is an SDE but mentions it's a "subset".

Copy link
Contributor

@jadams-tresys jadams-tresys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 assuming that SDE is the correct type of error for this.


// truncation is done by StringMaybeTruncateCharactersUnparser
eUnparser.unparse1(state, erd)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems SpecifiedLengthExplicitImplicitUnparser doesn't really do anything anymore. I wonder if it can just be greatly simplified? The binary and fixed width text cases call unparseBits which just call eUnparser.unpase1(...) (it evaluates target length but I'm not sure if that's needed anymore?). And now the non-fixed width text case also calls eUnparser.unparse1(...), just with an SDE check for complex types.

Feels like all of the real work is now moved out of this unparser and into others. Can this just be simplified to

if (text representation AND lengthUnits characters AND non fixed width AND isComplex) {
  SDE(...)
} else {
  // the child unparser inspects target length and handles truncation and padding/fill
  // nothing needs to be done in this unparser
  eUnparser.unparse1(...)
}

And literally everything else about targetLength and unparseBits goes away?

Copy link
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, possibility for removing a lot of code?

- we were truncating and overwriting value, but we didn't actually need to since we ended up truncating again right after. Removed the unnecessary and buggy code which changed the dataValue. StringMaybeTruncateBitsUnparser.unparse does not change the dataValue, instead it changes the DOS, resulting in the value getting truncated but string-length returning the untruncated length when it's called
- move subset/subsetError to ThrowsSDE trait so state has access to it
- refactor SpecifiedLengthExplicitImplicitUnparser to be more straightforward and to remove unused cruft
- add tests

DAFFODIL-1592
@olabusayoT olabusayoT force-pushed the daf-1592-unparsingStringTruncation branch from a795012 to 6eb8158 Compare November 4, 2024 21:49
@olabusayoT olabusayoT merged commit 1467784 into apache:main Nov 4, 2024
12 checks passed
@olabusayoT olabusayoT deleted the daf-1592-unparsingStringTruncation branch November 4, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants