You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by ib...@apache.org on 2020/12/16 21:25:46 UTC
[beam] branch master updated: [BEAM-10925] Add SQL AggregateFn
interface.
This is an automated email from the ASF dual-hosted git repository.
ibzib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 3de4f88 [BEAM-10925] Add SQL AggregateFn interface.
new a7457c0 Merge pull request #13306 from ibzib/aggregate-udf
3de4f88 is described below
commit 3de4f88aa8839af36e355060c8de62f9a6caf0e7
Author: Kyle Weaver <kc...@google.com>
AuthorDate: Wed Nov 11 13:05:20 2020 -0800
[BEAM-10925] Add SQL AggregateFn interface.
---
.../beam/sdk/extensions/sql/udf/AggregateFn.java | 70 ++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/sdks/java/extensions/sql/udf/src/main/java/org/apache/beam/sdk/extensions/sql/udf/AggregateFn.java b/sdks/java/extensions/sql/udf/src/main/java/org/apache/beam/sdk/extensions/sql/udf/AggregateFn.java
new file mode 100644
index 0000000..28ebf3b
--- /dev/null
+++ b/sdks/java/extensions/sql/udf/src/main/java/org/apache/beam/sdk/extensions/sql/udf/AggregateFn.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.sql.udf;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/**
+ * An aggregate function that can be executed as part of a SQL query.
+ *
+ * <p>AggregateFn contains a subset of the functionality of {@code
+ * org.apache.beam.sdk.transforms.Combine.CombineFn}.
+ *
+ * <p>AggregateFn is <strong>experimental</strong>. Compatibility is not guaranteed across Beam
+ * versions.
+ *
+ * @param <InputT> type of input values
+ * @param <AccumT> type of mutable accumulator values
+ * @param <OutputT> type of output values
+ */
+public interface AggregateFn<
+ InputT extends @Nullable Object,
+ AccumT extends @Nullable Object,
+ OutputT extends @Nullable Object> {
+
+ /**
+ * Returns a new, mutable accumulator value, representing the accumulation of zero input values.
+ */
+ AccumT createAccumulator();
+
+ /**
+ * Adds the given input value to the given accumulator, returning the new accumulator value.
+ *
+ * @param mutableAccumulator may be modified and returned for efficiency
+ * @param input should not be mutated
+ */
+ AccumT addInput(AccumT mutableAccumulator, InputT input);
+
+ /**
+ * Returns an accumulator representing the accumulation of all the input values accumulated in the
+ * merging accumulators.
+ *
+ * @param accumulators only the first accumulator may be modified and returned for efficiency; the
+ * other accumulators should not be mutated, because they may be shared with other code and
+ * mutating them could lead to incorrect results or data corruption.
+ */
+ AccumT mergeAccumulators(Iterable<AccumT> accumulators);
+
+ /**
+ * Returns the output value that is the result of combining all the input values represented by
+ * the given accumulator.
+ *
+ * @param accumulator can be modified for efficiency
+ */
+ OutputT extractOutput(AccumT accumulator);
+}