Skip to content

Commit

Permalink
HCK-7254: fix FE script generation for the time unit partitioning usi…
Browse files Browse the repository at this point in the history
…ng DATE type column
  • Loading branch information
dannleed committed Jul 16, 2024
1 parent a527ec9 commit f6862d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.exports = (baseProvider, options, app) => {
externalTableOptions,
foreignKeyConstraints,
primaryKey,
properties,
},
isActivated,
) {
Expand All @@ -95,6 +96,7 @@ module.exports = (baseProvider, options, app) => {
partitioningType,
timeUnitPartitionKey,
rangeOptions,
properties,
});
const clustering = getClusteringKey(clusteringKey, isActivated);
const isExternal = tableType === 'External';
Expand Down Expand Up @@ -205,6 +207,7 @@ module.exports = (baseProvider, options, app) => {
partitioningType: viewData.partitioningType,
timeUnitPartitionKey: viewData.timeUnitPartitionKey,
rangeOptions: viewData.rangeOptions,
properties: viewData.properties,
});
const clustering = getClusteringKey(viewData.clusteringKey, isActivated);
const partitionsStatement = commentIfDeactivated(partitions, { isActivated: isPartitionActivated });
Expand Down Expand Up @@ -422,6 +425,7 @@ module.exports = (baseProvider, options, app) => {
},
}[tableOptions.format] || {},
),
properties: jsonSchema.properties,
};
},

Expand All @@ -434,7 +438,7 @@ module.exports = (baseProvider, options, app) => {
};
},

hydrateView({ viewData, entityData }) {
hydrateView({ viewData, entityData, jsonSchema }) {
const detailsTab = entityData[0];

return {
Expand All @@ -458,6 +462,7 @@ module.exports = (baseProvider, options, app) => {
enableRefresh: detailsTab.enableRefresh,
maxStaleness: detailsTab.maxStaleness,
allowNonIncrementalDefinition: detailsTab.allowNonIncrementalDefinition,
properties: jsonSchema.properties,
};
},

Expand Down
12 changes: 10 additions & 2 deletions forward_engineering/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const getPartitioningByIntegerRange = (rangeOptions = {}) => {
return `RANGE_BUCKET(${name}, GENERATE_ARRAY(${start}, ${end}${isNaN(interval) ? '' : `, ${interval}`}))`;
};

const getPartitioningByTimeUnitColumn = ({ partitionTimeColumn, properties }) => {
if (properties?.[partitionTimeColumn]?.type === 'date') {
return wrapByBackticks(partitionTimeColumn);
}

return `DATE(${wrapByBackticks(partitionTimeColumn)})`;
};

const isActivatedPartition = ({ partitioning, timeUnitPartitionKey, rangeOptions }) => {
if (partitioning === 'By time-unit column') {
return timeUnitPartitionKey?.[0]?.isActivated;
Expand All @@ -47,7 +55,7 @@ const isActivatedPartition = ({ partitioning, timeUnitPartitionKey, rangeOptions
return true;
};

const getTablePartitioning = ({ partitioning, partitioningType, timeUnitPartitionKey, rangeOptions }) => {
const getTablePartitioning = ({ partitioning, partitioningType, timeUnitPartitionKey, rangeOptions, properties }) => {
const partitionTimeColumn = timeUnitPartitionKey?.[0]?.name;

if (partitioning === 'No partitioning') {
Expand All @@ -59,7 +67,7 @@ const getTablePartitioning = ({ partitioning, partitioningType, timeUnitPartitio
}

if (partitioning === 'By time-unit column' && partitionTimeColumn) {
return `PARTITION BY DATE(${wrapByBackticks(partitionTimeColumn)})`;
return 'PARTITION BY ' + getPartitioningByTimeUnitColumn({ partitionTimeColumn, properties });
}

if (partitioning === 'By integer-range') {
Expand Down

0 comments on commit f6862d5

Please sign in to comment.