Skip to content
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

Add support for elapsed in the Flux DSL #662

Closed
aivinog1 opened this issue Dec 25, 2023 · 2 comments · Fixed by #705
Closed

Add support for elapsed in the Flux DSL #662

aivinog1 opened this issue Dec 25, 2023 · 2 comments · Fixed by #705
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@aivinog1
Copy link

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)
@bednar
Copy link
Contributor

bednar commented Jan 8, 2024

Hi @aivinog1,

thanks for your suggestion.

Is this something you would be willing to help with? All PR is welcome and we will be happy to review your submission.

Regards

@bednar bednar added good first issue Good for newcomers enhancement New feature or request labels Jan 8, 2024
@UltimateFighter
Copy link

I think this is an inherent function. Without the FLUX DSL in Java and the possibility of prepare statements, any development with the Java API is quite complicated and time-consuming, as you should not simply pass the string queries to the DB (risk of injection).

@karel-rehor karel-rehor mentioned this issue Apr 22, 2024
6 tasks
@bednar bednar added this to the 7.1.0 milestone Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants