Github user jihoonson commented on a diff in the pull request:
https://github.com/apache/tajo/pull/200#discussion_r18820375
--- Diff:
tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/statistics/Histogram.java
---
@@ -0,0 +1,238 @@
+/**
+ * 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.tajo.catalog.statistics;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tajo.catalog.json.CatalogGsonHelper;
+import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.common.ProtoObject;
+import org.apache.tajo.json.GsonObject;
+import org.apache.tajo.util.TUtil;
+
+import com.google.common.base.Objects;
+import com.google.gson.annotations.Expose;
+
+public class Histogram implements
ProtoObject<CatalogProtos.HistogramProto>, Cloneable, GsonObject {
+
+ @Expose protected Long lastAnalyzed = null; // optional
+ @Expose protected List<HistogramBucket> buckets = null; // repeated
+ @Expose protected boolean isReady; // whether this histogram is ready to
be used for selectivity estimation
+ protected int DEFAULT_MAX_BUCKETS = 100; // Same as PostgreSQL
+
+ public Histogram() {
+ buckets = TUtil.newList();
+ isReady = false;
+ }
+
+ public Histogram(CatalogProtos.HistogramProto proto) {
+ if (proto.hasLastAnalyzed()) {
+ this.lastAnalyzed = proto.getLastAnalyzed();
+ }
+ buckets = TUtil.newList();
+ for (CatalogProtos.HistogramBucketProto bucketProto :
proto.getBucketsList()) {
+ this.buckets.add(new HistogramBucket(bucketProto));
+ }
+ isReady = true;
+ }
+
+ public Long getLastAnalyzed() {
+ return this.lastAnalyzed;
+ }
+
+ public void setLastAnalyzed(Long lastAnalyzed) {
+ this.lastAnalyzed = lastAnalyzed;
+ }
+
+ public List<HistogramBucket> getBuckets() {
+ return this.buckets;
+ }
+
+ public void setBuckets(List<HistogramBucket> buckets) {
+ this.buckets = new ArrayList<HistogramBucket>(buckets);
+ }
+
+ public void addBucket(HistogramBucket bucket) {
+ this.buckets.add(bucket);
+ }
+
+ public int getBucketsCount() {
+ return this.buckets.size();
+ }
+
+ public boolean getIsReady() {
+ return this.isReady;
+ }
+
+ public void setIsReady(boolean isReady) {
+ this.isReady = isReady;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof Histogram) {
+ Histogram other = (Histogram) obj;
+ return getLastAnalyzed().equals(other.getLastAnalyzed())
+ && TUtil.checkEquals(this.buckets, other.buckets);
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ return Objects.hashCode(this.lastAnalyzed, this.buckets);
+ }
+
+ public Histogram clone() throws CloneNotSupportedException {
+ Histogram hist = (Histogram) super.clone();
+ hist.lastAnalyzed = this.lastAnalyzed;
+ hist.buckets = new ArrayList<HistogramBucket>(this.buckets);
+ hist.isReady = this.isReady;
+ return hist;
+ }
+
+ public String toString() {
+ return CatalogGsonHelper.getPrettyInstance().toJson(this,
Histogram.class);
+ }
+
+ @Override
+ public String toJson() {
+ return CatalogGsonHelper.toJson(this, Histogram.class);
+ }
+
+
+ @Override
+ public CatalogProtos.HistogramProto getProto() {
+ CatalogProtos.HistogramProto.Builder builder =
CatalogProtos.HistogramProto.newBuilder();
+ if (this.lastAnalyzed != null) {
+ builder.setLastAnalyzed(this.lastAnalyzed);
+ }
+ if (this.buckets != null) {
+ for (HistogramBucket bucket : buckets) {
+ builder.addBuckets(bucket.getProto());
+ }
+ }
+ return builder.build();
+ }
+
+ /**
+ * Construct a histogram. Compute the number of buckets and the min,
max, frequency values for each of them. This
+ * method must be overridden by specific sub-classes. The number of
buckets should be less than or equal to the
+ * sample size.
+ *
+ * @param samples
+ * Sample data points to construct the histogram. This
collection should fit in the memory and Null values
+ * should never appear in it.
+ * @return Return true if the computation is done without any problem.
Otherwise, return false
+ */
+ public boolean construct(List<Double> samples) {
--- End diff --
Do you have any reasons for restricting the type of samples as double?
In Tajo, Datum is the basic class to contain values.
IMO, NumericDatum will be more proper type rather than Double.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---