Skip to content

Commit

Permalink
feat: added missing options to FE script
Browse files Browse the repository at this point in the history
  • Loading branch information
chulanovskyi-bs committed Sep 26, 2024
1 parent c934e6b commit fcf3d96
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
9 changes: 9 additions & 0 deletions forward_engineering/configs/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ module.exports = {
'${warehouse}' +
'${externalVolume}' +
'${catalog}' +
'${catalogTableName}' +
'${catalogNamespace}' +
'${catalogSync}' +
'${metadataFilePath}' +
'${replaceInvalidCharacters}' +
'${autoRefresh}' +
'${storageSerializationPolicy}' +
'${baseLocation}' +
'${refreshMode}' +
'${initialize}' +
'${clusterKeys}' +
'${dataRetentionTime}' +
'${maxDataExtensionTime}' +
'${changeTracking}' +
'${defaultDdlCollation}' +
'${copyGrants}' +
'${comment}' +
'${tagsStatement}' +
Expand Down
47 changes: 27 additions & 20 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,38 +764,34 @@ module.exports = (baseProvider, options, app) => {
},

hydrateTable({ tableData, entityData, jsonSchema }) {
const keyConstraints = keyHelper.getTableKeyConstraints({ jsonSchema });
const firstTab = head(entityData) ?? {};

const schemaName = getName(firstTab.isCaseSensitive, get(tableData, 'schemaData.schemaName'));
const databaseName = getName(firstTab.isCaseSensitive, get(tableData, 'schemaData.databaseName'));
const tableName = getName(firstTab.isCaseSensitive, tableData.name);
const fullName = getFullName(databaseName, getFullName(schemaName, tableName));
const fileFormat = firstTab.external ? firstTab.externalFileFormat : firstTab.fileFormat;

const getLocation = location => {
return location.namespace ? location.namespace + location.path : location.path;
};

const fileFormat = firstTab.external ? firstTab.externalFileFormat : firstTab.fileFormat;
const keyConstraints = keyHelper.getTableKeyConstraints({ jsonSchema });

const entityLevelCompositeKeysReducer = (keys, data) => ({
...keys,
[data.name]: data.columns.map(column => {
return { name: column.name, isActivated: column.isActivated };
}),
});

const entityLevelCompositePrimaryKeys = keyConstraints
.filter(({ keyType }) => keyType === 'PRIMARY KEY')
.reduce((keys, data) => {
return {
...keys,
[data.name]: data.columns.map(column => {
return { name: column.name, isActivated: column.isActivated };
}),
};
}, {});
.reduce(entityLevelCompositeKeysReducer, {});

const entityLevelCompositeUniqueKeys = keyConstraints
.filter(({ keyType }) => keyType === 'UNIQUE')
.reduce((keys, data) => {
return {
...keys,
[data.name]: data.columns.map(column => {
return { name: column.name, isActivated: column.isActivated };
}),
};
}, {});
.reduce(entityLevelCompositeKeysReducer, {});

const compositePrimaryKeys = tableData.columnDefinitions
.filter(column => column.compositePrimaryKey)
Expand Down Expand Up @@ -842,7 +838,7 @@ module.exports = (baseProvider, options, app) => {
return {
...tableData,
fullName,
name: getName(firstTab.isCaseSensitive, tableData.name),
name: tableName,
temporary: firstTab.temporary,
transient: firstTab.transient,
external: firstTab.external,
Expand All @@ -857,11 +853,22 @@ module.exports = (baseProvider, options, app) => {
initialize: firstTab.initialize,
query: firstTab.query,
externalVolume: firstTab.externalVolume,
catalog: firstTab.catalog,
baseLocation: firstTab.baseLocation,
maxDataExtensionTime: !isNaN(firstTab.MAX_DATA_EXTENSION_TIME_IN_DAYS)
? firstTab.MAX_DATA_EXTENSION_TIME_IN_DAYS
: '',
catalog: firstTab.catalog,
catalogMgmt: firstTab.catalogMgmt,
catalogExternal: firstTab.catalogExternal,
catalogSync: firstTab.catalogSync,
storageSerializationPolicy: firstTab.storageSerializationPolicy,
changeTracking: firstTab.changeTracking,
defaultDdlCollation: firstTab.defaultDdlCollation,
catalogTableName: firstTab.catalogTableName,
catalogNamespace: firstTab.catalogNamespace,
metadataFilePath: firstTab.metadataFilePath,
replaceInvalidCharacters: firstTab.replaceInvalidCharacters,
autoRefresh: firstTab.autoRefresh,
},
selectStatement: firstTab.selectStatement,
isCaseSensitive: firstTab.isCaseSensitive,
Expand Down
20 changes: 20 additions & 0 deletions forward_engineering/helpers/tableHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ module.exports = app => {
externalVolume,
catalog,
baseLocation,
catalogSync,
storageSerializationPolicy,
changeTracking,
defaultDdlCollation,
catalogTableName,
catalogNamespace,
metadataFilePath,
replaceInvalidCharacters,
autoRefresh,
},
} = tableData;

Expand All @@ -116,6 +125,17 @@ module.exports = app => {
transient: preSpace(transient && 'TRANSIENT'),
iceberg: preSpace(iceberg && 'ICEBERG'),
dynamic: preSpace(dynamic && 'DYNAMIC'),
catalogSync: catalogSync ? `CATALOG_SYNC = '${catalogSync}'\n` : '',
storageSerializationPolicy: storageSerializationPolicy
? `STORAGE_SERIALIZATION_POLICY = ${storageSerializationPolicy}\n`
: '',
changeTracking: changeTracking ? 'CHANGE_TRACKING = TRUE\n' : '',
defaultDdlCollation: defaultDdlCollation ? `DEFAULT_DDL_COLLATION = '${defaultDdlCollation}'\n` : '',
catalogTableName: catalogTableName ? `CATALOG_TABLE_NAME = '${catalogTableName}'\n` : '',
catalogNamespace: catalogNamespace ? `CATALOG_NAMESPACE = '${catalogNamespace}'\n` : '',
metadataFilePath: metadataFilePath ? `METADATA_FILE_PATH = '${metadataFilePath}'\n` : '',
replaceInvalidCharacters: replaceInvalidCharacters ? 'REPLACE_INVALID_CHARACTERS = TRUE\n' : '',
autoRefresh: autoRefresh ? 'AUTO_REFRESH = TRUE\n' : '',
};
};

Expand Down

0 comments on commit fcf3d96

Please sign in to comment.