influxdata/influxdb-client-java

how to use truncateTimeColumn or date.truncate?

sunnights opened this issue · 3 comments

I can't find the truncateTimeColumn function in flux-dsl,
or is there anyway to use package "date"?
It's important to me.

Hi @sunnights,

thanks for using our client.

I can't find the truncateTimeColumn function in flux-dsl,
or is there anyway to use package "date"?

Currently not, but you can create your own DSL function. Use the following code:

public static class TruncateTimeColumn extends AbstractParametrizedFlux {

    public TruncateTimeColumn(@Nonnull final Flux source) {
        super(source);
    }

    @Nonnull
    @Override
    protected String operatorName() {
        return "truncateTimeColumn";
    }

    /**
     * @param unit The unit of time to truncate to.
     * @return this
     */
    @Nonnull
    public TruncateTimeColumn withUnit(@Nonnull final String unit) {

        Arguments.checkDuration(unit, "Unit");

        withPropertyValue("unit", unit);

        return this;
    }
}
Flux flux = Flux
        .from("telegraf")
        .function(TruncateTimeColumn.class)
        .withUnit("1s");

System.out.println(flux);

Output:

from(bucket:"telegraf")
	|> truncateTimeColumn(unit:1s)

Regards

Thanks, it works for me!
I think you should update the readme doc
replace the operator with function.

BTW, flux-dsl doesn't support set TimeZone, is there any plan to support it?

Thanks, it works for me! I think you should update the readme doc replace the operator with function.

Good catch 👍, I will update the README.md.

BTW, flux-dsl doesn't support set TimeZone, is there any plan to support it?

Currently not, Is this something you might be willing to help with?