-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add embedded test for object-storage-encoding format for nested field #18818
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
+169
−8
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
868cf2f
nested-it
cecemei 3ee90cc
Merge branch 'master' into nested-it
cecemei fc63ca0
checkstyle
cecemei f2eb056
license
cecemei 4d1d6e8
fix-test
cecemei 299766b
emitter-config
cecemei 1deaef6
setup
cecemei fb1de07
Merge branch 'master' into nested-it
cecemei e79b5c7
prefix
cecemei 4c20bde
small-update
cecemei 2eceaa9
Update embedded-tests/src/test/java/org/apache/druid/testing/embedded…
cecemei 2aca113
datasourceWithDefaultFormat
cecemei 09bdf30
prefix
cecemei 170d354
Update embedded-tests/src/test/java/org/apache/druid/testing/embedded…
cecemei 1eaace7
style
cecemei 0786920
sql
cecemei 285204c
nested
cecemei 11b1f5b
client-sql
cecemei 1d44512
format
cecemei 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
139 changes: 139 additions & 0 deletions
139
...tests/src/test/java/org/apache/druid/testing/embedded/indexing/NestedDataFormatsTest.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,139 @@ | ||
| /* | ||
| * 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.embedded.indexing; | ||
|
|
||
| import org.apache.druid.indexing.common.task.TaskBuilder; | ||
| import org.apache.druid.java.util.common.StringUtils; | ||
| import org.apache.druid.segment.IndexSpec; | ||
| import org.apache.druid.segment.nested.NestedCommonFormatColumnFormatSpec; | ||
| import org.apache.druid.segment.nested.ObjectStorageEncoding; | ||
| import org.apache.druid.testing.embedded.EmbeddedBroker; | ||
| import org.apache.druid.testing.embedded.EmbeddedClusterApis; | ||
| import org.apache.druid.testing.embedded.EmbeddedCoordinator; | ||
| import org.apache.druid.testing.embedded.EmbeddedDruidCluster; | ||
| import org.apache.druid.testing.embedded.EmbeddedHistorical; | ||
| import org.apache.druid.testing.embedded.EmbeddedIndexer; | ||
| import org.apache.druid.testing.embedded.EmbeddedOverlord; | ||
| import org.apache.druid.testing.embedded.EmbeddedRouter; | ||
| import org.apache.druid.testing.embedded.junit5.EmbeddedClusterTestBase; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Embedded tests for nested data, ingested in different {@link NestedCommonFormatColumnFormatSpec}. | ||
| */ | ||
| public class NestedDataFormatsTest extends EmbeddedClusterTestBase | ||
| { | ||
| private final EmbeddedBroker broker = new EmbeddedBroker(); | ||
| private final EmbeddedOverlord overlord = new EmbeddedOverlord(); | ||
| private final EmbeddedCoordinator coordinator = new EmbeddedCoordinator(); | ||
|
|
||
| private final String datasourceWithDefaultFormat = EmbeddedClusterApis.createTestDatasourceName(); | ||
|
|
||
| @Override | ||
| protected EmbeddedDruidCluster createCluster() | ||
| { | ||
| return EmbeddedDruidCluster.withEmbeddedDerbyAndZookeeper() | ||
| .useLatchableEmitter() | ||
| .useDefaultTimeoutForLatchableEmitter(120) | ||
| .addServer(overlord) | ||
| .addServer(coordinator) | ||
| .addServer(new EmbeddedIndexer()) | ||
| .addServer(new EmbeddedHistorical()) | ||
| .addServer(broker) | ||
| .addServer(new EmbeddedRouter()); | ||
| } | ||
|
|
||
| @BeforeAll | ||
| protected void ingestWithDefaultFormat() | ||
| { | ||
| final TaskBuilder.IndexParallel indexTask = | ||
| TaskBuilder.ofTypeIndexParallel() | ||
| .dataSource(datasourceWithDefaultFormat) | ||
| .timestampColumn("timestamp") | ||
| .jsonInputFormat() | ||
| .inputSource(Resources.HttpData.kttmNested1Day()) | ||
| .schemaDiscovery(); | ||
|
|
||
| final String taskId = EmbeddedClusterApis.newTaskId(datasourceWithDefaultFormat); | ||
| cluster.callApi().runTask(indexTask.withId(taskId), overlord); | ||
| cluster.callApi().waitForAllSegmentsToBeAvailable(datasourceWithDefaultFormat, coordinator, broker); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_objectStorageEncoding() | ||
| { | ||
| // Ingest kttm data with skipping smile raw json format, comparing diff with defaultFormat | ||
| NestedCommonFormatColumnFormatSpec spec = | ||
| NestedCommonFormatColumnFormatSpec.builder().setObjectStorageEncoding(ObjectStorageEncoding.NONE).build(); | ||
| final TaskBuilder.IndexParallel indexTask = | ||
| TaskBuilder.ofTypeIndexParallel() | ||
| .dataSource(dataSource) | ||
| .timestampColumn("timestamp") | ||
| .jsonInputFormat() | ||
| .inputSource(Resources.HttpData.kttmNested1Day()) | ||
| .schemaDiscovery() | ||
| .tuningConfig(t -> t.withIndexSpec(IndexSpec.builder().withAutoColumnFormatSpec(spec).build())); | ||
| final String taskId = EmbeddedClusterApis.newTaskId(dataSource); | ||
| cluster.callApi().runTask(indexTask.withId(taskId), overlord); | ||
| cluster.callApi().waitForAllSegmentsToBeAvailable(dataSource, coordinator, broker); | ||
|
|
||
| // Test ingesting with skipping raw json smile format works, same row count, with ~20% storage saving | ||
| final String metadataSql = "select sum(num_rows), sum(size) from sys.segments where datasource = '%s'"; | ||
| final String defaultFormatResult = cluster.runSql(metadataSql, datasourceWithDefaultFormat); | ||
| final String noneObjectStorageFormatResult = cluster.runSql(metadataSql, dataSource); | ||
| Assertions.assertEquals(StringUtils.format("%d,%d", 465_346, 53_000_804), defaultFormatResult); | ||
| Assertions.assertEquals(StringUtils.format("%d,%d", 465_346, 41_938_750), noneObjectStorageFormatResult); | ||
|
|
||
| // Test querying on a nested field works | ||
| final String groupByQuery = | ||
| """ | ||
| select json_value(event, '$.type') as event_type, count(*) as total from %s | ||
| group by 1 order by 2 desc, 1 asc limit 10 | ||
| """; | ||
| final String queryResultDefaultFormat = cluster.runSql(groupByQuery, datasourceWithDefaultFormat); | ||
| final String queryResultNoneObjectStorage = cluster.runSql(groupByQuery, dataSource); | ||
| Assertions.assertEquals(queryResultDefaultFormat, queryResultNoneObjectStorage); | ||
|
|
||
| // Test reconstruct json column works, the ordering of the fields has changed, but all values are perserved. | ||
| final String scanQuery = | ||
| """ | ||
| select event, to_json_string(agent) as agent from %s | ||
| where json_value(event, '$.type') = 'PercentClear' and json_value(agent, '$.os') = 'Android' | ||
| order by __time asc limit 1 | ||
| """; | ||
| final String scanQueryResultDefaultFormat = cluster.runSql(scanQuery, datasourceWithDefaultFormat); | ||
| final String scanQueryResultNoneObjectStorage = cluster.runSql(scanQuery, dataSource); | ||
| // CHECKSTYLE: text blocks not supported in current Checkstyle version | ||
| Assertions.assertEquals( | ||
| """ | ||
| "{""type"":""PercentClear"",""percentage"":85}","{""type"":""Mobile Browser"",""category"":""Smartphone"",""browser"":""Chrome Mobile"",""browser_version"":""50.0.2661.89"",""os"":""Android"",""platform"":""Android""}" | ||
| """.trim(), | ||
| scanQueryResultDefaultFormat | ||
| ); | ||
| Assertions.assertEquals( | ||
| """ | ||
| "{""percentage"":85,""type"":""PercentClear""}","{""browser"":""Chrome Mobile"",""browser_version"":""50.0.2661.89"",""category"":""Smartphone"",""os"":""Android"",""platform"":""Android"",""type"":""Mobile Browser""}" | ||
| """.trim(), | ||
| scanQueryResultNoneObjectStorage | ||
| ); | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ | |
| </scm> | ||
|
|
||
| <properties> | ||
| <java.version>11</java.version> | ||
| <java.version>17</java.version> | ||
| <maven.compiler.release>${java.version}</maven.compiler.release> | ||
| <project.build.resourceEncoding>UTF-8</project.build.resourceEncoding> | ||
| <aether.version>0.9.0.M2</aether.version> | ||
|
|
@@ -1572,7 +1572,7 @@ | |
| <consoleOutput>true</consoleOutput> | ||
| <failsOnError>true</failsOnError> | ||
| <excludes> | ||
| *com/fasterxml/jackson/databind/* | ||
| *com/fasterxml/jackson/databind/*,**/NestedDataFormatsTest.java | ||
|
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. Why is the new test excluded from checkstyle?
Contributor
Author
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. parsing error |
||
| </excludes> | ||
| </configuration> | ||
| <dependencies> | ||
|
|
||
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
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.
Let's consider updating the checkstyle version in that case.
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.
only later version of checkstyle support the """ style (java 15+), and had to exclude this file since the error thrown was parsing error. in the later version of checkstyle a bunch of other things failed as well, so prefer to make checkstyle a separate pr besides this one.
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.
Okay, thanks for the details.
I think you can also use
// CHECKSTYLE.OFFto turn off checkstyle without having to exclude the entire file in pom. e.g. seeStringUtilsclass.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.
it still complains about error, i think parsing was before style check
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.
I see, thanks for checking. Let's just exclude it in the pom until we upgrade the checkstyle version in the follow up PR.