Skip to content
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
3 changes: 1 addition & 2 deletions forward_engineering/dbtProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class DbtProvider {
*/
decorateType({ columnDefinition }) {
const type = columnHelper.getTypeByProperty([], '')(columnDefinition);
const isComplexType = /^(array|struct)/i.test(type);

return isComplexType ? type.replace(/<[\s\S]+>$/, '<>') : type;
return columnHelper.clearComplexStructure({ type });
}

/**
Expand Down
21 changes: 21 additions & 0 deletions forward_engineering/helpers/columnHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,30 @@ const getDescription = (definitions, property) => {
return property.refDescription || property.description || definitionDescription;
};

/**
* @param {{ type: string }}
* @returns {string}
*/
const clearComplexStructure = ({ type }) => {
const isArray = /^array/i.test(type);
const isStruct = /^struct/i.test(type);
const isComplexType = isArray || isStruct;

if (!isComplexType) {
return type;
}

const structureRegExp = /<([\s\S]+)>$/;
const [, subType] = structureRegExp.exec(type) ?? ['', ''];
const structure = isArray ? clearComplexStructure({ type: subType }) : '';

return type.replace(structureRegExp, () => `<${structure}>`);
};

module.exports = {
getColumns,
getColumnsStatement,
getColumnStatement,
getTypeByProperty,
clearComplexStructure,
};