[ML] Fix cloning of partition field in per-partition categorization jobs (#86635) (#86662)

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

* fixing cloned bucket span
This commit is contained in:
James Gowdy 2020-12-21 21:05:31 +00:00 committed by GitHub
parent 13f316e6be
commit 7f72933444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 21 deletions

View file

@ -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;
}
@ -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;
}
}
}

View file

@ -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 = {};
}