Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Fix range error in queries #39

Merged
merged 3 commits into from
Jul 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions specs/metric_find_query.jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe('metric find query', () => {

it('returns a measurement query for measurements()', () => {
const query = ' measurements(mydb) ';
const result = expandMacros(query).replace(/\s/g, '');
const result = expandMacros(query);
expect(result).toBe(
'from(bucket:"mydb")|>range($range)|>group(columns:["_measurement"])|>distinct(column:"_measurement")'
'import "influxdata/influxdb/v1" v1.measurements(bucket: "mydb")'
);
});

Expand Down
8 changes: 4 additions & 4 deletions src/editor/FluxQueryField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ const DEFAULT_DATABASE = 'telegraf';
function expandQuery(bucket, measurement, field) {
if (field) {
return (
`from(bucket: "${bucket}")\n` +
` |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> filter(fn: (r) => r["_field"] == "${field}")\n |> range($range)\n |> limit(n: 1000)`
`from(bucket: "${bucket}")\n |> range($range)\n` +
` |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> filter(fn: (r) => r["_field"] == "${field}")\n |> aggregateWindow(every: $__interval, fn: last)`
);
}
return `from(bucket: "${bucket}")\n |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> range($range)\n |> limit(n: 1000)`;
return `from(bucket: "${bucket}")\n |> range($range)\n |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> aggregateWindow(every: $__interval, fn: last)`;
}

export default class FluxQueryField extends QueryField {
Expand Down Expand Up @@ -126,7 +126,7 @@ export default class FluxQueryField extends QueryField {
}
} else if (db) {
const measurements = this.measurements && this.measurements[db];
if (measurements) {
if (measurements && measurements.length > 0) {
prefix = prefix.replace(/\w*\.\./g, '');
typeaheadContext = 'context-measurements';
suggestionGroups.push({ label: 'Measurements', items: measurements });
Expand Down
47 changes: 0 additions & 47 deletions src/editor/slate-plugins/braces.test.ts

This file was deleted.

38 changes: 0 additions & 38 deletions src/editor/slate-plugins/clear.test.ts

This file was deleted.

5 changes: 1 addition & 4 deletions src/metric_find_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export default function expandMacros(query) {
const measurementsQuery = query.match(MEASUREMENTS_REGEXP);
if (measurementsQuery) {
const database = measurementsQuery[1];
return `from(bucket:"${database}")
|> range($range)
|> group(columns:["_measurement"])
|> distinct(column:"_measurement")`;
return `import "influxdata/influxdb/v1" v1.measurements(bucket: "${database}")`;
}

const tagsQuery = query.match(TAGS_REGEXP);
Expand Down