Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
Override limit only for Raw agg queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Apr 3, 2017
1 parent 1dd2330 commit a685ae6
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/datasource.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datasource.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CrateDatasource {
}

// Split target into two queries (with aggs and raw data)
query = this.queryBuilder.buildAggQuery(target, interval, adhocFilters, maxLimit);
query = this.queryBuilder.buildAggQuery(target, interval, adhocFilters);
queryTarget = _.cloneDeep(target);
queryTarget.metricAggs = getNotRawAggs(queryTarget.metricAggs);

Expand Down
9 changes: 5 additions & 4 deletions dist/query_builder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/query_builder.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/query_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import _ from 'lodash';

// Maximum LIMIT value
let MAX_LIMIT = 500000000;
let MAX_LIMIT = 100000;
let DEFAULT_LIMIT = 10000;

export class CrateQueryBuilder {
schema: string;
Expand All @@ -30,7 +31,7 @@ export class CrateQueryBuilder {
* @param {string} defaultAgg Default aggregation for values.
* @return {string} SQL query.
*/
build(target: any, groupInterval=0, adhocFilters=[], limit=10000, defaultAgg='avg') {
build(target: any, groupInterval = 0, adhocFilters = [], limit = DEFAULT_LIMIT, defaultAgg='avg') {
let query: string;
let timeExp: string;

Expand Down Expand Up @@ -89,7 +90,7 @@ export class CrateQueryBuilder {
return query;
}

buildAggQuery(target: any, groupInterval=0, adhocFilters=[], limit?: number) {
buildAggQuery(target: any, groupInterval = 0, adhocFilters = [], limit?: number) {
let query: string;
let timeExp: string;

Expand Down Expand Up @@ -148,15 +149,15 @@ export class CrateQueryBuilder {
}
query += " ASC";

if (limit) {
if (limit && limit > DEFAULT_LIMIT) {
limit = Math.min(limit, MAX_LIMIT);
query += ` LIMIT ${limit}`;
}

return query;
}

buildRawAggQuery(target: any, groupInterval=0, adhocFilters=[], limit?: number) {
buildRawAggQuery(target: any, groupInterval = 0, adhocFilters = [], limit?: number) {
let query: string;
let timeExp: string;

Expand Down
2 changes: 1 addition & 1 deletion src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CrateDatasource {
}

// Split target into two queries (with aggs and raw data)
query = this.queryBuilder.buildAggQuery(target, interval, adhocFilters, maxLimit);
query = this.queryBuilder.buildAggQuery(target, interval, adhocFilters);
queryTarget = _.cloneDeep(target);
queryTarget.metricAggs = getNotRawAggs(queryTarget.metricAggs);

Expand Down
11 changes: 6 additions & 5 deletions src/query_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import _ from 'lodash';

// Maximum LIMIT value
let MAX_LIMIT = 500000000;
let MAX_LIMIT = 100000;
let DEFAULT_LIMIT = 10000;

export class CrateQueryBuilder {
schema: string;
Expand All @@ -30,7 +31,7 @@ export class CrateQueryBuilder {
* @param {string} defaultAgg Default aggregation for values.
* @return {string} SQL query.
*/
build(target: any, groupInterval=0, adhocFilters=[], limit=10000, defaultAgg='avg') {
build(target: any, groupInterval = 0, adhocFilters = [], limit = DEFAULT_LIMIT, defaultAgg='avg') {
let query: string;
let timeExp: string;

Expand Down Expand Up @@ -89,7 +90,7 @@ export class CrateQueryBuilder {
return query;
}

buildAggQuery(target: any, groupInterval=0, adhocFilters=[], limit?: number) {
buildAggQuery(target: any, groupInterval = 0, adhocFilters = [], limit?: number) {
let query: string;
let timeExp: string;

Expand Down Expand Up @@ -148,15 +149,15 @@ export class CrateQueryBuilder {
}
query += " ASC";

if (limit) {
if (limit && limit > DEFAULT_LIMIT) {
limit = Math.min(limit, MAX_LIMIT);
query += ` LIMIT ${limit}`;
}

return query;
}

buildRawAggQuery(target: any, groupInterval=0, adhocFilters=[], limit?: number) {
buildRawAggQuery(target: any, groupInterval = 0, adhocFilters = [], limit?: number) {
let query: string;
let timeExp: string;

Expand Down

0 comments on commit a685ae6

Please sign in to comment.