cryptoe commented on code in PR #13374:
URL: https://github.com/apache/druid/pull/13374#discussion_r1024776864


##########
integration-tests-ex/cases/src/test/resources/multi-stage-query/batch-index/wikipedia_index_msq.json:
##########
@@ -0,0 +1,4 @@
+{
+  "sqlTask" : "REPLACE INTO \"%%DATASOURCE%%\" OVERWRITE ALL\nWITH \"source\" 
as (SELECT * FROM TABLE(\n  EXTERN(\n    
'{\"type\":\"local\",\"files\":[\"/resources/data/batch_index/json/wikipedia_index_data1.json\",\"/resources/data/batch_index/json/wikipedia_index_data2.json\",\"/resources/data/batch_index/json/wikipedia_index_data3.json\"]}',\n
    '{\"type\":\"json\"}',\n    
'[{\"name\":\"timestamp\",\"type\":\"string\"},{\"name\":\"page\",\"type\":\"string\"},{\"name\":\"language\",\"type\":\"string\"},{\"name\":\"user\",\"type\":\"string\"},{\"name\":\"unpatrolled\",\"type\":\"string\"},{\"name\":\"newPage\",\"type\":\"string\"},{\"name\":\"robot\",\"type\":\"string\"},{\"name\":\"anonymous\",\"type\":\"string\"},{\"name\":\"namespace\",\"type\":\"string\"},{\"name\":\"continent\",\"type\":\"string\"},{\"name\":\"country\",\"type\":\"string\"},{\"name\":\"region\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"},{\"name\":\"added\",\"type\":\"double\"},{\"name\":\"de
 leted\",\"type\":\"double\"},{\"name\":\"delta\",\"type\":\"double\"}]'\n  
)\n))\nSELECT\n  TIME_FLOOR(CASE WHEN CAST(\"timestamp\" AS BIGINT) > 0 THEN 
MILLIS_TO_TIMESTAMP(CAST(\"timestamp\" AS BIGINT)) ELSE 
TIME_PARSE(\"timestamp\") END, 'PT1S') AS __time,\n  \"page\",\n  
\"language\",\n  \"user\",\n  \"unpatrolled\",\n  \"newPage\",\n  \"robot\",\n  
\"anonymous\",\n  \"namespace\",\n  \"continent\",\n  \"country\",\n  
\"region\",\n  \"city\",\n  COUNT(*) AS \"count\",\n  SUM(\"added\") AS 
\"added\",\n  SUM(\"deleted\") AS \"deleted\",\n  SUM(\"delta\") AS 
\"delta\",\n  APPROX_COUNT_DISTINCT_DS_THETA(\"user\") AS \"thetaSketch\",\n  
DS_QUANTILES_SKETCH(\"delta\") AS \"quantilesDoublesSketch\",\n  
APPROX_COUNT_DISTINCT_DS_HLL(\"user\") AS \"HLLSketchBuild\"\nFROM 
\"source\"\nGROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13\nPARTITIONED BY 
DAY",

Review Comment:
   Is it possible to prettify this long str somehow ?



##########
integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java:
##########
@@ -95,7 +95,7 @@ public String getQueryURL(String schemeAndHost)
    */
   public SqlTaskStatus submitMsqTask(String sqlQueryString) throws 
ExecutionException, InterruptedException
   {
-    return submitMsqTask(new SqlQuery(sqlQueryString, null, false, false, 
false, ImmutableMap.of(), null));
+    return submitMsqTask(new SqlQuery(sqlQueryString, null, false, false, 
false, ImmutableMap.of("finalizeAggregations", false), null));

Review Comment:
   Long fix would be change it to a sql query builder. 
   The short fix would be to have the context param as part of the function 
argument. 
   I donot think its correct to have "finalizeAggregations", false as default 



##########
integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMSQForBatchIndex.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.druid.testsEx.msq;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.commons.io.IOUtils;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.msq.sql.SqlTaskStatus;
+import org.apache.druid.testing.IntegrationTestingConfig;
+import org.apache.druid.testing.clients.CoordinatorResourceTestClient;
+import org.apache.druid.testing.utils.DataLoaderHelper;
+import org.apache.druid.testing.utils.MsqSqlTasksWithTestQueries;
+import org.apache.druid.testing.utils.MsqTestQueryHelper;
+import org.apache.druid.testing.utils.TestQueryHelper;
+import org.apache.druid.testsEx.categories.MultiStageQuery;
+import org.apache.druid.testsEx.config.DruidTestRunner;
+import org.apache.druid.testsEx.indexer.AbstractITBatchIndexTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+@RunWith(DruidTestRunner.class)
+@Category(MultiStageQuery.class)
+public class ITMSQForBatchIndex

Review Comment:
   NIt: ITSQLBasedBatchIngestion



##########
integration-tests-ex/cases/src/test/resources/multi-stage-query/batch-index/wikipedia_index_msq.json:
##########
@@ -0,0 +1,4 @@
+{
+  "sqlTask" : "REPLACE INTO \"%%DATASOURCE%%\" OVERWRITE ALL\nWITH \"source\" 
as (SELECT * FROM TABLE(\n  EXTERN(\n    
'{\"type\":\"local\",\"files\":[\"/resources/data/batch_index/json/wikipedia_index_data1.json\",\"/resources/data/batch_index/json/wikipedia_index_data2.json\",\"/resources/data/batch_index/json/wikipedia_index_data3.json\"]}',\n
    '{\"type\":\"json\"}',\n    
'[{\"name\":\"timestamp\",\"type\":\"string\"},{\"name\":\"page\",\"type\":\"string\"},{\"name\":\"language\",\"type\":\"string\"},{\"name\":\"user\",\"type\":\"string\"},{\"name\":\"unpatrolled\",\"type\":\"string\"},{\"name\":\"newPage\",\"type\":\"string\"},{\"name\":\"robot\",\"type\":\"string\"},{\"name\":\"anonymous\",\"type\":\"string\"},{\"name\":\"namespace\",\"type\":\"string\"},{\"name\":\"continent\",\"type\":\"string\"},{\"name\":\"country\",\"type\":\"string\"},{\"name\":\"region\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"},{\"name\":\"added\",\"type\":\"double\"},{\"name\":\"de
 leted\",\"type\":\"double\"},{\"name\":\"delta\",\"type\":\"double\"}]'\n  
)\n))\nSELECT\n  TIME_FLOOR(CASE WHEN CAST(\"timestamp\" AS BIGINT) > 0 THEN 
MILLIS_TO_TIMESTAMP(CAST(\"timestamp\" AS BIGINT)) ELSE 
TIME_PARSE(\"timestamp\") END, 'PT1S') AS __time,\n  \"page\",\n  
\"language\",\n  \"user\",\n  \"unpatrolled\",\n  \"newPage\",\n  \"robot\",\n  
\"anonymous\",\n  \"namespace\",\n  \"continent\",\n  \"country\",\n  
\"region\",\n  \"city\",\n  COUNT(*) AS \"count\",\n  SUM(\"added\") AS 
\"added\",\n  SUM(\"deleted\") AS \"deleted\",\n  SUM(\"delta\") AS 
\"delta\",\n  APPROX_COUNT_DISTINCT_DS_THETA(\"user\") AS \"thetaSketch\",\n  
DS_QUANTILES_SKETCH(\"delta\") AS \"quantilesDoublesSketch\",\n  
APPROX_COUNT_DISTINCT_DS_HLL(\"user\") AS \"HLLSketchBuild\"\nFROM 
\"source\"\nGROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13\nPARTITIONED BY 
DAY",
+  "testQueriesFilePath" : 
"/multi-stage-query/batch-index/test-queries/wikipedia_index_msq_queries.json"

Review Comment:
   So if every test case has the same q's then it makes sense to create a new 
file else I would add the native q's here directly.  



##########
integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMSQForBatchIndex.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.druid.testsEx.msq;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.commons.io.IOUtils;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.msq.sql.SqlTaskStatus;
+import org.apache.druid.testing.IntegrationTestingConfig;
+import org.apache.druid.testing.clients.CoordinatorResourceTestClient;
+import org.apache.druid.testing.utils.DataLoaderHelper;
+import org.apache.druid.testing.utils.MsqSqlTasksWithTestQueries;
+import org.apache.druid.testing.utils.MsqTestQueryHelper;
+import org.apache.druid.testing.utils.TestQueryHelper;
+import org.apache.druid.testsEx.categories.MultiStageQuery;
+import org.apache.druid.testsEx.config.DruidTestRunner;
+import org.apache.druid.testsEx.indexer.AbstractITBatchIndexTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+@RunWith(DruidTestRunner.class)
+@Category(MultiStageQuery.class)
+public class ITMSQForBatchIndex
+{
+  public static final Logger LOG = new Logger(TestQueryHelper.class);
+  @Inject
+  private MsqTestQueryHelper msqHelper;
+
+  @Inject
+  protected TestQueryHelper queryHelper;
+
+  @Inject
+  private IntegrationTestingConfig config;
+
+  @Inject
+  private ObjectMapper jsonMapper;
+
+  @Inject
+  private DataLoaderHelper dataLoaderHelper;
+
+  @Inject
+  private CoordinatorResourceTestClient coordinatorClient;
+
+  private static final String BATCH_INDEX_TASKS_DIR = 
"/multi-stage-query/batch-index/";
+
+  protected void doTestQuery(String dataSource, String queryFilePath)
+  {
+    try {
+      String queryResponseTemplate;
+      try {
+        InputStream is = 
AbstractITBatchIndexTest.class.getResourceAsStream(queryFilePath);
+        queryResponseTemplate = IOUtils.toString(is, StandardCharsets.UTF_8);
+      }
+      catch (IOException e) {
+        throw new ISE(e, "could not read query file: %s", queryFilePath);
+      }
+
+      queryResponseTemplate = StringUtils.replace(
+        queryResponseTemplate,
+        "%%DATASOURCE%%",
+        dataSource
+      );
+      queryHelper.testQueriesFromString(queryResponseTemplate);
+
+    }
+    catch (Exception e) {
+      LOG.error(e, "Error while testing");
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Test
+  public void testMsqIngestionForBatchIndexTasks() throws Exception
+  {
+    File[] files = (new 
File(getClass().getResource(BATCH_INDEX_TASKS_DIR).toURI())).listFiles();
+    LOG.info(Arrays.toString(files));
+    String datasource = "dst";
+    for (int i = 1; i < files.length; i++) {
+      LOG.info("Starting MSQ test for [%s]", files[i]);
+      MsqSqlTasksWithTestQueries batchSqlTasksAndQueries =
+          jsonMapper.readValue(
+              TestQueryHelper.class.getResourceAsStream(BATCH_INDEX_TASKS_DIR 
+ files[i].getName()),
+              new TypeReference<MsqSqlTasksWithTestQueries>()
+              {
+              }
+          );
+      // Clear up the datasource from the previous runs
+      coordinatorClient.unloadSegmentsForDataSource(datasource + 
files[i].getName());
+
+      String sqlTask = StringUtils.replace(
+          batchSqlTasksAndQueries.getSqlTask(),
+          "%%DATASOURCE%%",
+          datasource + files[i].getName()
+      );
+
+      LOG.info("SqlTask - \n %s", sqlTask);
+
+      // Submit the tasks and wait for the datasource to get loaded
+      SqlTaskStatus sqlTaskStatus = msqHelper.submitMsqTask(sqlTask);
+
+      LOG.info("Sql Task submitted with task Id - %s", 
sqlTaskStatus.getTaskId());
+
+      if (sqlTaskStatus.getState().isFailure()) {
+        Assert.fail(StringUtils.format(
+              "Unable to start the task successfully.\nPossible exception: %s",
+              sqlTaskStatus.getError()
+        ));
+      }
+      msqHelper.pollTaskIdForCompletion(sqlTaskStatus.getTaskId());
+      dataLoaderHelper.waitUntilDatasourceIsReady(datasource + 
files[i].getName());

Review Comment:
   I think this should be pushed inside msqHelper or a base test class. It 
would most likely get copied in every test case.



##########
integration-tests/src/main/java/org/apache/druid/testing/utils/MsqSqlTasksWithTestQueries.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.druid.testing.utils;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class MsqSqlTasksWithTestQueries
+{
+  private final String sqlTask;
+  private final String testQueriesFilePath;
+
+  @JsonCreator
+  public MsqSqlTasksWithTestQueries(

Review Comment:
   I think this class is not needed. 
   checkout : ITMultiStageQuery



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to