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

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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