mirror of https://github.com/apache/druid.git
account for auto allowing for leading and trailing spaces (#14224)
This commit is contained in:
parent
3c62c00d4c
commit
0a3889b192
|
@ -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)?)?)?)$/;
|
||||
|
||||
|
|
|
@ -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<json>')))
|
||||
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",
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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(?)');
|
||||
|
||||
|
|
Loading…
Reference in New Issue