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

Allow auto calculated limit to be inserted a specific place instead of just appended to the end #237

Merged
merged 1 commit into from
May 27, 2020

Conversation

ptomasroos
Copy link
Contributor

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #232

Special notes for your reviewer:

Release note:

This allows the user to specify where the LIMIT statement should be inserted when using $__timeGroup(..., auto).

Use $__limitPosition to specify if the limit should be inserted to a specific placement rather than the default behaviour of appending to the end of the query.

@Tamirk Tamirk requested a review from LiorRacer April 22, 2020 06:58
Copy link
Contributor

@LiorRacer LiorRacer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ptomasroos,
Looks good can you please add a test for it?

@ptomasroos
Copy link
Contributor Author

There are no tests covering the LIMIT logic today, so can you give me a suggestion on how I would test this?

@LiorRacer
Copy link
Contributor

I would call the query method like so:

describe("When performing do request with limit position", () => {
    const limitResult = 2;
    let results;
    const response = {
      kind: "bigquery#queryResponse",
      schema: {
        fields: [
          {
            name: "time",
            type: "TIMESTAMP",
            mode: "NULLABLE"
          },
          {
            name: "start_station_latitude",
            type: "FLOAT",
            mode: "NULLABLE"
          }
        ]
      },
      jobReference: {
        projectId: "aviv-playground",
        jobId: "job_fB4qCDAO-TKg1Orc-OrkdIRxCGN5",
        location: "US"
      },
      totalRows: "3",
      rows: [
        {
          f: [
            {
              v: "1.521578851E9"
            },
            {
              v: "37.7753058"
            }
          ]
        },
        {
          f: [
            {
              v: "1.521578916E9"
            },
            {
              v: "37.3322326"
            }
          ]
        },
        {
          f: [
            {
              v: "1.521578927E9"
            },
            {
              v: "37.781752"
            }
          ]
        }
      ],
      totalBytesProcessed: "23289520",
      jobComplete: true,
      cacheHit: false
    };
    beforeEach(() => {
      ctx.backendSrv.datasourceRequest = jest.fn(options => {
        return Promise.resolve({ data: response, status: 200 });
      });
    });

    it("should return expected amount of rows", async () => {    
      await ctx.ds.query({}) //=> call with your params
      expect(results.rows.length).toBe(limitResult);
    });
  });

@LiorRacer LiorRacer merged commit d403629 into doitintl:master May 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support group by scenarios for the auto interval
2 participants