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

SNOW-830291: XmlParser configuration - fix default values. #567

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/global_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ exports.setJsonColumnVariantParser = function (value){
const defaultXmlParserConfiguration = {
ignoreAttributes: true,
alwaysCreateTextNode: false,
attributeNamePrefix: '@',
attributesGroupName: null
attributeNamePrefix: '@_',
attributesGroupName: false
};

// The default XML parser
Expand Down Expand Up @@ -226,10 +226,10 @@ exports.createXmlColumnVariantParserWithParameters = function (params){
/**
* Create function to parse XML using XMlParser with custom configuration.
* Parametrs that you can override:
* ignoreAttributes - default true,
* attributeNamePrefix - default '@',
* attributesGroupName - default null,
* alwaysCreateTextNode - default false
* ignoreAttributes: true,
* attributeNamePrefix: '@_',
* attributesGroupName: false,
* alwaysCreateTextNode: false
*
* @param {object} config
*/
Expand All @@ -241,7 +241,8 @@ function createXmlColumnVariantParser(config) {
parserConfiguration = {
ignoreAttributes: Util.exists(config.ignoreAttributes) ? config.ignoreAttributes : defaultXmlParserConfiguration.ignoreAttributes,
attributeNamePrefix: Util.exists(config.attributeNamePrefix) ? config.attributeNamePrefix : defaultXmlParserConfiguration.attributeNamePrefix,
attributesGroupName: Util.exists(config.attributesGroupName) ? config.attributesGroupName : defaultXmlParserConfiguration.attributesGroupName,
//For attributesGroupName null value is acceptable and mean no grouping
attributesGroupName: config.attributesGroupName !== undefined ? config.attributesGroupName : defaultXmlParserConfiguration.attributesGroupName,
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
alwaysCreateTextNode: Util.exists(config.alwaysCreateTextNode) ? config.alwaysCreateTextNode : defaultXmlParserConfiguration.alwaysCreateTextNode,
}
};
Expand Down
17 changes: 15 additions & 2 deletions test/integration/testExecute.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('Execute test - variant', function () {
}

testUtil.executeCmdAsync(connection, putVariant)
.then(()=> testUtil.executeCmdAsync(connection, copyIntoVariant))
.then(() => testUtil.executeCmdAsync(connection, copyIntoVariant))
.then(() => {
connection.execute({
sqlText: selectVariant,
Expand All @@ -231,8 +231,8 @@ describe('Execute test - variant', function () {
}
}
})
.catch((err) => done(err));
})
.catch((err) => done(err));
};
};

Expand Down Expand Up @@ -318,6 +318,19 @@ describe('Execute test - variant', function () {
assert.equal(row[TEST_COL]['node'][TEST_HEADER]['attributes'][TEST_ATTRIBUTE_CUSTOM_PREFIX + TEST_ATTRIBUTE_NAME], TEST_ATTRIBUTE_VALUE);
}
},
{
name: 'xml_with_group_attributes_group_without_prefixes',
type: 'XML',
fileExtension: '.xml',
sampleData: `<node><${TEST_HEADER} ${TEST_ATTRIBUTE_NAME}=${TEST_ATTRIBUTE_VALUE}>${TEST_XML_VAL}</${TEST_HEADER}></node>`,
ignoreAttributes: false,
attributeNamePrefix: '',
attributesGroupName: '@_',
assertionCheck: (row) => {
assert.strictEqual(row[TEST_COL]['node'][TEST_HEADER][ELEMENT_VALUE_FIELD], TEST_XML_VAL);
assert.strictEqual(row[TEST_COL]['node'][TEST_HEADER]['@_'][TEST_ATTRIBUTE_NAME], TEST_ATTRIBUTE_VALUE);
}
},
{
name: 'xml_skip_attributes',
type: 'XML',
Expand Down
2 changes: 2 additions & 0 deletions test/integration/testPutGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ describe('PUT GET test multiple files', function () {
// Run GET command
connection.execute({
sqlText: getQuery,
streamResult: true,
complete: function (err, stmt) {
if (err) {
callback(err);
Expand Down Expand Up @@ -789,6 +790,7 @@ describe('PUT GET test multiple files', function () {
// Run GET command
connection.execute({
sqlText: getQuery,
streamResult: true,
complete: function (err, stmt) {
if (err) {
callback(err);
Expand Down
Loading