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

HPCC-11151 Support xpath(‘<>’) for write #10348

Closed
wants to merge 1 commit into from

Conversation

afishbeck
Copy link
Member

@afishbeck afishbeck commented Aug 20, 2017

When #OPTION('writeInlineContent', true); is used writing a field with
XPATH('Name/<>') will output the string without XML/JSON encoding
the content. This allows users to insert arbitrary XML/JSON into
the output.

Also works with sets of strings XPATH('SetName/Name/<>').

There are 3 forms:
'<>' Writes the content without a root tag. Reading reads all
content of parent.
'Name<>' Writes the content without a tag. Reading reads the
content of the tag .
'Name/<>' Writes the content inside . Reading reads the
content of the tag .

Also fixes generated schemas to indicate locations where arbitrary
content might appear.

Signed-off-by: Anthony Fishbeck anthony.fishbeck@lexisnexis.com

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Testing:

When #OPTION('writeInlineContent', true); is used writing a field with
XPATH('Name/<>') will output the string without XML/JSON encoding
the content.  This allows users to insert arbitrary XML/JSON into
the output.

Also works with sets of strings XPATH('SetName/Name/<>').

There are 3 forms:
 '<>' Writes the content without a root tag.  Reading reads all
    content of parent.
 'Name<>' Writes the content without a <Name> tag.  Reading reads the
    content of the tag <Name>.
 'Name/<>' Writes the content inside <Name>.  Reading reads the
    content of the tag <Name>.

Also fixes generated schemas to indicate locations where arbitrary
content might appear.

Signed-off-by: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
@HPCCSmoketest
Copy link
Contributor

Automated Smoketest: ✅
Sha: 66eeb6c
Build: success
Build: success
ECL Watch: Rebuilding Site

errors warnings build time
0 75 43.914 seconds

Install hpccsystems-platform-community_6.5.0-trunk0.el7.x86_64.rpm
HPCC Start: OK

Unit tests result:

Test total passed failed errors timeout
unittest 91 91 0 0 0
wutoolTest(Dali) 19 19 0 0 0
wutoolTest(Cassandra) 19 19 0 0 0

Regression test result:

phase total pass fail
setup (hthor) 11 11 0
setup (thor) 11 11 0
setup (roxie) 11 11 0
test (hthor) 746 746 0
test (thor) 641 641 0
test (roxie) 774 774 0

HPCC Stop: OK
HPCC Uninstall: OK

@afishbeck
Copy link
Member Author

@richardkchapman you may want to take a look at where this overlapped with your dynamic typeinfo changes.
@ghalliday Can you review?

Copy link
Member

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

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

@afishbeck some initial comments. It is probably worth me reviewing it all again later because it is quite a lot to take in at once.

Main issues are utf8 encoding of strings, and main comment is using enumerations instead of byte.

s.append("><xs:annotation><xs:appinfo hpcc:keyed=\"true\"/></xs:annotation></xs:any>\n");
else
s.append("/>\n");

Copy link
Member

Choose a reason for hiding this comment

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

trivial: extra newline

@@ -302,8 +302,8 @@ typedef IArrayOf<ITypeInfo> TypeInfoArray;
interface ISchemaBuilder
{
public:
virtual void addField(const char * name, ITypeInfo & type, bool keyed) = 0;
virtual void addSetField(const char * name, const char * itemname, ITypeInfo & type) = 0;
virtual void addField(const char * name, ITypeInfo & type, bool keyed, byte contentFlags) = 0;
Copy link
Member

Choose a reason for hiding this comment

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

style: Cleaner to pass a named enumeration instead of a byte.

{
XPathContentInline = 0x01,
XPathContentNamed = 0x02,
XPathContentMixed = 0x04
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is used. Could you reuse the previous enumeration, rather than defining a new one?

break;
case type_unicode:
len = getLength(type, cur);
writer.outputUnicode(len, (UChar const *)cur, name);
//tbd
Copy link
Member

Choose a reason for hiding this comment

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

MORE: Is this going to be implemented?

@@ -1607,7 +1628,10 @@ void CResultSetCursor::writeXmlText(IXmlWriter &writer, int columnIndex, const c
case type_qstring:
len = getLength(type, cur);
rtlQStrToStrX(resultLen, resultStr, len, (const char *)cur);
writer.outputString(resultLen, resultStr, name);
if (meta.allowInlineContent && (contentFlags & XSBLD_contentInline))
writer.outputInline(resultLen, resultStr, (contentFlags & XSBLD_contentNamed) ? name : nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

Although this is output inline it will still need to be converted from iso-8859-1 codepage to utf8.

To test ensure the strings contain some latin accented characters.

@@ -10923,7 +10930,7 @@ void HqlCppTranslator::buildXmlSerializeSetValues(BuildCtx & ctx, IHqlExpression
CHqlBoundExpr boundCurElement;
cursor->buildIterateLoop(loopctx, boundCurElement, false);
OwnedHqlExpr curElement = boundCurElement.getTranslatedExpr();
buildXmlSerializeScalar(loopctx, curElement, itemName);
buildXmlSerializeScalar(loopctx, curElement, itemName, false);
Copy link
Member

Choose a reason for hiding this comment

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

The fourth parameter is a contentFlag, not a boolean. Using an enum for the parameter would have caught it.

@@ -117,6 +117,26 @@ void CommonXmlWriter::outputString(unsigned len, const char *field, const char *
}
}

void CommonXmlWriter::outputInline(unsigned len, const char *field, const char *fieldname)
Copy link
Member

Choose a reason for hiding this comment

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

minor style: Cleaner if length parameter are size32_t rather than unsigned.

@@ -3277,7 +3277,7 @@ bool CWsWorkunitsEx::onWUResult(IEspContext &context, IEspWUResultRequest &req,
const char* resultName = req.getResultName();

Owned<DataCacheElement> data;
if (!req.getBypassCachedResult())
if (0)//!req.getBypassCachedResult())
Copy link
Member

Choose a reason for hiding this comment

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

more: Is this left in by mistake?

@@ -679,11 +679,17 @@ size32_t RtlStringTypeInfo::toXML(const byte * self, const byte * selfrow, const
unsigned lenAscii;
rtlDataAttr ascii;
rtlEStrToStrX(lenAscii, ascii.refstr(), thisLength, str);
target.outputString(lenAscii, ascii.getstr(), queryScalarXPath(field));
if (field->hasInlineContentXpath())
target.outputInline(lenAscii, ascii.getstr(), field->hasNamedContentXpath() ? queryScalarXPath(field) : nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

Same issues of conversion to utf8.

target.outputUtf8(thisLength, str, queryScalarXPath(field));
if (field->hasInlineContentXpath())
{
target.outputInline(thisLength, str, field->hasNamedContentXpath() ? queryScalarXPath(field) : nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

Need to be careful about length v size. (Worth naming size variables appropriately.)

@richardkchapman
Copy link
Member

@afishbeck This seems to be stalled (and needs rebasing)

@afishbeck
Copy link
Member Author

Will reopen when I return from PTO.

@afishbeck afishbeck closed this Oct 28, 2017
@afishbeck afishbeck deleted the writeInlineXmlz branch October 7, 2022 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants