You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/12/02 11:25:13 UTC

[GitHub] [beam] rezarokni commented on a change in pull request #12973: [BEAM-10234] Create ApproximateDistinct using HLL Impl

rezarokni commented on a change in pull request #12973:
URL: https://github.com/apache/beam/pull/12973#discussion_r534093226



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/ApproximateUnique.java
##########
@@ -56,7 +56,10 @@
  *
  * For more details about using {@code HllCount} and the {@code zetasketch} extension module, see
  * https://s.apache.org/hll-in-beam#bookmark=id.v6chsij1ixo7.
+ *
+ * @deprecated use {@code ApproximateCountDistinct} which has moved to HLL implementation.

Review comment:
       Changed the comments. But not added snippets yet, would it be ok to just assume they will look at the new location?

##########
File path: sdks/java/extensions/zetasketch/src/main/java/org/apache/beam/sdk/extensions/zetasketch/ApproximateCountDistinct.java
##########
@@ -0,0 +1,287 @@
+/*
+ * 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.zetasketch;
+
+import com.google.auto.value.AutoValue;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.KvCoder;
+import org.apache.beam.sdk.extensions.zetasketch.HllCount.Init.Builder;
+import org.apache.beam.sdk.transforms.Contextful;
+import org.apache.beam.sdk.transforms.Contextful.Fn;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ProcessFunction;
+import org.apache.beam.sdk.transforms.display.DisplayData;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@code PTransform}s for estimating the number of distinct elements in a {@code PCollection}, or
+ * the number of distinct values associated with each key in a {@code PCollection} of {@code KV}s.
+ *
+ * <p>We make use of the {@link HllCount} implementation for this transform. Please use {@link
+ * HllCount} directly if you need access to the sketches.
+ *
+ * <p>If the object is not one of {@link Byte[]} {@link Integer} {@link Double} {@link String} make
+ * use of {@link Globally#via} or {@link PerKey#via}
+ *
+ * <h3>Examples</h3>
+ *
+ * <h4>Example 1: Approximate Count of Longs {@code PCollection<Long>} and specify precision</h4>

Review comment:
       Done.

##########
File path: sdks/java/extensions/zetasketch/src/main/java/org/apache/beam/sdk/extensions/zetasketch/ApproximateCountDistinct.java
##########
@@ -0,0 +1,287 @@
+/*
+ * 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.zetasketch;
+
+import com.google.auto.value.AutoValue;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.KvCoder;
+import org.apache.beam.sdk.extensions.zetasketch.HllCount.Init.Builder;
+import org.apache.beam.sdk.transforms.Contextful;
+import org.apache.beam.sdk.transforms.Contextful.Fn;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ProcessFunction;
+import org.apache.beam.sdk.transforms.display.DisplayData;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@code PTransform}s for estimating the number of distinct elements in a {@code PCollection}, or
+ * the number of distinct values associated with each key in a {@code PCollection} of {@code KV}s.
+ *
+ * <p>We make use of the {@link HllCount} implementation for this transform. Please use {@link
+ * HllCount} directly if you need access to the sketches.
+ *
+ * <p>If the object is not one of {@link Byte[]} {@link Integer} {@link Double} {@link String} make
+ * use of {@link Globally#via} or {@link PerKey#via}
+ *
+ * <h3>Examples</h3>
+ *
+ * <h4>Example 1: Approximate Count of Longs {@code PCollection<Long>} and specify precision</h4>
+ *
+ * <pre>{@Code
+ *     p.apply("Int", Create.of(ints)).apply("IntHLL", ApproximateCountDistinct.globally()

Review comment:
       Yes, corrected.




----------------------------------------------------------------
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:
users@infra.apache.org