-
Notifications
You must be signed in to change notification settings - Fork 3.8k
DruidInputSource can add new dimensions during re-ingestion #9590
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
15 commits
Select commit
Hold shift + click to select a range
6a4ee82
WIP integration tests
suneet-s 045584b
Add integration test for ingestion with transformSpec
suneet-s 46ae13b
WIP almost working tests
suneet-s 608e568
Add ignored tests
suneet-s 0f7dd96
checkstyle stuff
suneet-s f6f10aa
remove newPage from index task ingestion spec
suneet-s 013150d
more test cleanup
suneet-s db4dc28
still not quite working
suneet-s 8d2c471
Actually disable the tests
suneet-s 9da1c53
working tests
suneet-s 7afad45
fix codestyle
suneet-s 65216e3
dont use junit in integration tests
suneet-s fc8fedd
actually fix the bug
suneet-s 53433a2
fix checkstyle
suneet-s d5ee5ef
bring index tests closer to reindex tests
suneet-s 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,11 +22,13 @@ | |
| import com.google.common.collect.BiMap; | ||
| import com.google.common.collect.HashBiMap; | ||
| import com.google.common.collect.Lists; | ||
| import org.apache.druid.data.input.impl.DimensionsSpec; | ||
| import org.apache.druid.timeline.DataSegment; | ||
| import org.apache.druid.timeline.TimelineObjectHolder; | ||
| import org.apache.druid.timeline.partition.PartitionChunk; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import javax.validation.constraints.NotNull; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
@@ -101,4 +103,34 @@ public static List<String> getUniqueMetrics(List<TimelineObjectHolder<String, Da | |
| .mapToObj(orderedMetrics::get) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * Utility function to get dimensions that should be ingested. The preferred order is | ||
| * - Explicit dimensions if they are provided. | ||
| * - Custom dimensions are provided in the inputSpec. | ||
| * - Calculate dimensions from the timeline but exclude any dimension exclusions. | ||
| * | ||
| * @param explicitDimensions sent as part of the re-ingestion InputSource. | ||
| * @param dimensionsSpec from the provided ingestion spec. | ||
| * @param timeLineSegments for the datasource that is being read. | ||
| * @return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please add description for the return value or remove this. |
||
| */ | ||
| public static List<String> getDimensionsToReingest( | ||
| @Nullable List<String> explicitDimensions, | ||
| @NotNull DimensionsSpec dimensionsSpec, | ||
| @NotNull List<TimelineObjectHolder<String, DataSegment>> timeLineSegments) | ||
| { | ||
| final List<String> dims; | ||
| if (explicitDimensions != null) { | ||
| dims = explicitDimensions; | ||
| } else if (dimensionsSpec.hasCustomDimensions()) { | ||
| dims = dimensionsSpec.getDimensionNames(); | ||
| } else { | ||
| dims = ReingestionTimelineUtils.getUniqueDimensions( | ||
| timeLineSegments, | ||
| dimensionsSpec.getDimensionExclusions() | ||
| ); | ||
| } | ||
| return dims; | ||
| } | ||
| } | ||
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
115 changes: 115 additions & 0 deletions
115
integration-tests/src/test/java/org/apache/druid/tests/indexer/ITTransformTest.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,115 @@ | ||
| /* | ||
| * 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.tests.indexer; | ||
|
|
||
| import org.apache.druid.testing.guice.DruidTestModuleFactory; | ||
| import org.apache.druid.tests.TestNGGroup; | ||
| import org.testng.annotations.Guice; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
|
|
||
| @Test(groups = {TestNGGroup.BATCH_INDEX, TestNGGroup.QUICKSTART_COMPATIBLE}) | ||
| @Guice(moduleFactory = DruidTestModuleFactory.class) | ||
| public class ITTransformTest extends AbstractITBatchIndexTest | ||
| { | ||
| private static final String INDEX_TASK_WITH_FIREHOSE = "/indexer/wikipedia_index_task_with_transform.json"; | ||
| private static final String INDEX_TASK_WITH_INPUT_SOURCE = "/indexer/wikipedia_index_task_with_inputsource_transform.json"; | ||
| private static final String INDEX_QUERIES_RESOURCE = "/indexer/wikipedia_index_queries_with_transform.json"; | ||
| private static final String INDEX_DATASOURCE = "wikipedia_index_test"; | ||
|
|
||
| private static final String REINDEX_TASK = "/indexer/wikipedia_reindex_task_with_transforms.json"; | ||
| private static final String REINDEX_TASK_WITH_DRUID_INPUT_SOURCE = "/indexer/wikipedia_reindex_druid_input_source_task_with_transforms.json"; | ||
| private static final String REINDEX_QUERIES_RESOURCE = "/indexer/wikipedia_reindex_queries_with_transforms.json"; | ||
| private static final String REINDEX_DATASOURCE = "wikipedia_reindex_test"; | ||
|
|
||
| @Test | ||
| public void testIndexAndReIndexWithTransformSpec() throws IOException | ||
| { | ||
| final String reindexDatasourceWithDruidInputSource = REINDEX_DATASOURCE + "-druidInputSource"; | ||
|
|
||
| try ( | ||
| final Closeable ignored1 = unloader(INDEX_DATASOURCE + config.getExtraDatasourceNameSuffix()); | ||
| final Closeable ignored2 = unloader(reindexDatasourceWithDruidInputSource + config.getExtraDatasourceNameSuffix()) | ||
| ) { | ||
| doIndexTest( | ||
| INDEX_DATASOURCE, | ||
| INDEX_TASK_WITH_INPUT_SOURCE, | ||
| INDEX_QUERIES_RESOURCE, | ||
| false, | ||
| true, | ||
| true | ||
| ); | ||
| doReindexTest( | ||
| INDEX_DATASOURCE, | ||
| reindexDatasourceWithDruidInputSource, | ||
| REINDEX_TASK_WITH_DRUID_INPUT_SOURCE, | ||
| REINDEX_QUERIES_RESOURCE | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @Test(enabled = false) | ||
| public void testIndexAndReIndexUsingIngestSegmentWithTransforms() throws IOException | ||
| { | ||
| // TODO: re-instate this test when https://github.com/apache/druid/issues/9591 is fixed | ||
| // Move the re-index step into testIndexAndReIndexWithTransformSpec for faster tests! | ||
| final String reindexDatasource = REINDEX_DATASOURCE + "-testIndexData"; | ||
| try ( | ||
| final Closeable ignored1 = unloader(INDEX_DATASOURCE + config.getExtraDatasourceNameSuffix()); | ||
| final Closeable ignored2 = unloader(reindexDatasource + config.getExtraDatasourceNameSuffix()) | ||
| ) { | ||
| doIndexTest( | ||
| INDEX_DATASOURCE, | ||
| INDEX_TASK_WITH_INPUT_SOURCE, | ||
| INDEX_QUERIES_RESOURCE, | ||
| false, | ||
| true, | ||
| true | ||
| ); | ||
| doReindexTest( | ||
| INDEX_DATASOURCE, | ||
| reindexDatasource, | ||
| REINDEX_TASK, | ||
| REINDEX_QUERIES_RESOURCE | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @Test(enabled = false) | ||
| public void testIndexWithFirehoseAndTransforms() throws IOException | ||
| { | ||
| // TODO: re-instate this test when https://github.com/apache/druid/issues/9589 is fixed | ||
| final String indexDatasource = INDEX_DATASOURCE + "-firehose"; | ||
| try ( | ||
| final Closeable ignored1 = unloader(indexDatasource + config.getExtraDatasourceNameSuffix()); | ||
| ) { | ||
| doIndexTest( | ||
| indexDatasource, | ||
| INDEX_TASK_WITH_FIREHOSE, | ||
| INDEX_QUERIES_RESOURCE, | ||
| false, | ||
| true, | ||
| true | ||
| ); | ||
| } | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
integration-tests/src/test/resources/indexer/wikipedia_index_queries_with_transform.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,62 @@ | ||
| [ | ||
| { | ||
| "description":"having spec on post aggregation", | ||
| "query":{ | ||
| "queryType":"groupBy", | ||
| "dataSource":"%%DATASOURCE%%", | ||
| "granularity":"day", | ||
| "dimensions":[ | ||
| "page", | ||
| "city" | ||
| ], | ||
| "filter":{ | ||
| "type":"selector", | ||
| "dimension":"language", | ||
| "value":"language-zh" | ||
| }, | ||
| "aggregations":[ | ||
| { | ||
| "type":"count", | ||
| "name":"rows" | ||
| }, | ||
| { | ||
| "type":"longSum", | ||
| "fieldName":"triple-added", | ||
| "name":"added_count" | ||
| }, | ||
| { | ||
| "type":"longSum", | ||
| "fieldName":"delta", | ||
| "name":"delta_sum" | ||
| } | ||
| ], | ||
| "postAggregations": [ | ||
| { | ||
| "type":"arithmetic", | ||
| "name":"added_count_times_ten", | ||
| "fn":"*", | ||
| "fields":[ | ||
| {"type":"fieldAccess", "name":"added_count", "fieldName":"added_count"}, | ||
| {"type":"constant", "name":"const", "value":10} | ||
| ] | ||
| } | ||
| ], | ||
| "having":{"type":"greaterThan", "aggregation":"added_count_times_ten", "value":9000}, | ||
| "intervals":[ | ||
| "2013-08-31T00:00/2013-09-01T00:00" | ||
| ] | ||
| }, | ||
| "expectedResults":[ { | ||
| "version" : "v1", | ||
| "timestamp" : "2013-08-31T00:00:00.000Z", | ||
| "event" : { | ||
| "added_count_times_ten" : 27150.0, | ||
| "page" : "Crimson Typhoon", | ||
| "city" : "Taiyuan", | ||
| "added_count" : 2715, | ||
| "delta_sum" : 900, | ||
| "rows" : 1 | ||
| } | ||
| } ] | ||
| } | ||
| ] |
103 changes: 103 additions & 0 deletions
103
...ion-tests/src/test/resources/indexer/wikipedia_index_task_with_inputsource_transform.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,103 @@ | ||
| { | ||
| "type" : "index", | ||
| "spec" : { | ||
| "dataSchema" : { | ||
| "dataSource" : "%%DATASOURCE%%", | ||
| "timestampSpec": { | ||
| "column": "timestamp" | ||
| }, | ||
| "metricsSpec": [ | ||
| { | ||
| "type": "count", | ||
| "name": "count" | ||
| }, | ||
| { | ||
| "type": "doubleSum", | ||
| "name": "added", | ||
| "fieldName": "added" | ||
| }, | ||
| { | ||
| "type": "doubleSum", | ||
| "name": "triple-added", | ||
| "fieldName": "triple-added" | ||
| }, | ||
| { | ||
| "type": "doubleSum", | ||
| "name": "deleted", | ||
| "fieldName": "deleted" | ||
| }, | ||
| { | ||
| "type": "doubleSum", | ||
| "name": "delta", | ||
| "fieldName": "delta" | ||
| }, | ||
| { | ||
| "name": "thetaSketch", | ||
| "type": "thetaSketch", | ||
| "fieldName": "user" | ||
| }, | ||
| { | ||
| "name": "quantilesDoublesSketch", | ||
| "type": "quantilesDoublesSketch", | ||
| "fieldName": "delta" | ||
| }, | ||
| { | ||
| "name": "HLLSketchBuild", | ||
| "type": "HLLSketchBuild", | ||
| "fieldName": "user" | ||
| } | ||
| ], | ||
| "granularitySpec": { | ||
| "segmentGranularity": "DAY", | ||
| "queryGranularity": "second", | ||
| "intervals" : [ "2013-08-31/2013-09-02" ] | ||
| }, | ||
| "dimensionsSpec": { | ||
| "dimensions": [ | ||
| "page", | ||
| {"type": "string", "name": "language", "createBitmapIndex": false}, | ||
| "user", | ||
| "unpatrolled", | ||
| "robot", | ||
| "anonymous", | ||
| "namespace", | ||
| "continent", | ||
| "country", | ||
| "region", | ||
| "city" | ||
| ] | ||
| }, | ||
| "transformSpec": { | ||
| "transforms": [ | ||
| { | ||
| "type": "expression", | ||
| "name": "language", | ||
| "expression": "concat('language-', language)" | ||
| }, | ||
| { | ||
| "type": "expression", | ||
| "name": "triple-added", | ||
| "expression": "added * 3" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "ioConfig" : { | ||
| "type" : "index", | ||
| "inputSource" : { | ||
| "type" : "local", | ||
| "baseDir" : "/resources/data/batch_index", | ||
| "filter" : "wikipedia_index_data*" | ||
| }, | ||
| "inputFormat" : { | ||
| "type" : "json" | ||
| }, | ||
| "appendToExisting" : false | ||
| }, | ||
| "tuningConfig" : { | ||
| "type" : "index", | ||
| "maxRowsPerSegment" : 5000000, | ||
| "maxRowsInMemory" : 25000 | ||
| } | ||
| } | ||
| } |
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.
Good catch!