From 32b017508e845f1fd1536ec769c29429facbc31e Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Tue, 15 Oct 2024 23:04:35 -0700 Subject: [PATCH] make spec cleaning less agro --- .../ingestion-spec/ingestion-spec.tsx | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/web-console/src/druid-models/ingestion-spec/ingestion-spec.tsx b/web-console/src/druid-models/ingestion-spec/ingestion-spec.tsx index 2071aa2c3779..289f8a1d522c 100644 --- a/web-console/src/druid-models/ingestion-spec/ingestion-spec.tsx +++ b/web-console/src/druid-models/ingestion-spec/ingestion-spec.tsx @@ -27,12 +27,12 @@ import { AutoForm, ExternalLink } from '../../components'; import { IndexSpecDialog } from '../../dialogs/index-spec-dialog/index-spec-dialog'; import { getLink } from '../../links'; import { - allowKeys, deepDelete, deepGet, deepMove, deepSet, deepSetIfUnset, + deleteKeys, EMPTY_ARRAY, EMPTY_OBJECT, filterMap, @@ -79,6 +79,11 @@ export interface IngestionSpec { readonly spec: IngestionSpecInner; readonly context?: { useConcurrentLocks?: boolean }; readonly suspended?: boolean; + + // Added by the server + readonly id?: string; + readonly groupId?: string; + readonly resource?: any; } export interface IngestionSpecInner { @@ -490,11 +495,27 @@ export function normalizeSpec(spec: Partial): IngestionSpec { } /** - * Make sure that any extra junk in the spec other than 'type', 'spec', and 'context' is removed + * This function cleans a spec that was returned by the server so that it can be re-opened in the data loader to be + * submitted again. + * For backwards compatible reasons the contents of `spec` (`dataSchema`, `ioConfig`, and `tuningConfig`) + * are duplicated at the top level. This function removes these duplicates (if needed) so that there is no confusion + * which is the authoritative copy. * @param spec - the spec to clean */ export function cleanSpec(spec: Partial): Partial { - return allowKeys(spec, ['type', 'spec', 'context', 'suspended']) as IngestionSpec; + const specSpec = spec.spec; + if ( + specSpec && + specSpec.dataSchema && + specSpec.ioConfig && + specSpec.tuningConfig && + (spec as any).dataSchema && + (spec as any).ioConfig && + (spec as any).tuningConfig + ) { + spec = deleteKeys(spec, ['dataSchema', 'ioConfig', 'tuningConfig'] as any[]); + } + return deleteKeys(spec, ['id', 'groupId', 'resource']); } export function upgradeSpec(spec: any, yolo = false): Partial {