-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Migrate current integration batch tests to equivalent MSQ tests #13374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a0639a
Migrate current integration batch tests to equivalent MSQ tests using…
1d85bc0
Fix build issues
6a7bece
Trigger Build
1b0f3ff
Adding more tests and addressing comments
23a6dfe
fixBuildIssues
d1aee52
fix dependency issues
eb29310
Parameterized the test and addressed comments
0699b19
Addressing comments
686f00f
fixing checkstyle errors
57ec9b6
Adressing comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...ests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/AbstractITSQLBasedIngestion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * 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.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.testing.utils.DataLoaderHelper; | ||
| import org.apache.druid.testing.utils.MsqTestQueryHelper; | ||
| import org.apache.druid.testing.utils.TestQueryHelper; | ||
| import org.apache.druid.testsEx.indexer.AbstractITBatchIndexTest; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Map; | ||
|
|
||
| public class AbstractITSQLBasedIngestion | ||
| { | ||
| public static final Logger LOG = new Logger(TestQueryHelper.class); | ||
| @Inject | ||
| private MsqTestQueryHelper msqHelper; | ||
|
|
||
| @Inject | ||
| protected TestQueryHelper queryHelper; | ||
|
|
||
| @Inject | ||
| private DataLoaderHelper dataLoaderHelper; | ||
|
|
||
| /** | ||
| * Reads file as utf-8 string and replace %%DATASOURCE%% with the provide datasource value. | ||
| */ | ||
| protected String getStringFromFileAndReplaceDatasource(String filePath, String datasource) | ||
| { | ||
| String fileString; | ||
| try { | ||
| InputStream is = AbstractITBatchIndexTest.class.getResourceAsStream(filePath); | ||
| fileString = IOUtils.toString(is, StandardCharsets.UTF_8); | ||
| } | ||
| catch (IOException e) { | ||
| throw new ISE(e, "could not read query file: %s", filePath); | ||
| } | ||
|
|
||
| fileString = StringUtils.replace( | ||
| fileString, | ||
| "%%DATASOURCE%%", | ||
| datasource | ||
| ); | ||
|
|
||
| return fileString; | ||
| } | ||
|
|
||
| /** | ||
| * Reads native queries from a file and runs against the provided datasource. | ||
| */ | ||
| protected void doTestQuery(String queryFilePath, String dataSource) | ||
| { | ||
| try { | ||
| String query = getStringFromFileAndReplaceDatasource(queryFilePath, dataSource); | ||
| queryHelper.testQueriesFromString(query); | ||
| } | ||
| catch (Exception e) { | ||
| LOG.error(e, "Error while running test query"); | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sumits a sqlTask, waits for task completion and then runs test queries on ingested datasource. | ||
| */ | ||
| protected void submitTaskAnddoTestQuery(String sqlTask, String queryFilePath, String datasource, | ||
| Map<String, Object> msqContext) throws Exception | ||
| { | ||
| LOG.info("SqlTask - \n %s", sqlTask); | ||
|
|
||
| // Submit the tasks and wait for the datasource to get loaded | ||
| msqHelper.submitMsqTaskAndWaitForCompletion( | ||
| sqlTask, | ||
| msqContext | ||
| ); | ||
|
|
||
| dataLoaderHelper.waitUntilDatasourceIsReady(datasource); | ||
| doTestQuery(queryFilePath, datasource); | ||
| } | ||
|
|
||
| /** | ||
| * Runs a MSQ ingest sql test. | ||
| * | ||
| * @param sqlFilePath path of file containing the sql query. | ||
| * @param queryFilePath path of file containing the native test queries to be run on the ingested datasource. | ||
| * @param datasource name of the datasource. %%DATASOURCE%% in the sql and queries will be replaced with this value. | ||
| * @param msqContext context parameters to be passed with MSQ API call. | ||
| */ | ||
| protected void runMSQTaskandTestQueries(String sqlFilePath, String queryFilePath, String datasource, | ||
| Map<String, Object> msqContext) throws Exception | ||
| { | ||
| LOG.info("Starting MSQ test for [%s, %s]", sqlFilePath, queryFilePath); | ||
|
|
||
| String sqlTask = getStringFromFileAndReplaceDatasource(sqlFilePath, datasource); | ||
| submitTaskAnddoTestQuery(sqlTask, queryFilePath, datasource, msqContext); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
...n-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITSQLBasedBatchIngestion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * 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 junitparams.Parameters; | ||
| import org.apache.commons.io.FilenameUtils; | ||
| import org.apache.curator.shaded.com.google.common.collect.ImmutableMap; | ||
| import org.apache.druid.testsEx.categories.MultiStageQuery; | ||
| import org.apache.druid.testsEx.config.DruidTestRunner; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| @RunWith(DruidTestRunner.class) | ||
| @Category(MultiStageQuery.class) | ||
| public class ITSQLBasedBatchIngestion extends AbstractITSQLBasedIngestion | ||
| { | ||
| private static final String BATCH_INDEX_TASKS_DIR = "/multi-stage-query/batch-index/"; | ||
|
|
||
| public static List<List<String>> test_cases() | ||
| { | ||
| return Arrays.asList( | ||
| Arrays.asList("msq_inline.sql", "json_path_index_queries.json"), | ||
| Arrays.asList("sparse_column_msq.sql", "sparse_column_msq.json"), | ||
| Arrays.asList("wikipedia_http_inputsource_msq.sql", "wikipedia_http_inputsource_queries.json"), | ||
| Arrays.asList("wikipedia_index_msq.sql", "wikipedia_index_queries.json"), | ||
| Arrays.asList("wikipedia_merge_index_task.sql", "wikipedia_index_queries.json"), | ||
| Arrays.asList("wikipedia_index_task_with_transform.sql", "wikipedia_index_queries_with_transform.json") | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| @Parameters(method = "test_cases") | ||
| public void testSQLBasedBatchIngestion(String sqlFileName, String queryFileName) | ||
| { | ||
| try { | ||
| runMSQTaskandTestQueries(BATCH_INDEX_TASKS_DIR + sqlFileName, | ||
| BATCH_INDEX_TASKS_DIR + queryFileName, | ||
| FilenameUtils.removeExtension(sqlFileName), | ||
| ImmutableMap.of("finalizeAggregations", false, | ||
| "maxNumTasks", 5, | ||
| "groupByEnableMultiValueUnnesting", false | ||
| )); | ||
| } | ||
| catch (Exception e) { | ||
|
abhagraw marked this conversation as resolved.
|
||
| LOG.error(e, "Error while testing [%s, %s]", sqlFileName, queryFileName); | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
49 changes: 49 additions & 0 deletions
49
...ts-ex/cases/src/test/resources/multi-stage-query/batch-index/json_path_index_queries.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| [ | ||
| { | ||
| "description": "timeseries", | ||
| "query": { | ||
| "queryType": "timeseries", | ||
| "dataSource": "%%DATASOURCE%%", | ||
| "intervals": [ | ||
| "1000/3000" | ||
| ], | ||
| "aggregations": [ | ||
| { | ||
| "type": "longSum", | ||
| "name": "len", | ||
| "fieldName": "len" | ||
| }, | ||
| { | ||
| "type": "longSum", | ||
| "name": "max", | ||
| "fieldName": "max" | ||
| }, | ||
| { | ||
| "type": "longSum", | ||
| "name": "min", | ||
| "fieldName": "min" | ||
| }, | ||
| { | ||
| "type": "longSum", | ||
| "name": "sum", | ||
| "fieldName": "sum" | ||
| } | ||
| ], | ||
| "granularity": { | ||
| "type": "all" | ||
| } | ||
| }, | ||
| "expectedResults": [ | ||
| { | ||
| "timestamp": "2013-08-31T01:02:33.000Z", | ||
| "result": { | ||
| "sum": 10, | ||
| "min": 0, | ||
| "len": 5, | ||
| "max": 4 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
|
|
17 changes: 17 additions & 0 deletions
17
integration-tests-ex/cases/src/test/resources/multi-stage-query/batch-index/msq_inline.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| REPLACE INTO "%%DATASOURCE%%" OVERWRITE ALL | ||
| WITH "source" AS (SELECT * FROM TABLE( | ||
| EXTERN( | ||
| '{"type":"inline","data":"{\"timestamp\": \"2013-08-31T01:02:33Z\", \"values\": [0,1,2,3,4] }"}', | ||
| '{"type":"json","flattenSpec":{"useFieldDiscovery":true,"fields":[{"type":"path","name":"len","expr":"$.values.length()"},{"type":"path","name":"min","expr":"$.values.min()"},{"type":"path","name":"max","expr":"$.values.max()"},{"type":"path","name":"sum","expr":"$.values.sum()"}]}}', | ||
| '[{"name":"timestamp","type":"string"},{"name":"len","type":"long"},{"name":"min","type":"long"},{"name":"max","type":"long"},{"name":"sum","type":"long"}]' | ||
| ) | ||
| )) | ||
| SELECT | ||
| TIME_PARSE("timestamp") AS __time, | ||
| "len", | ||
| "min", | ||
| "max", | ||
| "sum" | ||
| FROM "source" | ||
| GROUP BY 1, 2, 3, 4, 5 | ||
| PARTITIONED BY HOUR |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to this PR? If not, then should this be raised as a separate PR?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docker containers created for the test fail with the following error, if this extension is not added -