Skip to content

Commit

Permalink
Added to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Oct 10, 2018
1 parent fc555b0 commit cb21c10
Show file tree
Hide file tree
Showing 45 changed files with 603 additions and 67 deletions.
14 changes: 14 additions & 0 deletions flux-dsl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,20 @@ Flux flux = Flux
.from("telegraf")
.sum();
```
### to
The To operation takes data from a stream and writes it to a bucket [[doc](http://bit.ly/flux-spec#to)].
- `bucket` - The bucket to which data will be written. [string]
- `bucketID` - The ID of the bucket to which data will be written. [string]
- `org` - The organization name of the above bucket. [string]
- `orgID` - The organization ID of the above bucket. [string]
- `host` - The remote host to write to. [string]
- `token` - The authorization token to use when writing to a remote host. [string]
- `timeColumn` - The time column of the output. [string]
- `tagColumns` - The tag columns of the output. **Default:** All columns of type string, excluding all value columns and the `_field` column if present. [array of strings]
- `fieldFn` - Function that takes a record from the input table and returns an object. For each record from the input table fieldFn returns on object that maps output field key to output value. **Default:** `(r) => ({ [r._field]: r._value })` [function(record) object]
```java

```

### toBool
Convert a value to a bool [[doc](http://bit.ly/flux-spec#tobool)].
Expand Down
171 changes: 170 additions & 1 deletion flux-dsl/src/main/java/org/influxdata/flux/Flux.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.influxdata.flux.functions.ToBoolFlux;
import org.influxdata.flux.functions.ToDurationFlux;
import org.influxdata.flux.functions.ToFloatFlux;
import org.influxdata.flux.functions.ToFlux;
import org.influxdata.flux.functions.ToIntFlux;
import org.influxdata.flux.functions.ToStringFlux;
import org.influxdata.flux.functions.ToTimeFlux;
Expand Down Expand Up @@ -121,7 +122,7 @@
* <li>!TODO stateTracking - Not defined in documentation or SPEC</li>
* <li>{@link StddevFlux}</li>
* <li>{@link SumFlux}</li>
* <li>!TODO - to</li>
* <li>{@link ToFlux}</li>
* <li>{@link ToBoolFlux}</li>
* <li>{@link ToIntFlux}</li>
* <li>{@link ToFloatFlux}</li>
Expand Down Expand Up @@ -1583,6 +1584,174 @@ public final SumFlux sum(final boolean useStartTime) {
return new SumFlux(this).withUseStartTime(useStartTime);
}

/**
* To operation takes data from a stream and writes it to a bucket.
*
* <h3>The parameters had to be defined by:</h3>
* <ul>
* <li>{@link ToFlux#withBucket(String)}</li>
* <li>{@link ToFlux#withBucketID(String)}</li>
* <li>{@link ToFlux#withOrg(String)}</li>
* <li>{@link ToFlux#withOrgID(String)}</li>
* <li>{@link ToFlux#withHost(String)}</li>
* <li>{@link ToFlux#withToken(String)}</li>
* <li>{@link ToFlux#withTimeColumn(String)}</li>
* <li>{@link ToFlux#withTagColumns(Collection)}</li>
* <li>{@link ToFlux#withTagColumns(String[])}</li>
* <li>{@link ToFlux#withFieldFunction(String)}</li>
* <li>{@link ToFlux#withPropertyNamed(String)}</li>
* <li>{@link ToFlux#withPropertyNamed(String, String)}</li>
* <li>{@link ToFlux#withPropertyValueEscaped(String, String)}</li>
* </ul>
*
* @return {@link ToFlux}
*/
@Nonnull
public final ToFlux to() {
return new ToFlux(this);
}

/**
* To operation takes data from a stream and writes it to a bucket.
*
* @param bucket The bucket to which data will be written.
* @param org The organization name of the above bucket.
* @return {@link ToFlux}
*/
@Nonnull
public final ToFlux to(@Nonnull final String bucket,
@Nonnull final String org) {

return new ToFlux(this)
.withBucket(bucket)
.withOrg(org);
}

/**
* To operation takes data from a stream and writes it to a bucket.
*
* @param bucket The bucket to which data will be written.
* @param org The organization name of the above bucket.
* @param fieldFn Function that takes a record from the input table and returns an object.
* @return {@link ToFlux}
*/
@Nonnull
public final ToFlux to(@Nonnull final String bucket,
@Nonnull final String org,
@Nonnull final String fieldFn) {

return new ToFlux(this)
.withBucket(bucket)
.withOrg(org)
.withFieldFunction(fieldFn);
}

/**
* To operation takes data from a stream and writes it to a bucket.
*
* @param bucket The bucket to which data will be written.
* @param org The organization name of the above bucket.
* @param tagColumns The tag columns of the output.
* @param fieldFn Function that takes a record from the input table and returns an object.
* @return {@link ToFlux}
*/
@Nonnull
public final ToFlux to(@Nonnull final String bucket,
@Nonnull final String org,
@Nonnull final String[] tagColumns,
@Nonnull final String fieldFn) {

return new ToFlux(this)
.withBucket(bucket)
.withOrg(org)
.withTagColumns(tagColumns)
.withFieldFunction(fieldFn);
}

/**
* To operation takes data from a stream and writes it to a bucket.
*
* @param bucket The bucket to which data will be written.
* @param org The organization name of the above bucket.
* @param tagColumns The tag columns of the output.
* @param fieldFn Function that takes a record from the input table and returns an object.
* @return {@link ToFlux}
*/
@Nonnull
public final ToFlux to(@Nonnull final String bucket,
@Nonnull final String org,
@Nonnull final Collection<String> tagColumns,
@Nonnull final String fieldFn) {

return new ToFlux(this)
.withBucket(bucket)
.withOrg(org)
.withTagColumns(tagColumns)
.withFieldFunction(fieldFn);
}

/**
* To operation takes data from a stream and writes it to a bucket.
*
* @param bucket The bucket to which data will be written.
* @param org The organization name of the above bucket.
* @param host The remote host to write to.
* @param token The authorization token to use when writing to a remote host.
* @param timeColumn The time column of the output.
* @param tagColumns The tag columns of the output.
* @param fieldFn Function that takes a record from the input table and returns an object.
* @return {@link ToFlux}
*/
@Nonnull
public final ToFlux to(@Nonnull final String bucket,
@Nonnull final String org,
@Nonnull final String host,
@Nonnull final String token,
@Nonnull final String timeColumn,
@Nonnull final String[] tagColumns,
@Nonnull final String fieldFn) {

return new ToFlux(this)
.withBucket(bucket)
.withOrg(org)
.withHost(host)
.withToken(token)
.withTimeColumn(timeColumn)
.withTagColumns(tagColumns)
.withFieldFunction(fieldFn);
}

/**
* To operation takes data from a stream and writes it to a bucket.
*
* @param bucket The bucket to which data will be written.
* @param org The organization name of the above bucket.
* @param host The remote host to write to.
* @param token The authorization token to use when writing to a remote host.
* @param timeColumn The time column of the output.
* @param tagColumns The tag columns of the output.
* @param fieldFn Function that takes a record from the input table and returns an object.
* @return {@link ToFlux}
*/
@Nonnull
public final ToFlux to(@Nonnull final String bucket,
@Nonnull final String org,
@Nonnull final String host,
@Nonnull final String token,
@Nonnull final String timeColumn,
@Nonnull final Collection<String> tagColumns,
@Nonnull final String fieldFn) {

return new ToFlux(this)
.withBucket(bucket)
.withOrg(org)
.withHost(host)
.withToken(token)
.withTimeColumn(timeColumn)
.withTagColumns(tagColumns)
.withFieldFunction(fieldFn);
}

/**
* Convert a value to a bool.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.influxdata.flux.Flux;

/**
* <a href="http://bit.ly/flux-spec#count">count</a> - Counts the number of results.
* Counts the number of results. <a href="http://bit.ly/flux-spec#count">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#covariance">covariance</a> -
* Covariance is an aggregate operation. Covariance computes the covariance between two columns.
* <a href="http://bit.ly/flux-spec#covariance">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#cumulative-sum">cumulativeSum</a> - Cumulative sum computes a running sum
* for non null records in the table. The output table schema will be the same as the input table
* Cumulative sum computes a running sum for non null records in the table.
* The output table schema will be the same as the input table.
* <a href="http://bit.ly/flux-spec#cumulative-sum">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#derivative">derivative</a> -
* Computes the time based difference between subsequent non null records.
* <a href="http://bit.ly/flux-spec#derivative">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#difference">difference</a> -
* Difference computes the difference between subsequent non null records.
* <a href="http://bit.ly/flux-spec#difference">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#distinct">distinct</a> - Distinct
* produces the unique values for a given column.
* Distinct produces the unique values for a given column.
* <a href="http://bit.ly/flux-spec#distinct">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#duplicate">duplicate</a> - Duplicate will
* duplicate a specified column in a table.
* Drop will exclude specified columns from a table.
* <a href="http://bit.ly/flux-spec#drop">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down Expand Up @@ -97,7 +97,6 @@ public DropFlux withColumns(@Nonnull final Collection<String> columns) {
return this;
}


/**
* @param function The function which takes a column name as a parameter and returns a boolean indicating whether
* or not the column should be excluded from the resulting table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#duplicate">duplicate</a> -Duplicate will
* duplicate a specified column in a table.
* Duplicate will duplicate a specified column in a table.
* <a href="http://bit.ly/flux-spec#duplicate">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#filter">filter</a> -
* Filters the results using an expression.
* <a href="http://bit.ly/flux-spec#filter">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.influxdata.flux.Flux;

/**
* <a href="http://bit.ly/flux-spec#first">first</a> - Returns the first result of
* the query.
* Returns the first result of the query.
* <a href="http://bit.ly/flux-spec#first">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import javax.annotation.Nonnull;

/**
* <a href="http://bit.ly/flux-spec#from">from</a> - starting point
* for all queries. Get data from the specified bucket.
* From produces a stream of tables from the specified bucket.
* <a href="http://bit.ly/flux-spec#from">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#group">group</a> - Groups results by
* a user-specified set of tags.
* Groups results by a user-specified set of tags.
* <a href="http://bit.ly/flux-spec#group">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#integral">integral</a> -
* For each aggregate column, it outputs the area under the curve of non null records.
* The curve is defined as function where the domain is the record times and the range is the record values.
* <a href="http://bit.ly/flux-spec#integral">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#join">join</a> -
* Join two time series together on time and the list of <i>on</i> keys.
* <a href="http://bit.ly/flux-spec#join">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import org.influxdata.platform.Arguments;

/**
* <a href="http://bit.ly/flux-spec#keep">keep</a> -
* Keep is the inverse of drop. It will return a table containing only columns that are specified, ignoring all others.
* Only columns in the group key that are also specified in keep will be kept in the resulting group key.
* <a href="http://bit.ly/flux-spec#keep">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.influxdata.flux.Flux;

/**
* <a href="http://bit.ly/flux-spec#last">last</a> - Returns the last result of
* the query.
* Returns the last result of the query.
* <a href="http://bit.ly/flux-spec#last">See SPEC</a>.
*
* <h3>Options</h3>
* <ul>
Expand Down
Loading

0 comments on commit cb21c10

Please sign in to comment.