make flattenSpec location adaptive (#15946)

This commit is contained in:
Vadim Ogievetsky 2024-02-22 14:07:04 -08:00 committed by GitHub
parent 8ebf237576
commit c52ddd0b86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 21 deletions

View File

@ -50,6 +50,7 @@ import {
getDimensionSpecName, getDimensionSpecName,
getDimensionSpecs, getDimensionSpecs,
} from '../dimension-spec/dimension-spec'; } from '../dimension-spec/dimension-spec';
import type { FlattenSpec } from '../flatten-spec/flatten-spec';
import type { IndexSpec } from '../index-spec/index-spec'; import type { IndexSpec } from '../index-spec/index-spec';
import { summarizeIndexSpec } from '../index-spec/index-spec'; import { summarizeIndexSpec } from '../index-spec/index-spec';
import type { InputFormat } from '../input-format/input-format'; import type { InputFormat } from '../input-format/input-format';
@ -381,6 +382,27 @@ export function getPossibleSystemFieldsForSpec(spec: Partial<IngestionSpec>): st
return getPossibleSystemFieldsForInputSource(inputSource); return getPossibleSystemFieldsForInputSource(inputSource);
} }
export function getFlattenSpec(spec: Partial<IngestionSpec>): FlattenSpec | undefined {
const inputFormat: InputFormat | undefined = deepGet(spec, 'spec.ioConfig.inputFormat');
if (!inputFormat) return;
return (
(inputFormat.type === 'kafka'
? inputFormat.valueFormat?.flattenSpec
: inputFormat.flattenSpec) || undefined
);
}
export function changeFlattenSpec(
spec: Partial<IngestionSpec>,
flattenSpec: FlattenSpec | undefined,
): Partial<IngestionSpec> {
if (deepGet(spec, 'spec.ioConfig.inputFormat.type') === 'kafka') {
return deepSet(spec, 'spec.ioConfig.inputFormat.valueFormat.flattenSpec', flattenSpec);
} else {
return deepSet(spec, 'spec.ioConfig.inputFormat.flattenSpec', flattenSpec);
}
}
export function getPossibleSystemFieldsForInputSource(inputSource: InputSource): string[] { export function getPossibleSystemFieldsForInputSource(inputSource: InputSource): string[] {
switch (inputSource.type) { switch (inputSource.type) {
case 's3': case 's3':

View File

@ -36,6 +36,7 @@ import {
DETECTION_TIMESTAMP_SPEC, DETECTION_TIMESTAMP_SPEC,
getDimensionNamesFromTransforms, getDimensionNamesFromTransforms,
getDimensionSpecName, getDimensionSpecName,
getFlattenSpec,
getSpecType, getSpecType,
getTimestampSchema, getTimestampSchema,
isDruidSource, isDruidSource,
@ -157,7 +158,7 @@ export function applyCache(sampleSpec: SampleSpec, cacheRows: CacheRows) {
data: cacheRows.map(r => JSONBig.stringify(r)).join('\n'), data: cacheRows.map(r => JSONBig.stringify(r)).join('\n'),
}); });
const flattenSpec = deepGet(sampleSpec, 'spec.ioConfig.inputFormat.flattenSpec'); const flattenSpec = getFlattenSpec(sampleSpec);
let inputFormat: InputFormat = { type: 'json', keepNullColumns: true }; let inputFormat: InputFormat = { type: 'json', keepNullColumns: true };
if (flattenSpec) { if (flattenSpec) {
inputFormat = deepSet(inputFormat, 'flattenSpec', flattenSpec); inputFormat = deepSet(inputFormat, 'flattenSpec', flattenSpec);

View File

@ -76,6 +76,7 @@ import {
adjustForceGuaranteedRollup, adjustForceGuaranteedRollup,
adjustId, adjustId,
BATCH_INPUT_FORMAT_FIELDS, BATCH_INPUT_FORMAT_FIELDS,
changeFlattenSpec,
chooseByBestTimestamp, chooseByBestTimestamp,
cleanSpec, cleanSpec,
computeFlattenPathsForData, computeFlattenPathsForData,
@ -89,6 +90,7 @@ import {
FLATTEN_FIELD_FIELDS, FLATTEN_FIELD_FIELDS,
getArrayMode, getArrayMode,
getDimensionSpecName, getDimensionSpecName,
getFlattenSpec,
getIngestionComboType, getIngestionComboType,
getIngestionImage, getIngestionImage,
getIngestionTitle, getIngestionTitle,
@ -1459,8 +1461,7 @@ export class LoadDataView extends React.PureComponent<LoadDataViewProps, LoadDat
const { columnFilter, specialColumnsOnly, parserQueryState, selectedFlattenField } = this.state; const { columnFilter, specialColumnsOnly, parserQueryState, selectedFlattenField } = this.state;
const spec = this.getEffectiveSpec(); const spec = this.getEffectiveSpec();
const inputFormat: InputFormat = deepGet(spec, 'spec.ioConfig.inputFormat') || EMPTY_OBJECT; const inputFormat: InputFormat = deepGet(spec, 'spec.ioConfig.inputFormat') || EMPTY_OBJECT;
const flattenFields: FlattenField[] = const flattenFields: FlattenField[] = getFlattenSpec(spec)?.fields || EMPTY_ARRAY;
deepGet(spec, 'spec.ioConfig.inputFormat.flattenSpec.fields') || EMPTY_ARRAY;
const canHaveNestedData = inputFormatCanProduceNestedData(inputFormat); const canHaveNestedData = inputFormatCanProduceNestedData(inputFormat);
@ -1617,13 +1618,7 @@ export class LoadDataView extends React.PureComponent<LoadDataViewProps, LoadDat
icon={IconNames.LIGHTBULB} icon={IconNames.LIGHTBULB}
text={`Auto add ${pluralIfNeeded(suggestedFlattenFields.length, 'flatten spec')}`} text={`Auto add ${pluralIfNeeded(suggestedFlattenFields.length, 'flatten spec')}`}
onClick={() => { onClick={() => {
this.updateSpec( this.updateSpec(changeFlattenSpec(spec, { fields: suggestedFlattenFields }));
deepSet(
spec,
'spec.ioConfig.inputFormat.flattenSpec.fields',
suggestedFlattenFields,
),
);
}} }}
/> />
</FormGroup> </FormGroup>
@ -1676,24 +1671,25 @@ export class LoadDataView extends React.PureComponent<LoadDataViewProps, LoadDat
initValue={selectedFlattenField.value} initValue={selectedFlattenField.value}
onClose={this.resetSelected} onClose={this.resetSelected}
onDirty={this.handleDirty} onDirty={this.handleDirty}
onApply={flattenField => onApply={flattenField => {
const flattenSpec = getFlattenSpec(spec) || {};
this.updateSpec( this.updateSpec(
deepSet( changeFlattenSpec(
spec, spec,
`spec.ioConfig.inputFormat.flattenSpec.fields.${selectedFlattenField.index}`, deepSet(flattenSpec, `fields.${selectedFlattenField.index}`, flattenField),
flattenField,
), ),
) );
} }}
showDelete={selectedFlattenField.index !== -1} showDelete={selectedFlattenField.index !== -1}
onDelete={() => onDelete={() => {
const flattenSpec = getFlattenSpec(spec) || {};
this.updateSpec( this.updateSpec(
deepDelete( changeFlattenSpec(
spec, spec,
`spec.ioConfig.inputFormat.flattenSpec.fields.${selectedFlattenField.index}`, deepDelete(flattenSpec, `fields.${selectedFlattenField.index}`),
), ),
) );
} }}
/> />
); );
} else { } else {