From e1b1f32329cee458bb59e08ce8c32d54589fac01 Mon Sep 17 00:00:00 2001 From: akvlad Date: Wed, 4 Sep 2024 20:38:33 +0300 Subject: [PATCH] fix --- parser/registry/common.js | 46 +++++++++++++++++++ .../smart_optimizations/optimization_v3_2.js | 7 ++- parser/transpiler.js | 42 +++++++++-------- test/__snapshots__/transpiler.test.js.snap | 34 +++++++------- 4 files changed, 89 insertions(+), 40 deletions(-) diff --git a/parser/registry/common.js b/parser/registry/common.js index cee7ff57..0f0273ca 100644 --- a/parser/registry/common.js +++ b/parser/registry/common.js @@ -1,6 +1,7 @@ const { hashLabels, parseLabels } = require('../../common') const { getPlg } = require('../../plugins/engine') const Sql = require('@cloki/clickhouse-sql') +const { DATABASE_NAME } = require('../../lib/utils') const clusterName = require('../../common').clusterName module.exports.dist = clusterName ? '_dist' : '' @@ -413,3 +414,48 @@ module.exports.patchCol = (query, name, patcher) => { return col }) } + +module.exports.preJoinLabels = (token, query, dist) => { + const from = query.getParam(module.exports.sharedParamNames.from) + const to = query.getParam(module.exports.sharedParamNames.to) + const sqlFrom = new Sql.Raw() + sqlFrom.toString = () => { + let fromNs = 0 + if (from.get()) { + fromNs = from.get() + } + return `toDate(fromUnixTimestamp(intDiv(${fromNs}, 1000000000)))` + } + const sqlTo = new Sql.Raw() + sqlTo.toString = () => { + let toNs = 0 + if (to.get()) { + toNs = to.get() + } + return `toDate(fromUnixTimestamp(intDiv(${toNs}, 1000000000)))` + } + let withIdxSel = query.with().idx_sel + let inRightSide = new Sql.WithReference(withIdxSel) + if (!withIdxSel) { + withIdxSel = query.with().str_sel + inRightSide = new Sql.Select() + .select('fingerprint') + .from(new Sql.WithReference(withIdxSel)) + } + dist = dist || '' + const timeSeriesReq = new Sql.Select() + .select('fingerprint', 'labels') + .from([`${DATABASE_NAME()}.time_series${dist}`, 'time_series']) + .where(new Sql.And( + new Sql.In('time_series.fingerprint', 'in', inRightSide), + Sql.Gte(new Sql.Raw('date'), sqlFrom), + Sql.Lte(new Sql.Raw('date'), sqlTo) + )) + timeSeriesReq._toString = timeSeriesReq.toString + timeSeriesReq.toString = () => { + return `(${timeSeriesReq._toString()})` + } + query.join(new module.exports.Aliased(timeSeriesReq, 'time_series'), 'left any', + Sql.Eq('samples.fingerprint', new Sql.Raw('time_series.fingerprint'))) + query.select([new Sql.Raw('JSONExtractKeysAndValues(time_series.labels, \'String\')'), 'labels']) +} diff --git a/parser/registry/smart_optimizations/optimization_v3_2.js b/parser/registry/smart_optimizations/optimization_v3_2.js index ede56134..ff7a7b03 100644 --- a/parser/registry/smart_optimizations/optimization_v3_2.js +++ b/parser/registry/smart_optimizations/optimization_v3_2.js @@ -1,4 +1,4 @@ -const { getDuration, Aliased } = require('../common') +const { getDuration, preJoinLabels, dist } = require('../common') const reg = require('./log_range_agg_reg_v3_2') const Sql = require('@cloki/clickhouse-sql') const { DATABASE_NAME, checkVersion } = require('../../../lib/utils') @@ -51,15 +51,14 @@ module.exports.apply = (token, fromNS, toNS, stepNS) => { .select(['samples.fingerprint', 'fingerprint']) .from([`${DATABASE_NAME()}.metrics_15s${_dist}`, 'samples']) .where(tsClause) - q.join(new Aliased(`${DATABASE_NAME()}.time_series`, 'time_series'), 'left any', - Sql.Eq('samples.fingerprint', new Sql.Raw('time_series.fingerprint'))) - q.select([new Sql.Raw('any(JSONExtractKeysAndValues(time_series.labels, \'String\'))'), 'labels']) q.ctx = { step: stepNS / 1000000000, inline: !!clusterName } + preJoinLabels(token, q, dist) + for (const streamSelectorRule of token.Children('log_stream_selector_rule')) { q = streamSelectorReg[streamSelectorRule.Child('operator').value](streamSelectorRule, q) } diff --git a/parser/transpiler.js b/parser/transpiler.js index afda33ac..8da0b920 100644 --- a/parser/transpiler.js +++ b/parser/transpiler.js @@ -10,7 +10,7 @@ const lineFormat = require('./registry/line_format') const parserRegistry = require('./registry/parser_registry') const unwrap = require('./registry/unwrap') const unwrapRegistry = require('./registry/unwrap_registry') -const { durationToMs, sharedParamNames, getStream, Aliased } = require('./registry/common') +const { durationToMs, sharedParamNames, getStream, preJoinLabels } = require('./registry/common') const compiler = require('./bnf') const { parseMs, @@ -75,11 +75,6 @@ module.exports.initQuery = (joinLabels, types) => { .addParam(to) .addParam(limit) .addParam(matrix) - if (joinLabels) { - q.join(new Aliased(`${DATABASE_NAME()}.time_series`, 'time_series'), 'left any', - Sql.Eq('samples.fingerprint', new Sql.Raw('time_series.fingerprint'))) - q.select([new Sql.Raw('JSONExtractKeysAndValues(time_series.labels, \'String\')'), 'labels']) - } return q } @@ -88,7 +83,7 @@ module.exports.initQuery = (joinLabels, types) => { * @param types {[number] || undefined} * @returns {Select} */ -module.exports.initQueryV3_2 = (joinLabels, types) => { +/*module.exports.initQueryV3_2 = (joinLabels, types) => { types = types || [bothType, logType] const from = new Sql.Parameter(sharedParamNames.from) const to = new Sql.Parameter(sharedParamNames.to) @@ -108,12 +103,13 @@ module.exports.initQueryV3_2 = (joinLabels, types) => { .addParam(from) .addParam(to) if (joinLabels) { + //TODO: fix join q.join(new Aliased(`${DATABASE_NAME()}.time_series${dist}`, 'time_series'), 'left any', Sql.Eq('samples.fingerprint', new Sql.Raw('time_series.fingerprint'))) q.select([new Sql.Raw('JSONExtractKeysAndValues(time_series.labels, \'String\')'), 'labels']) } return q -} +}*/ /** * @@ -193,6 +189,8 @@ module.exports.transpile = (request) => { end } } + joinLabels && doStreamSelectorOperatorRegistry(token, query) + joinLabels && preJoinLabels(token, query) matrixOp = matrixOp || (token.Child('summary') && 'summary') switch (matrixOp) { case 'aggregation_operator': @@ -223,10 +221,9 @@ module.exports.transpile = (request) => { .orderBy(['labels', order], ['timestamp_ns', order]) setQueryParam(query, sharedParamNames.limit, limit) if (!joinLabels) { - query.join(new Aliased(`${DATABASE_NAME()}.time_series${dist}`, 'time_series'), 'left any', - Sql.Eq('sel_a.fingerprint', new Sql.Raw('time_series.fingerprint'))) - query.select([new Sql.Raw('JSONExtractKeysAndValues(time_series.labels, \'String\')'), 'labels'], - new Sql.Raw('sel_a.*')) + query.from([new Sql.WithReference(query.with().sel_a), 'samples']) + preJoinLabels(token, query, dist) + query.select(new Sql.Raw('samples.*')) } } if (token.Child('agg_statement') && token.Child('compared_agg_statement_cmp')) { @@ -381,7 +378,9 @@ module.exports.transpileTail = (request) => { } } - let query = module.exports.initQuery(true) + let query = module.exports.initQuery(false) + doStreamSelectorOperatorRegistry(expression.rootToken, query) + preJoinLabels(expression.rootToken, query, dist) query.ctx = { ...(query.ctx || {}), legacy: true @@ -393,7 +392,6 @@ module.exports.transpileTail = (request) => { query.order_expressions = [] query.orderBy(['timestamp_ns', 'asc']) query.limit(undefined, undefined) - //logger.debug(query.toString()) return { query: request.rawRequest ? query : query.toString(), stream: getStream(query) @@ -496,11 +494,7 @@ module.exports.transpileLogRangeAggregation = (token, query) => { * @returns {Sql.Select} */ module.exports.transpileLogStreamSelector = (token, query) => { - const rules = token.Children('log_stream_selector_rule') - for (const rule of rules) { - const op = rule.Child('operator').value - query = streamSelectorOperatorRegistry[op](rule, query) - } + doStreamSelectorOperatorRegistry(token, query) for (const pipeline of token.Children('log_pipeline')) { if (pipeline.Child('line_filter_expression')) { const op = pipeline.Child('line_filter_operator').value @@ -619,3 +613,13 @@ const whereBuilder = (clause) => { const _clause = clause.slice(1).map(c => Array.isArray(c) ? `(${whereBuilder(c)})` : c) return _clause.join(` ${op} `) } + +const doStreamSelectorOperatorRegistry = (token, query) => { + if (!query.with().idx_sel && !query.with().str_sel) { + const rules = token.Children('log_stream_selector_rule') + for (const rule of rules) { + const op = rule.Child('operator').value + query = streamSelectorOperatorRegistry[op](rule, query) + } + } +} diff --git a/test/__snapshots__/transpiler.test.js.snap b/test/__snapshots__/transpiler.test.js.snap index 415e0654..94a26ba0 100644 --- a/test/__snapshots__/transpiler.test.js.snap +++ b/test/__snapshots__/transpiler.test.js.snap @@ -9370,7 +9370,7 @@ exports[`should transpile complex pipelines 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '\${testID}')) and ((JSONHas(labels, 'freq') = 1) and (toFloat64OrNull(JSONExtractString(labels, 'freq')) >= '4'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 0000000 and 100000000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` asc limit 1000) select * from sel_a order by \`labels\` asc,\`timestamp_ns\` asc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '\${testID}')) and ((JSONHas(labels, 'freq') = 1) and (toFloat64OrNull(JSONExtractString(labels, 'freq')) >= '4'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(0000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(100000000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 0000000 and 100000000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` asc limit 1000) select * from sel_a order by \`labels\` asc,\`timestamp_ns\` asc", "stream": [], } `; @@ -9733,7 +9733,7 @@ exports[`should transpile json requests 2`] = ` "l2": "v2", "l3": "v4", }, - "string": "{\"l1\":\"v3\",\"l3\":\"v4\"}", + "string": "{"l1":"v3","l3":"v4"}", }, ] `; @@ -9759,7 +9759,7 @@ exports[`should transpile line format 2`] = ` "intval": "5", "lbl1": "a", }, - "string": "{ \"entry\": \"str\", \"intval\": 5 }", + "string": "{ "entry": "str", "intval": 5 }", }, ] `; @@ -12875,7 +12875,7 @@ exports[`should transpile logfmt requests 1`] = ` "l2": "v2", "l3": "v4", }, - "string": "l1=\"v3\" l3=\"v4\" ", + "string": "l1="v3" l3="v4" ", }, ] `; @@ -12884,7 +12884,7 @@ exports[`should transpile new style 1 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7387779420506657'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\` from loki.samples_vX as \`samples\` where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,sel_a.* from sel_a left any join \`loki\`.\`time_series\` AS time_series on \`sel_a\`.\`fingerprint\` = time_series.fingerprint order by \`labels\` desc,\`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7387779420506657'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\` from loki.samples_vX as \`samples\` where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,samples.* from sel_a as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint order by \`labels\` desc,\`timestamp_ns\` desc", "stream": [], } `; @@ -12893,7 +12893,7 @@ exports[`should transpile new style 2 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.2119268970232')) and ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '2'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\` from loki.samples_vX as \`samples\` where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (match(string, '2[0-9]$') = 1) order by \`timestamp_ns\` desc limit 2000) select JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,sel_a.* from sel_a left any join \`loki\`.\`time_series\` AS time_series on \`sel_a\`.\`fingerprint\` = time_series.fingerprint order by \`labels\` desc,\`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.2119268970232')) and ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '2'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\` from loki.samples_vX as \`samples\` where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (match(string, '2[0-9]$') = 1) order by \`timestamp_ns\` desc limit 2000) select JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,samples.* from sel_a as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint order by \`labels\` desc,\`timestamp_ns\` desc", "stream": [], } `; @@ -12902,7 +12902,7 @@ exports[`should transpile new style 3 1`] = ` { "duration": 1000, "matrix": true, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7026038163617259')) and ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '2'))), rate_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (match(string, '2[0-9]$') = 1) order by \`timestamp_ns\` desc), rate_b AS (select labels as \`labels\`,intDiv(timestamp_ns, 1000) * 1000 as \`timestamp_ns\`,toFloat64(count(1)) * 1000 / 1000 as \`value\` from rate_a group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc) select \`labels\`,intDiv(timestamp_ns, 2000) * 2000 as \`timestamp_ns\`,argMin(rate_b.value, rate_b.timestamp_ns) as \`value\` from \`rate_b\` group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7026038163617259')) and ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '2'))), rate_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (match(string, '2[0-9]$') = 1) order by \`timestamp_ns\` desc), rate_b AS (select labels as \`labels\`,intDiv(timestamp_ns, 1000) * 1000 as \`timestamp_ns\`,toFloat64(count(1)) * 1000 / 1000 as \`value\` from rate_a group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc) select \`labels\`,intDiv(timestamp_ns, 2000) * 2000 as \`timestamp_ns\`,argMin(rate_b.value, rate_b.timestamp_ns) as \`value\` from \`rate_b\` group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc", "stream": [], } `; @@ -12911,7 +12911,7 @@ exports[`should transpile new style 4 1`] = ` { "duration": 1000, "matrix": true, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7026038163617259')) and ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '2'))) select \`labels\`,toUInt64(intDiv(timestamp_ns, 1000000000) * 1000) as \`timestamp_ns\`,toFloat64(0) as \`value\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (match(string, '2[0-9]$') = 1) group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7026038163617259')) and ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '2'))) select \`labels\`,toUInt64(intDiv(timestamp_ns, 1000000000) * 1000) as \`timestamp_ns\`,toFloat64(0) as \`value\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (match(string, '2[0-9]$') = 1) group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc", "stream": [ [Function], ], @@ -12922,7 +12922,7 @@ exports[`should transpile new style 5 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.000341166036469831_json'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.000341166036469831_json'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", "stream": [ [Function], ], @@ -12933,7 +12933,7 @@ exports[`should transpile new style 6 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.2053747382122484_json'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,arrayFilter((x) -> x.2 != '', [('lbl_repl', if(JSONType(samples.string, 'new_lbl') == 'String', JSONExtractString(samples.string, 'new_lbl'), JSONExtractRaw(samples.string, 'new_lbl')))]) as \`extra_labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (isValidJSON(samples.string) = 1) and ((indexOf(extra_labels, ('lbl_repl', 'new_val')) > 0) or ((arrayExists(x -> x.1 == 'lbl_repl', extra_labels) = 0) and ((arrayExists(x -> x.1 == 'lbl_repl', labels) = 1) and (arrayFirst(x -> x.1 == 'lbl_repl', labels).2 = 'new_val')))) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.2053747382122484_json'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,arrayFilter((x) -> x.2 != '', [('lbl_repl', if(JSONType(samples.string, 'new_lbl') == 'String', JSONExtractString(samples.string, 'new_lbl'), JSONExtractRaw(samples.string, 'new_lbl')))]) as \`extra_labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (isValidJSON(samples.string) = 1) and ((indexOf(extra_labels, ('lbl_repl', 'new_val')) > 0) or ((arrayExists(x -> x.1 == 'lbl_repl', extra_labels) = 0) and ((arrayExists(x -> x.1 == 'lbl_repl', labels) = 1) and (arrayFirst(x -> x.1 == 'lbl_repl', labels).2 = 'new_val')))) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", "stream": [], } `; @@ -12942,7 +12942,7 @@ exports[`should transpile new style 7 1`] = ` { "duration": 3000, "matrix": true, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.1547558751138609_json'))) select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.1547558751138609_json'))) select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc", "stream": [ [Function], [Function], @@ -12958,7 +12958,7 @@ exports[`should transpile new style 8 1`] = ` { "duration": 1000, "matrix": true, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.4075242197275857'))) select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.4075242197275857'))) select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc", "stream": [ [Function], [Function], @@ -12974,7 +12974,7 @@ exports[`should transpile new style 9 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7186063017626447_json'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,arrayFilter((x) -> x.2 != '', [('sid', if(JSONType(samples.string, 'str_id') == 'String', JSONExtractString(samples.string, 'str_id'), JSONExtractRaw(samples.string, 'str_id')))]) as \`extra_labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (isValidJSON(samples.string) = 1) and ((arrayExists(x -> x.1 == 'sid' AND (coalesce(toFloat64OrNull(x.2) >= '598', 0)), extra_labels) != 0) or ((arrayExists(x -> x.1 == 'sid', extra_labels) = 0) and (arrayExists(x -> x.1 == 'sid', labels) = 1) and (toFloat64OrNull(arrayFirst(x -> x.1 == 'sid', labels).2) >= '598'))) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.7186063017626447_json'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,arrayFilter((x) -> x.2 != '', [('sid', if(JSONType(samples.string, 'str_id') == 'String', JSONExtractString(samples.string, 'str_id'), JSONExtractRaw(samples.string, 'str_id')))]) as \`extra_labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (isValidJSON(samples.string) = 1) and ((arrayExists(x -> x.1 == 'sid' AND (coalesce(toFloat64OrNull(x.2) >= '598', 0)), extra_labels) != 0) or ((arrayExists(x -> x.1 == 'sid', extra_labels) = 0) and (arrayExists(x -> x.1 == 'sid', labels) = 1) and (toFloat64OrNull(arrayFirst(x -> x.1 == 'sid', labels).2) >= '598'))) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", "stream": [], } `; @@ -12983,7 +12983,7 @@ exports[`should transpile new style 10 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.5505504081219323'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,arrayFilter(x -> x.1 != '' AND x.2 != '', arrayZip(['e'], arrayMap(x -> x[length(x)], extractAllGroupsHorizontal(string, '^([^0-9]+)[0-9]+$')))) as \`extra_labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (JSONExtractString(labels, 'test_id') = '0.5505504081219323'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,arrayFilter(x -> x.1 != '' AND x.2 != '', arrayZip(['e'], arrayMap(x -> x[length(x)], extractAllGroupsHorizontal(string, '^([^0-9]+)[0-9]+$')))) as \`extra_labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", "stream": [], } `; @@ -12992,7 +12992,7 @@ exports[`should transpile new style 11 1`] = ` { "duration": 1000, "matrix": true, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'label') = 1) and (JSONExtractString(labels, 'label') = 'val'))), uw_rate_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,toFloat64OrNull(arrayFirst(x -> x.1 == 'b', labels).2) as \`unwrapped\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and ((arrayExists(x -> x.1 == 'b', labels) = 1) and (isNotNull(unwrapped) = 1)) order by \`timestamp_ns\` desc), uw_rate_b AS (select labels as \`labels\`,SUM(unwrapped) / 1 as \`value\`,intDiv(timestamp_ns, 1000) * 1000 as \`timestamp_ns\` from uw_rate_a group by \`labels\`,\`timestamp_ns\` order by \`labels\`,\`timestamp_ns\`) select \`labels\`,intDiv(timestamp_ns, 2000) * 2000 as \`timestamp_ns\`,argMin(uw_rate_b.value, uw_rate_b.timestamp_ns) as \`value\` from uw_rate_b group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'label') = 1) and (JSONExtractString(labels, 'label') = 'val'))), uw_rate_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,intDiv(samples.timestamp_ns, 1000000) as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\`,toFloat64OrNull(arrayFirst(x -> x.1 == 'b', labels).2) as \`unwrapped\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and ((arrayExists(x -> x.1 == 'b', labels) = 1) and (isNotNull(unwrapped) = 1)) order by \`timestamp_ns\` desc), uw_rate_b AS (select labels as \`labels\`,SUM(unwrapped) / 1 as \`value\`,intDiv(timestamp_ns, 1000) * 1000 as \`timestamp_ns\` from uw_rate_a group by \`labels\`,\`timestamp_ns\` order by \`labels\`,\`timestamp_ns\`) select \`labels\`,intDiv(timestamp_ns, 2000) * 2000 as \`timestamp_ns\`,argMin(uw_rate_b.value, uw_rate_b.timestamp_ns) as \`value\` from uw_rate_b group by \`labels\`,\`timestamp_ns\` order by \`labels\` asc,\`timestamp_ns\` asc", "stream": [], } `; @@ -13001,7 +13001,7 @@ exports[`should transpile new style 12 1`] = ` { "duration": 1000, "matrix": false, - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '1'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", + "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'freq') = 1) and (JSONExtractString(labels, 'freq') = '1'))), sel_a AS (select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_vX as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) and (date >= toDate(fromUnixTimestamp(intDiv(1638802620000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(1638803220000000000, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` between 1638802620000000000 and 1638803220000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` desc limit 2000) select * from sel_a order by \`labels\` desc,\`timestamp_ns\` desc", "stream": [ [Function], [Function], @@ -13028,7 +13028,7 @@ exports[`should transpile series 1`] = `"WITH idx_sel AS ((select \`sel_1\`.\`fi exports[`should transpile tail 1`] = ` { - "query": "WITH str_sel AS (select DISTINCT \`fingerprint\` from loki.time_series where ((JSONHas(labels, 'test_id') = 1) and (extractAllGroups(JSONExtractString(labels, 'test_id'), '(_ws)') != '[]'))) select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_v3 as \`samples\` left any join \`loki\`.\`time_series\` AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` > (toUnixTimestamp(now()) - 5) * 1000000000) and (\`samples\`.\`type\` in (0,0))) and (\`samples\`.\`fingerprint\` in (select \`fingerprint\` from str_sel)) order by \`timestamp_ns\` asc", + "query": "WITH idx_sel AS (select \`sel_1\`.\`fingerprint\` from (select \`fingerprint\` from \`loki\`.\`time_series_gin\` where ((\`key\` = 'test_id') and (match(val, '_ws') = 1))) as \`sel_1\`) select \`samples\`.\`string\` as \`string\`,\`samples\`.\`fingerprint\` as \`fingerprint\`,samples.timestamp_ns as \`timestamp_ns\`,JSONExtractKeysAndValues(time_series.labels, 'String') as \`labels\` from loki.samples_v3 as \`samples\` left any join (select \`fingerprint\`,\`labels\` from \`loki\`.\`time_series\` as \`time_series\` where ((\`time_series\`.\`fingerprint\` in (idx_sel)) and (date >= toDate(fromUnixTimestamp(intDiv((toUnixTimestamp(now()) - 5) * 1000000000, 1000000000)))) and (date <= toDate(fromUnixTimestamp(intDiv(0, 1000000000)))))) AS time_series on \`samples\`.\`fingerprint\` = time_series.fingerprint where ((\`samples\`.\`timestamp_ns\` > (toUnixTimestamp(now()) - 5) * 1000000000) and (\`samples\`.\`type\` in (0,0))) and (samples.fingerprint IN idx_sel) order by \`timestamp_ns\` asc", "stream": [], } `;