Jackie-Jiang commented on a change in pull request #4535: Implement DISTINCT 
clause
URL: https://github.com/apache/incubator-pinot/pull/4535#discussion_r319706007
 
 

 ##########
 File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/DistinctTable.java
 ##########
 @@ -0,0 +1,235 @@
+/**
+ * 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.pinot.core.query.aggregation;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.apache.pinot.common.data.FieldSpec;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.common.utils.DataTable;
+import org.apache.pinot.core.common.datatable.DataTableBuilder;
+import org.apache.pinot.core.common.datatable.DataTableFactory;
+import org.apache.pinot.core.data.table.Key;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This serves the following purposes:
+ *
+ * (1) Intermediate result object for Distinct aggregation function
+ * (2) The same object is serialized by the server inside the data table
+ * for sending the results to broker. Broker deserializes it.
+ */
+public class DistinctTable {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DistinctTable.class);
+  private final static int INITIAL_CAPACITY = 64000;
+  private FieldSpec.DataType[] _projectedColumnTypes;
+  private String[] _projectedColumnNames;
+  private int _recordLimit;
+  private Set<Key> _table;
+
+  /**
+   * Add a row to hash table
+   * @param key multi-column key to add
+   */
+  public void addKey(final Key key) {
+    if (_table.size() >= _recordLimit) {
+      LOGGER.info("Distinct table Reached allowed max cardinality of {}", 
_recordLimit);
+      return;
+    }
+
+    _table.add(key);
+  }
+
+  public DistinctTable(int recordLimit) {
+    _recordLimit = recordLimit;
+    _table = new HashSet<>(INITIAL_CAPACITY);
+  }
+
+  /**
+   * DESERIALIZE: Broker side
+   * @param byteBuffer data to deserialize
+   * @throws IOException
+   */
+  public DistinctTable(final ByteBuffer byteBuffer) throws IOException {
+    final DataTable dataTable = DataTableFactory.getDataTable(byteBuffer);
+    final DataSchema dataSchema = dataTable.getDataSchema();
+    final int numRows = dataTable.getNumberOfRows();
+    final int numColumns = dataSchema.size();
+
+    _table = new HashSet<>();
+
+    // extract rows from the datatable
+    for (int rowIndex  = 0; rowIndex < numRows; rowIndex++) {
 
 Review comment:
   format the class

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to