Skip to content

Commit

Permalink
[ML] Fix cloning of partition field in per-partition categorization j…
Browse files Browse the repository at this point in the history
…obs (elastic#86635)

* [ML] Fix cloning of partition field in per-partition categorization jobs

* fixing cloned bucket span
  • Loading branch information
jgowdyelastic committed Dec 21, 2020
1 parent a4e9975 commit 59db5b4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,6 @@ export class CategorizationJobCreator extends JobCreator {
return this._categorizationAnalyzer;
}

public cloneFromExistingJob(job: Job, datafeed: Datafeed) {
this._overrideConfigs(job, datafeed);
this.createdBy = CREATED_BY_LABEL.CATEGORIZATION;
const detectors = getRichDetectors(job, datafeed, this.additionalFields, false);

const dtr = detectors[0];
if (detectors.length && dtr.agg !== null && dtr.field !== null) {
this._detectorType =
dtr.agg.id === ML_JOB_AGGREGATION.COUNT
? ML_JOB_AGGREGATION.COUNT
: ML_JOB_AGGREGATION.RARE;

const bs = job.analysis_config.bucket_span;
this.setDetectorType(this._detectorType);
// set the bucketspan back to the original value
// as setDetectorType applies a default
this.bucketSpan = bs;
}
}

public get categorizationPerPartitionField() {
return this._partitionFieldName;
}
Expand All @@ -204,4 +184,43 @@ export class CategorizationJobCreator extends JobCreator {
}
}
}

// override the setter and getter for the per-partition toggle
// so we can remove the partition field in the wizard when
// per-partition categorization is disabled.
public get perPartitionCategorization() {
return this._job_config.analysis_config.per_partition_categorization?.enabled === true;
}

public set perPartitionCategorization(enabled: boolean) {
this._initPerPartitionCategorization();
this._job_config.analysis_config.per_partition_categorization!.enabled = enabled;
if (enabled === false) {
this.categorizationPerPartitionField = null;
}
}

public cloneFromExistingJob(job: Job, datafeed: Datafeed) {
this._overrideConfigs(job, datafeed);
this.createdBy = CREATED_BY_LABEL.CATEGORIZATION;
const detectors = getRichDetectors(job, datafeed, this.additionalFields, false);

const dtr = detectors[0];
if (dtr !== undefined && dtr.agg !== null && dtr.field !== null) {
const detectorType =
dtr.agg.id === ML_JOB_AGGREGATION.COUNT
? ML_JOB_AGGREGATION.COUNT
: ML_JOB_AGGREGATION.RARE;

const bs = job.analysis_config.bucket_span;
this.setDetectorType(detectorType);
if (dtr.partitionField !== null) {
this.categorizationPerPartitionField = dtr.partitionField.id;
}

// set the bucketspan back to the original value
// as setDetectorType applies a default
this.bucketSpan = bs;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ export class JobCreator {
return JSON.stringify(this._datafeed_config, null, 2);
}

private _initPerPartitionCategorization() {
protected _initPerPartitionCategorization() {
if (this._job_config.analysis_config.per_partition_categorization === undefined) {
this._job_config.analysis_config.per_partition_categorization = {};
}
Expand Down

0 comments on commit 59db5b4

Please sign in to comment.