Web console: fix service view filtering on other bugs (#14597)

* fix service view filter

* MSQ choose best timeformat also
This commit is contained in:
Vadim Ogievetsky 2023-07-17 13:57:37 -07:00 committed by GitHub
parent 0e3ce0a7f7
commit 6425ef4c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 17 deletions

View File

@ -397,7 +397,7 @@ export class ConsoleApplication extends React.PureComponent<
'services', 'services',
<ServicesView <ServicesView
filters={stringToTableFilters(p.match.params.filters)} filters={stringToTableFilters(p.match.params.filters)}
onFiltersChange={viewFilterChange('tasks')} onFiltersChange={viewFilterChange('services')}
goToQuery={this.goToQuery} goToQuery={this.goToQuery}
capabilities={capabilities} capabilities={capabilities}
/>, />,

View File

@ -91,3 +91,15 @@ export function possibleDruidFormatForValues(values: any[]): string | undefined
return values.every(value => timeFormatMatches(format, value)); return values.every(value => timeFormatMatches(format, value));
}); });
} }
export function chooseByBestTimestamp<T extends { column: string; format: string }>(
candidates: T[],
): T | undefined {
return (
candidates.find(ts => ts.column === '__time') || // If there is a __time column, just pick it
candidates.find(ts => /time/i.test(ts.column) && !NUMERIC_TIME_FORMATS.includes(ts.format)) || // Prefer a suggestion that has "time" in the name and is not a numeric format
candidates.find(ts => /time/i.test(ts.column)) || // Otherwise anything that has "time" in the name
candidates.find(ts => !NUMERIC_TIME_FORMATS.includes(ts.format)) || // Use a suggestion that is not numeric
candidates[0]
);
}

View File

@ -74,6 +74,7 @@ import {
adjustForceGuaranteedRollup, adjustForceGuaranteedRollup,
adjustId, adjustId,
BATCH_INPUT_FORMAT_FIELDS, BATCH_INPUT_FORMAT_FIELDS,
chooseByBestTimestamp,
cleanSpec, cleanSpec,
computeFlattenPathsForData, computeFlattenPathsForData,
CONSTANT_TIMESTAMP_SPEC, CONSTANT_TIMESTAMP_SPEC,
@ -114,7 +115,6 @@ import {
MAX_INLINE_DATA_LENGTH, MAX_INLINE_DATA_LENGTH,
METRIC_SPEC_FIELDS, METRIC_SPEC_FIELDS,
normalizeSpec, normalizeSpec,
NUMERIC_TIME_FORMATS,
possibleDruidFormatForValues, possibleDruidFormatForValues,
PRIMARY_PARTITION_RELATED_FORM_FIELDS, PRIMARY_PARTITION_RELATED_FORM_FIELDS,
removeTimestampTransform, removeTimestampTransform,
@ -279,16 +279,7 @@ function getTimestampSpec(sampleResponse: SampleResponse | null): TimestampSpec
}, },
); );
return ( return chooseByBestTimestamp(timestampSpecs) || CONSTANT_TIMESTAMP_SPEC;
// Prefer a suggestion that has "time" in the name and is not a numeric format
timestampSpecs.find(
ts => /time/i.test(ts.column) && !NUMERIC_TIME_FORMATS.includes(ts.format),
) ||
timestampSpecs.find(ts => /time/i.test(ts.column)) || // Otherwise anything that has "time" in the name
timestampSpecs.find(ts => !NUMERIC_TIME_FORMATS.includes(ts.format)) || // Use a suggestion that is not numeric
timestampSpecs[0] || // Fall back to the first one
CONSTANT_TIMESTAMP_SPEC // Ok, empty it is...
);
} }
type Step = type Step =

View File

@ -26,6 +26,7 @@ import { AutoForm, CenterMessage, LearnMore, Loader } from '../../../components'
import type { InputFormat, InputSource } from '../../../druid-models'; import type { InputFormat, InputSource } from '../../../druid-models';
import { import {
BATCH_INPUT_FORMAT_FIELDS, BATCH_INPUT_FORMAT_FIELDS,
chooseByBestTimestamp,
DETECTION_TIMESTAMP_SPEC, DETECTION_TIMESTAMP_SPEC,
guessColumnTypeFromSampleResponse, guessColumnTypeFromSampleResponse,
guessIsArrayFromSampleResponse, guessIsArrayFromSampleResponse,
@ -40,7 +41,6 @@ import {
deepSet, deepSet,
EMPTY_ARRAY, EMPTY_ARRAY,
filterMap, filterMap,
findMap,
timeFormatToSql, timeFormatToSql,
} from '../../../utils'; } from '../../../utils';
import type { SampleResponse, SampleSpec } from '../../../utils/sampler'; import type { SampleResponse, SampleSpec } from '../../../utils/sampler';
@ -58,6 +58,7 @@ export interface InputFormatAndMore {
interface PossibleTimeExpression { interface PossibleTimeExpression {
column: string; column: string;
format: string;
timeExpression: SqlExpression; timeExpression: SqlExpression;
} }
@ -116,9 +117,8 @@ export const InputFormatStep = React.memo(function InputFormatStep(props: InputF
let possibleTimeExpression: PossibleTimeExpression | undefined; let possibleTimeExpression: PossibleTimeExpression | undefined;
if (previewSampleResponse) { if (previewSampleResponse) {
possibleTimeExpression = findMap( possibleTimeExpression = chooseByBestTimestamp(
getHeaderNamesFromSampleResponse(previewSampleResponse), filterMap(getHeaderNamesFromSampleResponse(previewSampleResponse), column => {
column => {
const values = filterMap(previewSampleResponse.data, d => d.input?.[column]); const values = filterMap(previewSampleResponse.data, d => d.input?.[column]);
const possibleDruidFormat = possibleDruidFormatForValues(values); const possibleDruidFormat = possibleDruidFormatForValues(values);
if (!possibleDruidFormat) return; if (!possibleDruidFormat) return;
@ -127,6 +127,7 @@ export const InputFormatStep = React.memo(function InputFormatStep(props: InputF
if (column === TIME_COLUMN) { if (column === TIME_COLUMN) {
return { return {
column, column,
format: '',
timeExpression: C(column), timeExpression: C(column),
}; };
} }
@ -136,9 +137,10 @@ export const InputFormatStep = React.memo(function InputFormatStep(props: InputF
return { return {
column, column,
format: possibleDruidFormat,
timeExpression: formatSql.fillPlaceholders([C(column)]), timeExpression: formatSql.fillPlaceholders([C(column)]),
}; };
}, }),
); );
} }