Skip to content

Commit

Permalink
HCK-7804: [RE] Snowflake dynamic tables (#139)
Browse files Browse the repository at this point in the history
* HCK-7804: Create a basic logic

* HCK-7804: Small enhancements

* HCK-7804: Add initialize param

* HCK-7804: fix sq warnings

* HCK-7804: Add New rules

* HCK-78094: resolve comments & improve logic

* HCK-78094: resolve comments
  • Loading branch information
Nightlngale authored Sep 18, 2024
1 parent ce15900 commit 1a21363
Show file tree
Hide file tree
Showing 6 changed files with 952 additions and 556 deletions.
19 changes: 3 additions & 16 deletions forward_engineering/configs/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,7 @@ module.exports = {
'${out_of_line_constraints}\n' +
'\t)${tableOptions};\n',
createDynamicTable:
'CREATE OR REPLACE${transient} DYNAMIC TABLE\n' +
'\t${name}\n' +
'${column_definitions}' +
'${targetLag}' +
'${warehouse}' +
'${refreshMode}' +
'${initialize}' +
'${clusterKeys}' +
'${dataRetentionTime}' +
'${maxDataExtensionTime}' +
'${comment}' +
'${tagsStatement}' +
'${selectStatement};\n',
createDynamicIcebergTable:
'CREATE DYNAMIC ICEBERG${transient} TABLE\n' +
'CREATE${orReplace}${transient} DYNAMIC${iceberg} TABLE${tableIfNotExists}\n' +
'\t${name}\n' +
'${column_definitions}' +
'${targetLag}' +
Expand All @@ -36,8 +22,9 @@ module.exports = {
'${initialize}' +
'${clusterKeys}' +
'${dataRetentionTime}' +
'${comment}' +
'${maxDataExtensionTime}' +
'${copyGrants}' +
'${comment}' +
'${tagsStatement}' +
'${selectStatement};\n',
createLikeTable: 'CREATE TABLE IF NOT EXISTS ${name} LIKE ${source_table}${tableOptions};\n',
Expand Down
13 changes: 7 additions & 6 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ module.exports = (baseProvider, options, app) => {
const schemaName = _.get(tableData, 'schemaData.schemaName');
const temporary = tableData.temporary ? ' TEMPORARY' : '';
const transient = tableData.transient && !tableData.temporary ? ' TRANSIENT' : '';
const orReplace = tableData.orReplace ? ' OR REPLACE' : '';
const tableIfNotExists = tableData.tableIfNotExists ? ' IF NOT EXISTS' : '';
const clusterKeys = !_.isEmpty(tableData.clusteringKey)
? ' CLUSTER BY (' +
(isActivated
Expand Down Expand Up @@ -327,6 +329,7 @@ module.exports = (baseProvider, options, app) => {

if (tableData.dynamic) {
const dynamicTableOptions = getDynamicTableProps({
iceberg: tableData.iceberg,
tableData,
tagsStatement,
clusterKeys,
Expand All @@ -336,11 +339,9 @@ module.exports = (baseProvider, options, app) => {
columnDefinitions,
});

const template = tableData.dynamicTableProps.iceberg
? templates.createDynamicIcebergTable
: templates.createDynamicTable;

return assignTemplates(template, {
return assignTemplates(templates.createDynamicTable, {
orReplace,
tableIfNotExists,
name: tableData.fullName,
transient,
...dynamicTableOptions,
Expand Down Expand Up @@ -747,6 +748,7 @@ module.exports = (baseProvider, options, app) => {
const getLocation = location => {
return location.namespace ? location.namespace + location.path : location.path;
};

const fileFormat = firstTab.external ? firstTab.externalFileFormat : firstTab.fileFormat;
const entityLevelCompositePrimaryKeys = keyConstraints
.filter(({ keyType }) => keyType === 'PRIMARY KEY')
Expand Down Expand Up @@ -819,7 +821,6 @@ module.exports = (baseProvider, options, app) => {
temporary: firstTab.temporary,
transient: firstTab.transient,
external: firstTab.external,
dynamic: firstTab.dynamic,
dynamicTableProps: {
iceberg: firstTab.iceberg,
warehouse: firstTab.warehouse,
Expand Down
Loading

0 comments on commit 1a21363

Please sign in to comment.