You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/07/01 23:30:32 UTC

[GitHub] [incubator-pinot] sajjad-moradi commented on a change in pull request #5514: Add integration test for theta sketches

sajjad-moradi commented on a change in pull request #5514:
URL: https://github.com/apache/incubator-pinot/pull/5514#discussion_r448667440



##########
File path: pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ThetaSketchIntegrationTest.java
##########
@@ -0,0 +1,263 @@
+/**
+ * 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.integration.tests;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.ImmutableList;
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.avro.Schema.Field;
+import org.apache.avro.Schema.Type;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.datasketches.theta.UpdateSketch;
+import org.apache.datasketches.theta.UpdateSketchBuilder;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.util.TestUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+public class ThetaSketchIntegrationTest extends BaseClusterIntegrationTest {
+
+  private static final String DIM_NAME = "dimName";
+  private static final String DIM_VALUE = "dimValue";
+  private static final String SHARD_ID = "shardId";
+  private static final String THETA_SKETCH = "thetaSketchCol";
+
+  @BeforeClass
+  public void setup()
+      throws Exception {
+    TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir);
+
+    // Start the Pinot cluster
+    startZk();
+    startController();
+    startBroker();
+    startServer();
+
+    // create & upload schema AND table config
+    Schema schema = new Schema.SchemaBuilder().setSchemaName(DEFAULT_SCHEMA_NAME)
+        .addSingleValueDimension(DIM_NAME, FieldSpec.DataType.STRING)
+        .addSingleValueDimension(DIM_VALUE, FieldSpec.DataType.STRING)
+        .addSingleValueDimension(SHARD_ID, FieldSpec.DataType.INT)
+        .addSingleValueDimension(THETA_SKETCH, FieldSpec.DataType.BYTES).build();
+    addSchema(schema);
+    TableConfig tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(DEFAULT_TABLE_NAME).build();
+    addTableConfig(tableConfig);
+
+    // create & upload segments
+    File avroFile = createAvroFile();
+    ClusterIntegrationTestUtils.buildSegmentFromAvro(avroFile, tableConfig, schema, 0, _segmentDir, _tarDir);
+    uploadSegments(DEFAULT_TABLE_NAME, _tarDir);
+
+    waitForAllDocsLoaded(60_000);
+  }
+
+  @Override
+  protected long getCountStarResult() {
+    /*
+    Uploaded table content:
+
+    row#  dimName  dimValue  shardId  thetaSketchCol
+    ----  =======  ========  =======  ==============
+    1     country  US        1        ...
+    2     country  CA        1        ...
+    3     country  MX        1        ...
+    4     title    Engineer  1        ...
+    5     title    Manager   1        ...
+    6     country  US        2        ...
+    7     country  CA        2        ...
+    8     country  MX        2        ...
+    9     title    Engineer  2        ...
+    10    title    Manager   2        ...
+     */
+    return 10;
+  }
+
+  @Test
+  public void testThetaSketchQuery()
+      throws Exception {
+    /*
+    Original data:
+
+    Title     Country  Shard#1  Shard#2
+    --------  -------  -------  -------
+    Engineer  US       50       110
+    Engineer  CA       60       120
+    Engineer  MX       70       130
+    Manager   US       80       140
+    Manager   CA       90       150
+    Manager   MX       100      160
+     */
+
+    // title = engineer
+    String query = "select distinctCountThetaSketch(thetaSketchCol, '', "

Review comment:
       I just added the test case for groupby and also ran everything against sql endpoint as well.
   For utility method, I intentionally didn't use it here because this is a slightly complicated aggregation function and I wanted to spell out the queries so the reader can easily see what the syntax is and what the differences are.
   




----------------------------------------------------------------
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



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