Skip to content
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
55 changes: 27 additions & 28 deletions web-console/src/utils/ingestion-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ const INPUT_FORMAT_FORM_FIELDS: Field<InputFormat>[] = [
defined: (p: InputFormat) =>
((p.type === 'csv' || p.type === 'tsv') && !p.findColumnsFromHeader) || p.type === 'regex',
},
// {
// name: 'delimiter',
// type: 'string',
// defaultValue: '\t',
// defined: (p: InputFormat) => p.type === 'tsv',
// info: <>A custom delimiter for data values.</>,
// },
{
name: 'delimiter',
type: 'string',
defaultValue: '\t',
defined: (p: InputFormat) => p.type === 'tsv',
info: <>A custom delimiter for data values.</>,
},
{
name: 'listDelimiter',
type: 'string',
Expand Down Expand Up @@ -2455,34 +2455,33 @@ export function updateIngestionType(
}

export function fillInputFormat(spec: IngestionSpec, sampleData: string[]): IngestionSpec {
const inputFormat = guessInputFormat(sampleData);
if (!inputFormat) return spec;

return deepSet(spec, 'ioConfig.inputFormat', inputFormat);
return deepSet(spec, 'ioConfig.inputFormat', guessInputFormat(sampleData));
}

function guessInputFormat(sampleData: string[]): InputFormat | undefined {
const sampleDatum = sampleData[0];
if (!sampleDatum) return;
function guessInputFormat(sampleData: string[]): InputFormat {
let sampleDatum = sampleData[0];
if (sampleDatum) {
sampleDatum = String(sampleDatum); // Really ensure it is a string

if (sampleDatum.startsWith('{') && sampleDatum.endsWith('}')) {
return inputFormatFromType('json');
}
if (sampleDatum.startsWith('{') && sampleDatum.endsWith('}')) {
return inputFormatFromType('json');
}

if (sampleDatum.split('\t').length > 3) {
return inputFormatFromType('tsv', !/\t\d+\t/.test(sampleDatum));
}
if (sampleDatum.split('\t').length > 3) {
return inputFormatFromType('tsv', !/\t\d+\t/.test(sampleDatum));
}

if (sampleDatum.split(',').length > 3) {
return inputFormatFromType('csv', !/,\d+,/.test(sampleDatum));
}
if (sampleDatum.split(',').length > 3) {
return inputFormatFromType('csv', !/,\d+,/.test(sampleDatum));
}

if (sampleDatum.startsWith('PAR1')) {
return inputFormatFromType('parquet');
}
if (sampleDatum.startsWith('PAR1')) {
return inputFormatFromType('parquet');
}

if (sampleDatum.startsWith('ORC')) {
return inputFormatFromType('orc');
if (sampleDatum.startsWith('ORC')) {
return inputFormatFromType('orc');
}
}

return inputFormatFromType('regex');
Expand Down
4 changes: 1 addition & 3 deletions web-console/src/views/load-data-view/load-data-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,7 @@ export class LoadDataView extends React.PureComponent<LoadDataViewProps, LoadDat
const inputData = inputQueryState.data;

if (druidSource) {
let newSpec = fillInputFormat(spec, []);

newSpec = deepSet(newSpec, 'dataSchema.timestampSpec', {
let newSpec = deepSet(spec, 'dataSchema.timestampSpec', {
column: '__time',
format: 'iso',
});
Expand Down