From 6425ef4c3c799105b9c50b2e87ab0f740c8a8224 Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Mon, 17 Jul 2023 13:57:37 -0700 Subject: [PATCH] Web console: fix service view filtering on other bugs (#14597) * fix service view filter * MSQ choose best timeformat also --- web-console/src/console-application.tsx | 2 +- web-console/src/druid-models/time/time.ts | 12 ++++++++++++ .../src/views/load-data-view/load-data-view.tsx | 13 ++----------- .../input-format-step/input-format-step.tsx | 12 +++++++----- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/web-console/src/console-application.tsx b/web-console/src/console-application.tsx index 9215d65b7c4..807a71225f7 100644 --- a/web-console/src/console-application.tsx +++ b/web-console/src/console-application.tsx @@ -397,7 +397,7 @@ export class ConsoleApplication extends React.PureComponent< 'services', , diff --git a/web-console/src/druid-models/time/time.ts b/web-console/src/druid-models/time/time.ts index 8443f08888a..8b4e1adc453 100644 --- a/web-console/src/druid-models/time/time.ts +++ b/web-console/src/druid-models/time/time.ts @@ -91,3 +91,15 @@ export function possibleDruidFormatForValues(values: any[]): string | undefined return values.every(value => timeFormatMatches(format, value)); }); } + +export function chooseByBestTimestamp( + 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] + ); +} diff --git a/web-console/src/views/load-data-view/load-data-view.tsx b/web-console/src/views/load-data-view/load-data-view.tsx index 9dbf6e6eb75..df927079bec 100644 --- a/web-console/src/views/load-data-view/load-data-view.tsx +++ b/web-console/src/views/load-data-view/load-data-view.tsx @@ -74,6 +74,7 @@ import { adjustForceGuaranteedRollup, adjustId, BATCH_INPUT_FORMAT_FIELDS, + chooseByBestTimestamp, cleanSpec, computeFlattenPathsForData, CONSTANT_TIMESTAMP_SPEC, @@ -114,7 +115,6 @@ import { MAX_INLINE_DATA_LENGTH, METRIC_SPEC_FIELDS, normalizeSpec, - NUMERIC_TIME_FORMATS, possibleDruidFormatForValues, PRIMARY_PARTITION_RELATED_FORM_FIELDS, removeTimestampTransform, @@ -279,16 +279,7 @@ function getTimestampSpec(sampleResponse: SampleResponse | null): TimestampSpec }, ); - return ( - // 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... - ); + return chooseByBestTimestamp(timestampSpecs) || CONSTANT_TIMESTAMP_SPEC; } type Step = diff --git a/web-console/src/views/workbench-view/input-format-step/input-format-step.tsx b/web-console/src/views/workbench-view/input-format-step/input-format-step.tsx index 0de752f9019..7e5064867a3 100644 --- a/web-console/src/views/workbench-view/input-format-step/input-format-step.tsx +++ b/web-console/src/views/workbench-view/input-format-step/input-format-step.tsx @@ -26,6 +26,7 @@ import { AutoForm, CenterMessage, LearnMore, Loader } from '../../../components' import type { InputFormat, InputSource } from '../../../druid-models'; import { BATCH_INPUT_FORMAT_FIELDS, + chooseByBestTimestamp, DETECTION_TIMESTAMP_SPEC, guessColumnTypeFromSampleResponse, guessIsArrayFromSampleResponse, @@ -40,7 +41,6 @@ import { deepSet, EMPTY_ARRAY, filterMap, - findMap, timeFormatToSql, } from '../../../utils'; import type { SampleResponse, SampleSpec } from '../../../utils/sampler'; @@ -58,6 +58,7 @@ export interface InputFormatAndMore { interface PossibleTimeExpression { column: string; + format: string; timeExpression: SqlExpression; } @@ -116,9 +117,8 @@ export const InputFormatStep = React.memo(function InputFormatStep(props: InputF let possibleTimeExpression: PossibleTimeExpression | undefined; if (previewSampleResponse) { - possibleTimeExpression = findMap( - getHeaderNamesFromSampleResponse(previewSampleResponse), - column => { + possibleTimeExpression = chooseByBestTimestamp( + filterMap(getHeaderNamesFromSampleResponse(previewSampleResponse), column => { const values = filterMap(previewSampleResponse.data, d => d.input?.[column]); const possibleDruidFormat = possibleDruidFormatForValues(values); if (!possibleDruidFormat) return; @@ -127,6 +127,7 @@ export const InputFormatStep = React.memo(function InputFormatStep(props: InputF if (column === TIME_COLUMN) { return { column, + format: '', timeExpression: C(column), }; } @@ -136,9 +137,10 @@ export const InputFormatStep = React.memo(function InputFormatStep(props: InputF return { column, + format: possibleDruidFormat, timeExpression: formatSql.fillPlaceholders([C(column)]), }; - }, + }), ); }