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

HCK-5631: fix handle of multiple sample data for map properties #127

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
11 changes: 10 additions & 1 deletion reverse_engineering/helpers/filterComplexUdt.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ module.exports = (_) => {

return handlerRecords.some(record => record === undefined) ? [] : handlerRecords;
};

const handleMap = ({ properties, records }) => {
return Object.entries(properties).reduce((result, [propertyName, propertyValue]) => {
return {
...result,
[propertyName]: filterUdt(propertyValue?.properties, records?.[propertyName])
}
}, {});
};

const filterUdt = (properties, records) => {
if (!_.isPlainObject(records)) {
Expand All @@ -45,7 +54,7 @@ module.exports = (_) => {
} else if (type === 'map' && propertyValue.properties) {
return {
...records,
[recordName]: filterUdt(propertyValue.properties, recordValues),
[recordName]: handleMap({ properties: propertyValue.properties, records: recordValues }),
}
}

Expand Down
18 changes: 16 additions & 2 deletions reverse_engineering/typesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = (_) => {
const keyData = (column.info || column.type.info)[0];
const valueData = (column.info || column.type.info)[1];
const handledKeyData = getColumnType(keyData);
const properties = getProperties(valueData, sample, udtHash);
const properties = getMapProperties({ valueData, sample, udtHash });
const keySubtype = handledKeyData.mode
? { keySubtype: handledKeyData.mode }
: {};
Expand Down Expand Up @@ -176,10 +176,24 @@ module.exports = (_) => {
const name = handledValueData.refName || defaultColumnName;

return {
[name]: _.omit(handledValueData, 'refName')
[name]: _.omit(handledValueData, 'refName'),
};
};

const getMapProperties = ({ valueData, sample, udtHash }) => {
const properties = getProperties(valueData, sample, udtHash);
const propertyPairs = Object.entries(properties);
const uniqueProperties = _.uniqWith(
propertyPairs,
([, propertyA], [, propertyB]) =>
propertyA.type === propertyB.type &&
propertyA.$ref === propertyB.$ref &&
propertyA.mode === propertyB.mode
);

return Object.fromEntries(uniqueProperties);
};

const getJsonType = (type) => {
switch (type) {
case "smallint":
Expand Down