darshanj commented on a change in pull request #11610: URL: https://github.com/apache/beam/pull/11610#discussion_r425689729
########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/SetFns.java ########## @@ -0,0 +1,618 @@ +/* + * 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.transforms; + +import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument; +import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull; + +import java.util.ArrayList; +import java.util.List; +import org.apache.beam.sdk.Pipeline; +import org.apache.beam.sdk.coders.Coder; +import org.apache.beam.sdk.transforms.join.CoGbkResult; +import org.apache.beam.sdk.transforms.join.CoGroupByKey; +import org.apache.beam.sdk.transforms.join.KeyedPCollectionTuple; +import org.apache.beam.sdk.transforms.windowing.Trigger; +import org.apache.beam.sdk.transforms.windowing.WindowFn; +import org.apache.beam.sdk.values.KV; +import org.apache.beam.sdk.values.PCollection; +import org.apache.beam.sdk.values.PCollectionList; +import org.apache.beam.sdk.values.TupleTag; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables; + +public class SetFns { + + /** + * Returns a new {@code PTransform} transform that follows SET DISTINCT semantics to compute the + * intersection with provided {@code PCollection<T>}. + * + * <p>The argument should not be modified after this is called. + * + * <p>The elements of the output {@link PCollection} will all distinct elements that present in + * both pipeline is constructed and provided {@link PCollection}. + * + * <p>Note that this transform requires that the {@code Coder} of the all {@code PCollection<T>} + * to be deterministic (see {@link Coder#verifyDeterministic()}). If the collection {@code Coder} + * is not deterministic, an exception is thrown at pipeline construction time. + * + * <p>All inputs must have equal {@link WindowFn}s and compatible triggers (see {@link + * Trigger#isCompatible(Trigger)}). + * + * <p>By default, the output {@code PCollection<T>} encodes its elements using the same {@code + * Coder} that of {@code PCollection<T>} + * + * <pre>{@code + * Pipeline p = ...; + * + * PCollection<String> left = p.apply(Create.of("1", "2", "3", "3","4", "5")); + * PCollection<String> right = p.apply(Create.of("1", "3", "4","4", "6")); + * + * PCollection<String> results = + * left.apply(SetFns.intersectDistinct(right)); // results will be PCollection<String> containing: "1","3","4" + * + * }</pre> + * + * @param <T> the type of the elements in the input and output {@code PCollection<T>}s. + */ + public static <T> SetImpl<T> intersectDistinct(PCollection<T> rightCollection) { + checkNotNull(rightCollection, "rightCollection argument is null"); + return new SetImpl<>(rightCollection, intersectDistinct()); + } + + /** + * Returns a {@code PTransform} that takes a {@code PCollectionList<PCollection<T>>} and returns a + * {@code PCollection<T>} containing intersection of collections done in order for all collections + * in {@code PCollectionList<T>}. + * + * <p>Returns a new {@code PTransform} transform that follows SET DISTINCT semantics which takes a + * {@code PCollectionList<PCollection<T>>} and returns a {@code PCollection<T>} containing + * intersection of collections done in order for all collections in {@code PCollectionList<T>}. + * + * <p>The elements of the output {@link PCollection} will have all distinct elements that are + * present in both pipeline is constructed and next {@link PCollection} in the list and applied to + * all collections in order. + * + * <p>Note that this transform requires that the {@code Coder} of the all {@code PCollection<T>} + * to be deterministic (see {@link Coder#verifyDeterministic()}). If the collection {@code Coder} + * is not deterministic, an exception is thrown at pipeline construction time. + * + * <p>All inputs must have equal {@link WindowFn}s and compatible triggers (see {@link + * Trigger#isCompatible(Trigger)}). + * + * <p>By default, the output {@code PCollection<T>} encodes its elements using the same {@code + * Coder} that of first in {@code PCollectionList<T>} Review comment: Thanks.Done ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/SetFns.java ########## @@ -0,0 +1,618 @@ +/* + * 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.transforms; + +import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument; +import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull; + +import java.util.ArrayList; +import java.util.List; +import org.apache.beam.sdk.Pipeline; +import org.apache.beam.sdk.coders.Coder; +import org.apache.beam.sdk.transforms.join.CoGbkResult; +import org.apache.beam.sdk.transforms.join.CoGroupByKey; +import org.apache.beam.sdk.transforms.join.KeyedPCollectionTuple; +import org.apache.beam.sdk.transforms.windowing.Trigger; +import org.apache.beam.sdk.transforms.windowing.WindowFn; +import org.apache.beam.sdk.values.KV; +import org.apache.beam.sdk.values.PCollection; +import org.apache.beam.sdk.values.PCollectionList; +import org.apache.beam.sdk.values.TupleTag; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables; + +public class SetFns { + + /** + * Returns a new {@code PTransform} transform that follows SET DISTINCT semantics to compute the + * intersection with provided {@code PCollection<T>}. + * + * <p>The argument should not be modified after this is called. + * + * <p>The elements of the output {@link PCollection} will all distinct elements that present in + * both pipeline is constructed and provided {@link PCollection}. + * + * <p>Note that this transform requires that the {@code Coder} of the all {@code PCollection<T>} + * to be deterministic (see {@link Coder#verifyDeterministic()}). If the collection {@code Coder} + * is not deterministic, an exception is thrown at pipeline construction time. + * + * <p>All inputs must have equal {@link WindowFn}s and compatible triggers (see {@link + * Trigger#isCompatible(Trigger)}). + * + * <p>By default, the output {@code PCollection<T>} encodes its elements using the same {@code + * Coder} that of {@code PCollection<T>} Review comment: Thanks.Done ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/SetFns.java ########## @@ -0,0 +1,528 @@ +/* + * 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.transforms; + +import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull; + +import java.util.ArrayList; +import java.util.List; +import org.apache.beam.sdk.Pipeline; +import org.apache.beam.sdk.transforms.join.CoGbkResult; +import org.apache.beam.sdk.transforms.join.CoGroupByKey; +import org.apache.beam.sdk.transforms.join.KeyedPCollectionTuple; +import org.apache.beam.sdk.values.KV; +import org.apache.beam.sdk.values.PCollection; +import org.apache.beam.sdk.values.PCollectionList; +import org.apache.beam.sdk.values.TupleTag; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables; + +public class SetFns { Review comment: Thanks.Done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
