From 0a3889b192f3d3bcf976a22fa679f6bfa56a75b0 Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Mon, 8 May 2023 13:18:31 -0700 Subject: [PATCH] account for auto allowing for leading and trailing spaces (#14224) --- web-console/src/druid-models/time/time.ts | 2 +- .../src/helpers/__snapshots__/spec-conversion.spec.ts.snap | 6 +++--- web-console/src/helpers/spec-conversion.ts | 2 +- web-console/src/utils/sql.ts | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/web-console/src/druid-models/time/time.ts b/web-console/src/druid-models/time/time.ts index bfd9e88ee28..8443f08888a 100644 --- a/web-console/src/druid-models/time/time.ts +++ b/web-console/src/druid-models/time/time.ts @@ -53,7 +53,7 @@ const MIN_NANO = MIN_MICRO * 1000; const MAX_NANO = MIN_NANO * 1000; export const AUTO_MATCHER = - /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))( ((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)$/; + /^\s*([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))( ((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)\s*$/; export const ISO_MATCHER = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))(T((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)$/; diff --git a/web-console/src/helpers/__snapshots__/spec-conversion.spec.ts.snap b/web-console/src/helpers/__snapshots__/spec-conversion.spec.ts.snap index ac4dd8655e8..a70842ee1c5 100644 --- a/web-console/src/helpers/__snapshots__/spec-conversion.spec.ts.snap +++ b/web-console/src/helpers/__snapshots__/spec-conversion.spec.ts.snap @@ -10,7 +10,7 @@ WITH "source" AS (SELECT * FROM TABLE( ) ) EXTEND ("event_ts" VARCHAR, "col1" VARCHAR, "col2" VARCHAR, "col3" VARCHAR, "col4" VARCHAR, "field1" DOUBLE, "field2" DOUBLE, "field3" DOUBLE, "field4" VARCHAR, "field5" VARCHAR, "field6" BIGINT, "field7" DOUBLE)) SELECT - TIME_FLOOR(CASE WHEN CAST("event_ts" AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST("event_ts" AS BIGINT)) ELSE TIME_PARSE("event_ts") END, 'PT1H') AS "__time", + TIME_FLOOR(CASE WHEN CAST("event_ts" AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST("event_ts" AS BIGINT)) ELSE TIME_PARSE(TRIM("event_ts")) END, 'PT1H') AS "__time", "col1", "col2", "col3", @@ -77,7 +77,7 @@ WITH "source" AS (SELECT * FROM TABLE( ) ) EXTEND ("timestamp" VARCHAR, "isRobot" VARCHAR, "channel" VARCHAR, "flags" VARCHAR, "isUnpatrolled" VARCHAR, "page" VARCHAR, "diffUrl" VARCHAR, "added" BIGINT, "comment" VARCHAR, "commentLength" BIGINT, "isNew" VARCHAR, "isMinor" VARCHAR, "delta" BIGINT, "isAnonymous" VARCHAR, "user" VARCHAR, "deltaBucket" BIGINT, "deleted" BIGINT, "namespace" VARCHAR, "cityName" VARCHAR, "countryName" VARCHAR, "regionIsoCode" VARCHAR, "metroCode" VARCHAR, "countryIsoCode" VARCHAR, "regionName" VARCHAR, "event" TYPE('COMPLEX'))) SELECT - CASE WHEN CAST("timestamp" AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST("timestamp" AS BIGINT)) ELSE TIME_PARSE("timestamp") END AS "__time", + CASE WHEN CAST("timestamp" AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST("timestamp" AS BIGINT)) ELSE TIME_PARSE(TRIM("timestamp")) END AS "__time", "isRobot", "channel", "flags", @@ -159,7 +159,7 @@ WITH "source" AS (SELECT * FROM TABLE( ) EXTEND ("timestamp" VARCHAR, "isRobot" VARCHAR, "channel" VARCHAR, "flags" VARCHAR, "isUnpatrolled" VARCHAR, "page" VARCHAR, "diffUrl" VARCHAR, "added" BIGINT, "comment" VARCHAR, "commentLength" BIGINT, "isNew" VARCHAR, "isMinor" VARCHAR, "delta" BIGINT, "isAnonymous" VARCHAR, "user" VARCHAR, "deltaBucket" BIGINT, "deleted" BIGINT, "namespace" VARCHAR, "cityName" VARCHAR, "countryName" VARCHAR, "regionIsoCode" VARCHAR, "metroCode" VARCHAR, "countryIsoCode" VARCHAR, "regionName" VARCHAR)) SELECT --:ISSUE: The spec contained transforms that could not be automatically converted. - CASE WHEN CAST("timestamp" AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST("timestamp" AS BIGINT)) ELSE TIME_PARSE("timestamp") END AS "__time", + CASE WHEN CAST("timestamp" AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST("timestamp" AS BIGINT)) ELSE TIME_PARSE(TRIM("timestamp")) END AS "__time", "isRobot", "channel", "flags", diff --git a/web-console/src/helpers/spec-conversion.ts b/web-console/src/helpers/spec-conversion.ts index 62412e7eca1..72f48c79238 100644 --- a/web-console/src/helpers/spec-conversion.ts +++ b/web-console/src/helpers/spec-conversion.ts @@ -140,7 +140,7 @@ export function convertSpecToSql(spec: any): QueryWithContext { switch (format) { case 'auto': timestampColumnType = SqlType.VARCHAR; - timeExpression = `CASE WHEN CAST(${timestampColumn} AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST(${timestampColumn} AS BIGINT)) ELSE TIME_PARSE(${timestampColumn}) END`; + timeExpression = `CASE WHEN CAST(${timestampColumn} AS BIGINT) > 0 THEN MILLIS_TO_TIMESTAMP(CAST(${timestampColumn} AS BIGINT)) ELSE TIME_PARSE(TRIM(${timestampColumn})) END`; break; case 'iso': diff --git a/web-console/src/utils/sql.ts b/web-console/src/utils/sql.ts index 4e63f4a23ca..235f8987b90 100644 --- a/web-console/src/utils/sql.ts +++ b/web-console/src/utils/sql.ts @@ -21,6 +21,8 @@ import { SqlColumn, SqlExpression, SqlFunction, SqlLiteral, SqlStar } from 'drui export function timeFormatToSql(timeFormat: string): SqlExpression | undefined { switch (timeFormat) { case 'auto': + return SqlExpression.parse('TIME_PARSE(TRIM(?))'); + case 'iso': return SqlExpression.parse('TIME_PARSE(?)');