Skip to content

Add support for elapsed in the Flux DSL #662

Description

@aivinog1

Proposal:
The Flux already has the elapsed function. But the Flux DSL is missing this function.

Current behavior:
There is no such function in the com.influxdb.query.dsl.Flux class.

Desired behavior:
I should be able to use the elapsed function, something like this:

Flux flux = Flux
    .from("telegraf")
    .groupBy("_measurement")
    .elaspsed(); // the default unit is 1s

Alternatives considered:
I can't see any alternatives.

Use case:
I am using this while I am building queries:

public static class ElapsedFunction extends AbstractParametrizedFlux {

        public ElapsedFunction(final Flux source) {
            super(source);
        }

        @NotNull
        @Override
        protected String operatorName() {
            return "elapsed";
        }

        public ElapsedFunction withUnit(final Long amount,
                                        @Nullable final ChronoUnit unit) {
            this.withPropertyValue("unit", amount, unit);
            return this;
        }
 }

final Flux query = Flux
                    .from(INFLUX_DB_CONTAINER.getBucket())
                    .withBucket(INFLUX_DB_CONTAINER.getBucket())
                    .range().withStart(Instant.now(clock).minus(1, ChronoUnit.HOURS)).withStop(Instant.now(clock).plus(1, ChronoUnit.HOURS))
                    .filter(Restrictions.measurement().equal("measurement"))
                    .filter(Restrictions.tag("someTag").equal("someValue"))
                    .groupBy("_value")
                    .function(ElapsedFunction.class).withUnit(1L, ChronoUnit.NANOS)
                    .group()
                    .quantile().withColumn("elapsed").withQuantile(0.9999f)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions