Skip to content

Commit

Permalink
Merge branch 'hudi-spec-fix' of github.com:Sanketika-Obsrv/obsrv-api-…
Browse files Browse the repository at this point in the history
…service into hudi-spec-fix
  • Loading branch information
SanthoshVasabhaktula committed Nov 13, 2024
2 parents c01be2a + 939893d commit 6d1cb44
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions api-service/src/controllers/DatasetUpdate/DatasetUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const datasetUpdate = async (req: Request, res: Response) => {

const mergeDraftDataset = (datasetModel: Model<any, any> | null, datasetReq: any): Record<string, any> => {

const cache_config = _.get(datasetModel, ["dataset_config", "cache_config"]) || {}
const prev_dataset_config = _.get(datasetModel, ["dataset_config"])
const currentSchema = _.get(datasetModel, 'data_schema')
const fieldsRemoved = (datasetReq.data_schema) ? getMissingFieldsInNewSchema(datasetReq.data_schema, currentSchema) : []
const dataset: Record<string, any> = {
Expand All @@ -79,8 +79,7 @@ const mergeDraftDataset = (datasetModel: Model<any, any> | null, datasetReq: any
if (datasetReq.extraction_config) dataset["extraction_config"] = datasetReq.extraction_config
if (datasetReq.dedup_config) dataset["dedup_config"] = datasetReq.dedup_config
if (datasetReq.data_schema) dataset["data_schema"] = datasetReq.data_schema
const updatedDatasetConfig = _.merge(_.get(datasetModel, "dataset_config"), { ...datasetReq.dataset_config, cache_config })
if (datasetReq.dataset_config) dataset["dataset_config"] = updatedDatasetConfig
if (datasetReq.dataset_config) dataset["dataset_config"] = { ...prev_dataset_config, ...datasetReq.dataset_config }
if (datasetReq.transformations_config || fieldsRemoved.length > 0)
dataset["transformations_config"] = mergeTransformationsConfig(_.get(datasetModel, ["transformations_config"]), datasetReq.transformations_config, fieldsRemoved)
if (datasetReq.denorm_config || fieldsRemoved.length > 0) dataset["denorm_config"] = mergeDenormConfig(_.get(datasetModel, ["denorm_config"]), datasetReq.denorm_config, fieldsRemoved)
Expand All @@ -89,20 +88,29 @@ const mergeDraftDataset = (datasetModel: Model<any, any> | null, datasetReq: any
if (datasetReq.sample_data) dataset["sample_data"] = datasetReq.sample_data
if (datasetReq.type) dataset["type"] = datasetReq.type
if (fieldsRemoved.length > 0) {
const keys_config = _.get(dataset, ["dataset_config", "keys_config"])
const keys_config = _.get(dataset["dataset_config"] ? dataset["dataset_config"] : prev_dataset_config, ["keys_config"])
let modified = false;
if (_.includes(fieldsRemoved, keys_config['data_key'])) {
modified = true;
keys_config['data_key'] = '';
}
if (_.includes(fieldsRemoved, keys_config['primary_key'])) {
keys_config['primary_key'] = '';
}
if (_.includes(fieldsRemoved, keys_config['partition_key'])) {
modified = true;
keys_config['partition_key'] = '';
}
if (_.includes(fieldsRemoved, keys_config['timestamp_key'])) {
modified = true;
keys_config['timestamp_key'] = '';
}
_.set(dataset["dataset_config"], 'keys_config', keys_config)
if (modified) {
if (dataset["dataset_config"]) {
_.set(dataset["dataset_config"], 'keys_config', keys_config)
} else {
const keys_config = _.get(prev_dataset_config, ["keys_config"])
dataset["dataset_config"] = { ...prev_dataset_config }
_.set(dataset["dataset_config"], 'keys_config', keys_config)
}
}
}
return dataset;
}
Expand Down

0 comments on commit 6d1cb44

Please sign in to comment.