Skip to content

Fix bugs: time range longer than expected #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zlzlzlstone opened this issue Jun 12, 2018 · 1 comment
Open

Fix bugs: time range longer than expected #14

zlzlzlstone opened this issue Jun 12, 2018 · 1 comment

Comments

@zlzlzlstone
Copy link

zlzlzlstone commented Jun 12, 2018

Raw:
SELECT sum("col") AS "shift_1_days" FROM "m" WHERE time >= now() - 3h GROUP BY time(1m)

Proxy:
SELECT sum("col") AS "shift_1_days" FROM "m" WHERE time >= now() - 3h - 1d GROUP BY time(1m)

Which real need:
SELECT sum("col") AS "shift_1_days" FROM "m" WHERE time <= now() - 1d AND time >= now() - 3h - 1d GROUP BY time(1m)

FIX:

function fix_query_time_relative(q, reg, count, unit) {
    const match = q.match(reg);
    if (match) {
        return q.replace(match[0], match[0] + " - " + moment.duration(count, unit).valueOf() + "ms");
    }
    else if (reg === to_rel) {
        const match = q.match(from_rel);
        if (match) {
            return q.replace(match[0], "time <= now()" + " - " + moment.duration(count, unit).valueOf() + "ms AND " + match[0]);
        }
    }
    return q;
}
@dataviruset
Copy link

I found this quite useful. Unless this code breaks something, maybe you can submit a pull request? :)

dataviruset added a commit to dataviruset/influxdb-timeshift-proxy that referenced this issue Feb 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants