+ * Flux flux = Flux + * .from("telegraf") + * .duplicate("host", "server"); ** * @author Jakub Bednar (bednar@github) (09/10/2018 13:13) diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/ExpressionFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/ExpressionFlux.java index 06c6fd81201..1d2a561ba0c 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/ExpressionFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/ExpressionFlux.java @@ -38,7 +38,6 @@ * * * @author Jakub Bednar (bednar@github) (27/06/2018 11:21) - * @since 1.0.0 */ public final class ExpressionFlux extends AbstractFluxWithUpstream { diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/FilterFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/FilterFlux.java index 1cf91722014..943059b253e 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/FilterFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/FilterFlux.java @@ -28,7 +28,7 @@ import org.influxdata.platform.Arguments; /** - * filter - + * filter - * Filters the results using an expression. * *
+ * Flux flux = Flux.from("telegraf") + * .pivot() + * .withRowKey(new String[]{"_time"}) + * .withColKey(new String[]{"_field"}) + * .withValueCol("_value"); + *+ * + * @author Jakub Bednar (10/10/2018 06:16) + */ +public final class PivotFlux extends AbstractParametrizedFlux { + + public PivotFlux(@Nonnull final Flux source) { + super(source); + } + + @Nonnull + @Override + protected String operatorName() { + return "pivot"; + } + + /** + * @param rowKey the columns used to uniquely identify a row for the output. + * @return this + */ + @Nonnull + public PivotFlux withRowKey(@Nonnull final String[] rowKey) { + + Arguments.checkNotNull(rowKey, "rowKey"); + + this.withPropertyValue("rowKey", rowKey); + + return this; + } + + /** + * @param rowKey the columns used to uniquely identify a row for the output. + * @return this + */ + @Nonnull + public PivotFlux withRowKey(@Nonnull final Collection
@@ -37,7 +37,6 @@ ** * @author Jakub Bednar (bednar@github) (25/06/2018 15:57) - * @since 1.0.0 */ public final class ToBoolFlux extends AbstractParametrizedFlux { diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToDurationFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToDurationFlux.java index 6a0c5c1c707..eee34e9357d 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToDurationFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToDurationFlux.java @@ -26,7 +26,7 @@ import org.influxdata.flux.Flux; /** - * toDuration - + * toDuration - * Convert a value to a duration. * *
diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToIntFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToIntFlux.java index aa10b355609..a704b16c038 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToIntFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToIntFlux.java @@ -26,7 +26,7 @@ import org.influxdata.flux.Flux; /** - * toInt - Convert a value to a int. + * toInt - Convert a value to a int. * ** * @author Jakub Bednar (bednar@github) (26/06/2018 06:40) - * @since 1.0.0 */ public final class ToUIntFlux extends AbstractParametrizedFlux { diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/WindowFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/WindowFlux.java index 891457aab32..0f877f22fcd 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/WindowFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/WindowFlux.java @@ -29,7 +29,7 @@ import org.influxdata.platform.Arguments; /** - * window - Groups the results by + * window - Groups the results by * a given time range. * *Example
*diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToStringFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToStringFlux.java index 8b4798f1a84..9dbca99bc67 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToStringFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToStringFlux.java @@ -26,7 +26,7 @@ import org.influxdata.flux.Flux; /** - * toString - Convert a value + * toString - Convert a value * to a string. * ** * @author Jakub Bednar (bednar@github) (26/06/2018 06:32) - * @since 1.0.0 */ public final class ToStringFlux extends AbstractParametrizedFlux { diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToTimeFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToTimeFlux.java index 3eceff1d306..6385cfa814a 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToTimeFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToTimeFlux.java @@ -26,7 +26,7 @@ import org.influxdata.flux.Flux; /** - * toTime - Convert a value to a time. + * toTime - Convert a value to a time. * *Example
@@ -38,7 +38,6 @@ *Example
*@@ -37,7 +37,6 @@ ** * @author Jakub Bednar (bednar@github) (26/06/2018 06:37) - * @since 1.0.0 */ public final class ToTimeFlux extends AbstractParametrizedFlux { diff --git a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToUIntFlux.java b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToUIntFlux.java index c248eec4534..9ec2b4b8186 100644 --- a/flux-dsl/src/main/java/org/influxdata/flux/functions/ToUIntFlux.java +++ b/flux-dsl/src/main/java/org/influxdata/flux/functions/ToUIntFlux.java @@ -26,7 +26,7 @@ import org.influxdata.flux.Flux; /** - * toDuration - + * toDuration - * Convert a value to a duration. * *Example
@@ -38,7 +38,6 @@ *
* A duration literal is a representation of a length of time. It has an integer part and a duration unit part.
*
diff --git a/flux-dsl/src/test/java/org/influxdata/flux/functions/PivotFluxTest.java b/flux-dsl/src/test/java/org/influxdata/flux/functions/PivotFluxTest.java
new file mode 100644
index 00000000000..fcc997c0ff8
--- /dev/null
+++ b/flux-dsl/src/test/java/org/influxdata/flux/functions/PivotFluxTest.java
@@ -0,0 +1,80 @@
+/*
+ * The MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.influxdata.flux.functions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.influxdata.flux.Flux;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.platform.runner.JUnitPlatform;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Jakub Bednar (10/10/2018 06:59)
+ */
+@RunWith(JUnitPlatform.class)
+class PivotFluxTest {
+
+ @Test
+ void pivot() {
+
+ Flux flux = Flux.from("telegraf")
+ .pivot()
+ .withRowKey(new String[]{"_time"})
+ .withColKey(new String[]{"_field"})
+ .withValueCol("_value");
+
+ String expected = "from(bucket:\"telegraf\") |> pivot(rowKey: [\"_time\"], colKey: [\"_field\"], valueCol: \"_value\")";
+
+ Assertions.assertThat(flux.toString()).isEqualToIgnoringWhitespace(expected);
+ }
+
+ @Test
+ void pivotArray() {
+
+ Flux flux = Flux.from("telegraf")
+ .pivot(new String[]{"_time"}, new String[]{"_measurement", "_field"}, "_value");
+
+ String expected = "from(bucket:\"telegraf\") |> pivot(rowKey: [\"_time\"], colKey: [\"_measurement\", \"_field\"], valueCol: \"_value\")";
+
+ Assertions.assertThat(flux.toString()).isEqualToIgnoringWhitespace(expected);
+ }
+
+ @Test
+ void pivotCollection() {
+
+ List