Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#OBS-I116: Dataset CRUD apis test fixes #202

Merged
merged 10 commits into from
Jul 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const validateRequest = (req: Request, datasetId: any) => {
const validateDataset = (dataset: any, datasetId: any, action: string) => {

if (_.isEmpty(dataset)) {
throw obsrvError(datasetId, datasetNotFound, `Dataset not found for dataset: ${dataset.id}`, "NOT_FOUND", 404)
throw obsrvError(datasetId, datasetNotFound, `Dataset not found for dataset: ${datasetId}`, "NOT_FOUND", 404)
}

if (dataset.api_version !== "v2" && _.includes(["ReadyToPublish", "Live"], action)) {
Expand All @@ -54,7 +54,7 @@ const datasetStatusTransition = async (req: Request, res: Response) => {
const { dataset_id, status } = _.get(req.body, "request");
validateRequest(req, dataset_id);

const dataset:Record<string, any> = (_.includes(liveDatasetActions, status)) ? await datasetService.getDataset(dataset_id, ["id", "status", "type"], true) : await datasetService.getDraftDataset(dataset_id, ["id", "dataset_id", "status", "type"])
const dataset:Record<string, any> = (_.includes(liveDatasetActions, status)) ? await datasetService.getDataset(dataset_id, ["id", "status", "type", "api_version"], true) : await datasetService.getDraftDataset(dataset_id, ["id", "dataset_id", "status", "type", "api_version"])
validateDataset(dataset, dataset_id, status);

switch(status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"type": {
"type": "string",
"enum": ["dataset", "master-dataset"]
"enum": ["event", "transaction", "master"]
},
"name": {
"type": "string",
Expand Down Expand Up @@ -305,7 +305,7 @@
}
},
"sample_data": {
"type": "string"
"type": "object"
},
"transformations_config": {
"type": "array",
Expand Down
4 changes: 4 additions & 0 deletions api-service/src/v2/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export const Dataset = sequelize.define("datasets", {
sample_data: {
type: DataTypes.JSON,
defaultValue: {}
},
entry_topic: {
type: DataTypes.STRING,
allowNull: false
}
}, {
tableName: "datasets",
Expand Down
8 changes: 6 additions & 2 deletions api-service/src/v2/models/DatasetDraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ export const DatasetDraft = sequelize.define("datasets_draft", {
defaultValue: "v2"
},
sample_data: {
type: DataTypes.JSON,
defaultValue: {}
type: DataTypes.JSON,
defaultValue: {}
},
entry_topic: {
type: DataTypes.STRING,
allowNull: false
}
}, {
timestamps: true,
Expand Down
32 changes: 16 additions & 16 deletions api-service/src/v2/services/TableGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class BaseTableGenerator {
* @param denorm_config
* @returns Promise<Record<string, any>[]>
*/
getAllFields = async (dataset: Record<string, any>, type: string) : Promise<Record<string, any>[]> => {
getAllFields = async (dataset: Record<string, any>, type: string): Promise<Record<string, any>[]> => {

const { data_schema, denorm_config, transformations_config} = dataset
const { data_schema, denorm_config, transformations_config } = dataset
const instance = this;
let dataFields = instance.flattenSchema(data_schema, type);
if(denorm_config.denorm_fields) {
_.map(denorm_config.denorm_fields, async (denormField) => {
if (!_.isEmpty(denorm_config.denorm_fields)) {
for (const denormField of denorm_config.denorm_fields) {
const denormDataset: any = await datasetService.getDataset(denormField.dataset_id, ["data_schema"], true);
const properties = instance.flattenSchema(denormDataset.data_schema, type);
const transformProps = _.map(properties, (prop) => {
Expand All @@ -63,21 +63,21 @@ class BaseTableGenerator {
return prop;
});
dataFields.push(...transformProps);
})
}
}
if(transformations_config) {
_.map(transformations_config, async (tf) => {
dataFields.push({
expr: "$." + tf.field_key,
name: tf.field_key,
data_type: tf.transformation_function.datatype,
arrival_format: tf.transformation_function.datatype,
type: tf.transformation_function.datatype
})
})
if (!_.isEmpty(transformations_config)) {
const transformationFields = _.map(transformations_config, (tf) => ({
expr: "$." + tf.field_key,
name: tf.field_key,
data_type: tf.transformation_function.datatype,
arrival_format: tf.transformation_function.datatype,
type: tf.transformation_function.datatype
}))
const originalFields = _.differenceBy(dataFields, transformationFields, "name")
dataFields = _.concat(originalFields, transformationFields)
}
dataFields.push(rawIngestionSpecDefaults.synctsField)
_.remove(dataFields, {is_deleted: true}) // Delete all the excluded fields
_.remove(dataFields, { is_deleted: true }) // Delete all the excluded fields
return dataFields;
}
}
Expand Down
Loading