Skip to content

Commit

Permalink
make spec cleaning less agro
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky committed Oct 16, 2024
1 parent 2e20ec4 commit 32b0175
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions web-console/src/druid-models/ingestion-spec/ingestion-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -490,11 +495,27 @@ export function normalizeSpec(spec: Partial<IngestionSpec>): 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<IngestionSpec>): Partial<IngestionSpec> {
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<IngestionSpec> {
Expand Down

0 comments on commit 32b0175

Please sign in to comment.