Web console: Update dqt to a version that adds quotes by default (#13243)

* update dqt

* auto quote by default
This commit is contained in:
Vadim Ogievetsky 2022-10-28 01:06:45 -07:00 committed by GitHub
parent 4775427e2c
commit 32020247d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 42 additions and 44 deletions

View File

@ -5673,7 +5673,7 @@ license_category: binary
module: web-console module: web-console
license_name: Apache License version 2.0 license_name: Apache License version 2.0
copyright: Imply Data copyright: Imply Data
version: 0.15.3 version: 0.16.1
--- ---

View File

@ -22,7 +22,7 @@
"d3-axis": "^2.1.0", "d3-axis": "^2.1.0",
"d3-scale": "^3.3.0", "d3-scale": "^3.3.0",
"d3-selection": "^2.0.0", "d3-selection": "^2.0.0",
"druid-query-toolkit": "^0.15.3", "druid-query-toolkit": "^0.16.1",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"follow-redirects": "^1.14.7", "follow-redirects": "^1.14.7",
"fontsource-open-sans": "^3.0.9", "fontsource-open-sans": "^3.0.9",
@ -8967,9 +8967,9 @@
} }
}, },
"node_modules/druid-query-toolkit": { "node_modules/druid-query-toolkit": {
"version": "0.15.3", "version": "0.16.1",
"resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.15.3.tgz", "resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.16.1.tgz",
"integrity": "sha512-AtKnmCDWSHh1+bHFs36drJAKQ60914ttF62x3wIxXbD1zoUEmwwsX4Ks2zD3SItantVS4fTj3cyjMl/c0fojpA==", "integrity": "sha512-HiovpGh1m2QTvexBX1AvQAz5ONc9sChazL0hsXl0qEvHcIQ69pksJZWXZOStBI2T9fJAXQpSUVB4DUSdE6UXmQ==",
"dependencies": { "dependencies": {
"tslib": "^2.3.1" "tslib": "^2.3.1"
}, },
@ -34591,9 +34591,9 @@
} }
}, },
"druid-query-toolkit": { "druid-query-toolkit": {
"version": "0.15.3", "version": "0.16.1",
"resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.15.3.tgz", "resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.16.1.tgz",
"integrity": "sha512-AtKnmCDWSHh1+bHFs36drJAKQ60914ttF62x3wIxXbD1zoUEmwwsX4Ks2zD3SItantVS4fTj3cyjMl/c0fojpA==", "integrity": "sha512-HiovpGh1m2QTvexBX1AvQAz5ONc9sChazL0hsXl0qEvHcIQ69pksJZWXZOStBI2T9fJAXQpSUVB4DUSdE6UXmQ==",
"requires": { "requires": {
"tslib": "^2.3.1" "tslib": "^2.3.1"
} }

View File

@ -79,7 +79,7 @@
"d3-axis": "^2.1.0", "d3-axis": "^2.1.0",
"d3-scale": "^3.3.0", "d3-scale": "^3.3.0",
"d3-selection": "^2.0.0", "d3-selection": "^2.0.0",
"druid-query-toolkit": "^0.15.3", "druid-query-toolkit": "^0.16.1",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"follow-redirects": "^1.14.7", "follow-redirects": "^1.14.7",
"fontsource-open-sans": "^3.0.9", "fontsource-open-sans": "^3.0.9",

View File

@ -24,7 +24,7 @@ describe('ingest-query-pattern', () => {
it('works', () => { it('works', () => {
const query = SqlQuery.parse(sane` const query = SqlQuery.parse(sane`
INSERT INTO "kttm-2019" INSERT INTO "kttm-2019"
WITH ext AS (SELECT * WITH "ext" AS (SELECT *
FROM TABLE( FROM TABLE(
EXTERN( EXTERN(
'{"type":"http","uris":["https://example.com/data.json.gz"]}', '{"type":"http","uris":["https://example.com/data.json.gz"]}',
@ -38,7 +38,7 @@ describe('ingest-query-pattern', () => {
agent_type, agent_type,
browser, browser,
browser_version browser_version
FROM ext FROM "ext"
PARTITIONED BY HOUR PARTITIONED BY HOUR
CLUSTERED BY 4 CLUSTERED BY 4
`); `);

View File

@ -157,7 +157,7 @@ describe('WorkbenchQuery', () => {
'[{"name":"timestamp","type":"string"}]' '[{"name":"timestamp","type":"string"}]'
) )
) )
ORDER BY FLOOR(__time TO HOUR), browser, session ORDER BY FLOOR("__time" TO HOUR), browser, session
`); `);
}); });
}); });

View File

@ -115,8 +115,8 @@ describe('spec conversion', () => {
expect(converted.queryString).toEqual(sane` expect(converted.queryString).toEqual(sane`
-- This SQL query was auto generated from an ingestion spec -- This SQL query was auto generated from an ingestion spec
REPLACE INTO wikipedia OVERWRITE ALL REPLACE INTO "wikipedia" OVERWRITE ALL
WITH source AS (SELECT * FROM TABLE( WITH "source" AS (SELECT * FROM TABLE(
EXTERN( EXTERN(
'{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}', '{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}',
'{"type":"json"}', '{"type":"json"}',
@ -148,7 +148,7 @@ describe('spec conversion', () => {
"metroCode", "metroCode",
"countryIsoCode", "countryIsoCode",
"regionName" "regionName"
FROM source FROM "source"
WHERE NOT ("channel" = 'xxx') WHERE NOT ("channel" = 'xxx')
PARTITIONED BY HOUR PARTITIONED BY HOUR
CLUSTERED BY "isRobot" CLUSTERED BY "isRobot"
@ -255,8 +255,8 @@ describe('spec conversion', () => {
expect(converted.queryString).toEqual(sane` expect(converted.queryString).toEqual(sane`
-- This SQL query was auto generated from an ingestion spec -- This SQL query was auto generated from an ingestion spec
REPLACE INTO wikipedia_rollup OVERWRITE ALL REPLACE INTO "wikipedia_rollup" OVERWRITE ALL
WITH source AS (SELECT * FROM TABLE( WITH "source" AS (SELECT * FROM TABLE(
EXTERN( EXTERN(
'{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}', '{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}',
'{"type":"json"}', '{"type":"json"}',
@ -288,7 +288,7 @@ describe('spec conversion', () => {
SUM("deltaBucket") AS "sum_deltaBucket", SUM("deltaBucket") AS "sum_deltaBucket",
SUM("deleted") AS "sum_deleted", SUM("deleted") AS "sum_deleted",
APPROX_COUNT_DISTINCT_DS_THETA("page") AS "page_theta" APPROX_COUNT_DISTINCT_DS_THETA("page") AS "page_theta"
FROM source FROM "source"
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
PARTITIONED BY HOUR PARTITIONED BY HOUR
`); `);
@ -417,8 +417,8 @@ describe('spec conversion', () => {
expect(converted.queryString).toEqual(sane` expect(converted.queryString).toEqual(sane`
-- This SQL query was auto generated from an ingestion spec -- This SQL query was auto generated from an ingestion spec
REPLACE INTO newSource OVERWRITE ALL REPLACE INTO "newSource" OVERWRITE ALL
WITH source AS (SELECT * FROM TABLE( WITH "source" AS (SELECT * FROM TABLE(
EXTERN( EXTERN(
'{"type":"s3","uris":["s3://path"]}', '{"type":"s3","uris":["s3://path"]}',
'{"columns":["col1","col2","col3","col4","metric1","metric2","metric3","metric4","metric5","metric6","metric7"],"type":"timeAndDims"}', '{"columns":["col1","col2","col3","col4","metric1","metric2","metric3","metric4","metric5","metric6","metric7"],"type":"timeAndDims"}',
@ -426,7 +426,7 @@ describe('spec conversion', () => {
) )
)) ))
SELECT 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("event_ts") END, 'PT1H') AS __time,
"col1", "col1",
"col2", "col2",
"col3", "col3",
@ -438,7 +438,7 @@ describe('spec conversion', () => {
APPROX_COUNT_DISTINCT_BUILTIN("field5") AS "metric5", APPROX_COUNT_DISTINCT_BUILTIN("field5") AS "metric5",
SUM("field6") AS "metric6", SUM("field6") AS "metric6",
SUM("field7") AS "metric7" SUM("field7") AS "metric7"
FROM source FROM "source"
WHERE "col2" = 'xxx' WHERE "col2" = 'xxx'
GROUP BY 1, 2, 3, 4, 5 GROUP BY 1, 2, 3, 4, 5
PARTITIONED BY HOUR PARTITIONED BY HOUR
@ -537,8 +537,8 @@ describe('spec conversion', () => {
expect(converted.queryString).toEqual(sane` expect(converted.queryString).toEqual(sane`
-- This SQL query was auto generated from an ingestion spec -- This SQL query was auto generated from an ingestion spec
REPLACE INTO wikipedia OVERWRITE ALL REPLACE INTO "wikipedia" OVERWRITE ALL
WITH source AS (SELECT * FROM TABLE( WITH "source" AS (SELECT * FROM TABLE(
EXTERN( EXTERN(
'{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}', '{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}',
'{"type":"json"}', '{"type":"json"}',
@ -571,7 +571,7 @@ describe('spec conversion', () => {
"metroCode", "metroCode",
"countryIsoCode", "countryIsoCode",
"regionName" "regionName"
FROM source FROM "source"
PARTITIONED BY HOUR PARTITIONED BY HOUR
CLUSTERED BY "isRobot" CLUSTERED BY "isRobot"
`); `);
@ -667,8 +667,8 @@ describe('spec conversion', () => {
expect(converted.queryString).toEqual(sane` expect(converted.queryString).toEqual(sane`
-- This SQL query was auto generated from an ingestion spec -- This SQL query was auto generated from an ingestion spec
REPLACE INTO wikipedia OVERWRITE ALL REPLACE INTO "wikipedia" OVERWRITE ALL
WITH source AS (SELECT * FROM TABLE( WITH "source" AS (SELECT * FROM TABLE(
EXTERN( EXTERN(
'{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}', '{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}',
'{"type":"json"}', '{"type":"json"}',
@ -701,7 +701,7 @@ describe('spec conversion', () => {
"metroCode", "metroCode",
"countryIsoCode", "countryIsoCode",
"regionName" "regionName"
FROM source FROM "source"
WHERE REWRITE_[{"type":"strange"}]_TO_SQL --:ISSUE: The spec contained a filter that could not be automatically converted, please convert it manually WHERE REWRITE_[{"type":"strange"}]_TO_SQL --:ISSUE: The spec contained a filter that could not be automatically converted, please convert it manually
PARTITIONED BY HOUR PARTITIONED BY HOUR
CLUSTERED BY "isRobot" CLUSTERED BY "isRobot"

View File

@ -38,10 +38,10 @@ export function getSpecDatasourceName(spec: IngestionSpec): string {
function convertFilter(filter: any): SqlExpression { function convertFilter(filter: any): SqlExpression {
switch (filter.type) { switch (filter.type) {
case 'selector': case 'selector':
return SqlRef.columnWithQuotes(filter.dimension).equal(filter.value); return SqlRef.column(filter.dimension).equal(filter.value);
case 'in': case 'in':
return SqlRef.columnWithQuotes(filter.dimension).in(filter.values); return SqlRef.column(filter.dimension).in(filter.values);
case 'not': case 'not':
return convertFilter(filter.field).not(); return convertFilter(filter.field).not();
@ -264,7 +264,7 @@ export function convertSpecToSql(spec: any): QueryWithContext {
const relevantTransform = transforms.find(t => t.name === dimensionName); const relevantTransform = transforms.find(t => t.name === dimensionName);
return ` ${ return ` ${
relevantTransform ? `REWRITE_[${relevantTransform.expression}]_TO_SQL AS ` : '' relevantTransform ? `REWRITE_[${relevantTransform.expression}]_TO_SQL AS ` : ''
}${SqlRef.columnWithQuotes(dimensionName)},${ }${SqlRef.column(dimensionName)},${
relevantTransform ? ` --:ISSUE: Transform for dimension could not be converted` : '' relevantTransform ? ` --:ISSUE: Transform for dimension could not be converted` : ''
}`; }`;
}), }),
@ -316,9 +316,7 @@ export function convertSpecToSql(spec: any): QueryWithContext {
partitionsSpec.partitionDimensions || partitionsSpec.partitionDimensions ||
(partitionsSpec.partitionDimension ? [partitionsSpec.partitionDimension] : undefined); (partitionsSpec.partitionDimension ? [partitionsSpec.partitionDimension] : undefined);
if (Array.isArray(partitionDimensions)) { if (Array.isArray(partitionDimensions)) {
lines.push( lines.push(`CLUSTERED BY ${partitionDimensions.map(d => SqlRef.column(d)).join(', ')}`);
`CLUSTERED BY ${partitionDimensions.map(d => SqlRef.columnWithQuotes(d)).join(', ')}`,
);
} }
return { return {
@ -399,7 +397,7 @@ function metricSpecToSqlExpression(metricSpec: MetricSpec): string | undefined {
} }
if (!metricSpec.fieldName) return; if (!metricSpec.fieldName) return;
const ref = SqlRef.columnWithQuotes(metricSpec.fieldName); const ref = SqlRef.column(metricSpec.fieldName);
switch (metricSpec.type) { switch (metricSpec.type) {
case 'longSum': case 'longSum':

View File

@ -142,7 +142,7 @@ export function sqlQueryCustomTableFilter(filter: Filter): SqlExpression | undef
const modeAndNeedle = parseFilterModeAndNeedle(filter); const modeAndNeedle = parseFilterModeAndNeedle(filter);
if (!modeAndNeedle) return; if (!modeAndNeedle) return;
const { mode, needle } = modeAndNeedle; const { mode, needle } = modeAndNeedle;
const column = SqlRef.columnWithQuotes(filter.id); const column = SqlRef.column(filter.id);
const needleLiteral = SqlLiteral.create(needle); const needleLiteral = SqlLiteral.create(needle);
switch (mode) { switch (mode) {
case '=': case '=':

View File

@ -309,6 +309,6 @@ export interface QueryExplanation {
export function formatSignature(queryExplanation: QueryExplanation): string { export function formatSignature(queryExplanation: QueryExplanation): string {
return queryExplanation.signature return queryExplanation.signature
.map(({ name, type }) => `${SqlRef.column(name)}::${type}`) .map(({ name, type }) => `${SqlRef.columnWithoutQuotes(name)}::${type}`)
.join(', '); .join(', ');
} }

View File

@ -48,13 +48,13 @@ describe('sample-query', () => {
expect(sampleDataToQuery(result).toString()).toEqual(sane` expect(sampleDataToQuery(result).toString()).toEqual(sane`
SELECT SELECT
CAST(c0 AS TIMESTAMP) AS "__time", CAST("c0" AS TIMESTAMP) AS "__time",
CAST(c1 AS VARCHAR) AS "host", CAST("c1" AS VARCHAR) AS "host",
CAST(c2 AS VARCHAR) AS "service", CAST("c2" AS VARCHAR) AS "service",
PARSE_JSON(c3) AS "msg" PARSE_JSON("c3") AS "msg"
FROM (VALUES FROM (VALUES
('2022-02-01T00:00:00.000Z', 'brokerA.internal', 'broker', '"{\\"type\\":\\"sys\\",\\"swap/free\\":1223334,\\"swap/max\\":3223334}"'), ('2022-02-01T00:00:00.000Z', 'brokerA.internal', 'broker', '"{\\"type\\":\\"sys\\",\\"swap/free\\":1223334,\\"swap/max\\":3223334}"'),
('2022-02-01T00:00:00.000Z', 'brokerA.internal', 'broker', '"{\\"type\\":\\"query\\",\\"time\\":1223,\\"bytes\\":2434234}"')) AS t ("c0", "c1", "c2", "c3") ('2022-02-01T00:00:00.000Z', 'brokerA.internal', 'broker', '"{\\"type\\":\\"query\\",\\"time\\":1223,\\"bytes\\":2434234}"')) AS "t" ("c0", "c1", "c2", "c3")
`); `);
}); });
}); });

View File

@ -294,7 +294,7 @@ END AS "time_span"`,
} }
} else if (f.id.startsWith('is_')) { } else if (f.id.startsWith('is_')) {
if (f.value === 'all') return; if (f.value === 'all') return;
return SqlRef.columnWithQuotes(f.id).equal(f.value === 'true' ? 1 : 0); return SqlRef.column(f.id).equal(f.value === 'true' ? 1 : 0);
} else { } else {
return sqlQueryCustomTableFilter(f); return sqlQueryCustomTableFilter(f);
} }

View File

@ -23,7 +23,7 @@ exports[`IngestSuccessPane matches snapshot 1`] = `
className="action" className="action"
onClick={[Function]} onClick={[Function]}
> >
SELECT * FROM kttm_simple SELECT * FROM "kttm_simple"
</span> </span>
</p> </p>
</div> </div>