-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Keeps nullness attributes of merged in comparison column values #10704
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
Jackie-Jiang
merged 8 commits into
apache:master
from
egalpin:egalpin/multi-comp-col-null-handling
Jun 1, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
63c7831
Keeps nullness attributes of merged in comparison column values
egalpin 0abb88e
Introduces special handling for reading sealed segments with multiple…
egalpin 0ff3e6b
Adds explicit null handling
egalpin 56e07b6
Updates comment for clarity
egalpin 634b4cb
Adds back use of explicit null values in ComparisonColumns values
egalpin 0c97020
Adds ComparisonColumnsTest.java
egalpin 72fd3cf
Adds missing license to test file
egalpin 284ae68
Adds asserts for merge of comparison column values upon persisting
egalpin 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
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
171 changes: 171 additions & 0 deletions
171
...ment-local/src/test/java/org/apache/pinot/segment/local/upsert/ComparisonColumnsTest.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,171 @@ | ||
| /** | ||
| * 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.segment.local.upsert; | ||
|
|
||
| import java.util.Arrays; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
|
|
||
| public class ComparisonColumnsTest { | ||
| private void nullFill(Comparable[]... comparables) { | ||
| for (Comparable[] comps : comparables) { | ||
| Arrays.fill(comps, null); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testRealtimeComparison() { | ||
| Comparable[] newComparables = new Comparable[3]; | ||
| Comparable[] persistedComparables = new Comparable[3]; | ||
| ComparisonColumns alreadyPersisted = new ComparisonColumns(persistedComparables, 0); | ||
| ComparisonColumns toBeIngested = new ComparisonColumns(newComparables, 0); | ||
|
|
||
| // reject same col with smaller value | ||
| newComparables[0] = 1; | ||
| persistedComparables[0] = 2; | ||
| int comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, -1); | ||
|
|
||
| // persist same col with equal value | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[0] = 2; | ||
| persistedComparables[0] = 2; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 0); | ||
|
|
||
| // persist same col with larger value | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[0] = 2; | ||
| persistedComparables[0] = 1; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 1); | ||
| Assert.assertEquals(toBeIngested.getValues(), new Comparable[]{2, null, null}); | ||
|
|
||
| // persist doc with col which was previously null, even though its value is smaller than the previous non-null col | ||
| nullFill(newComparables, persistedComparables); | ||
| toBeIngested = new ComparisonColumns(newComparables, newComparables.length - 1); | ||
| newComparables[newComparables.length - 1] = 1; | ||
| persistedComparables[0] = 2; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 1); | ||
| Assert.assertEquals(toBeIngested.getValues(), new Comparable[]{2, null, 1}); | ||
|
|
||
| // persist new doc where existing doc has multiple non-null comparison values | ||
| nullFill(newComparables, persistedComparables); | ||
| toBeIngested = new ComparisonColumns(newComparables, 1); | ||
| newComparables[1] = 2; | ||
| Arrays.fill(persistedComparables, 1); | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 1); | ||
| Assert.assertEquals(toBeIngested.getValues(), new Comparable[]{1, 2, 1}); | ||
|
|
||
| // reject new doc where existing doc has multiple non-null comparison values | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[1] = 0; | ||
| Arrays.fill(persistedComparables, 1); | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, -1); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSealedComparison() { | ||
| // Remember to be cognizant of which scenarios are _actually_ possible in a sealed segment. The way in which docs | ||
| // are compared during realtime ingestion dictates the possible scenarios of persisted rows. Ex. it is not | ||
| // possible for 2 docs with the same primary key to have a mutually exclusive set of non-null values; if such a | ||
| // scenario arose during realtime ingestion, the values would be merged such that the newly persisted doc would | ||
| // have all non-null comparison values. We should avoid making tests pass for scenarios that are not intended to | ||
| // be supported. | ||
| Comparable[] newComparables = new Comparable[3]; | ||
| Comparable[] persistedComparables = new Comparable[3]; | ||
| ComparisonColumns alreadyPersisted = | ||
| new ComparisonColumns(persistedComparables, ComparisonColumns.SEALED_SEGMENT_COMPARISON_INDEX); | ||
| ComparisonColumns toBeIngested = | ||
| new ComparisonColumns(newComparables, ComparisonColumns.SEALED_SEGMENT_COMPARISON_INDEX); | ||
|
|
||
| // reject same col with smaller value | ||
| newComparables[0] = 1; | ||
| persistedComparables[0] = 2; | ||
| int comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, -1); | ||
|
|
||
| // persist same col with equal value | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[0] = 2; | ||
| persistedComparables[0] = 2; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 0); | ||
| // Verify unchanged comparables in the case of SEALED comparison | ||
| Assert.assertEquals(toBeIngested.getValues(), newComparables); | ||
|
|
||
| // persist same col with larger value | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[0] = 2; | ||
| persistedComparables[0] = 1; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 1); | ||
|
|
||
| // reject doc where existing doc has more than one, but not all, non-null comparison values, but _this_ doc has 2 | ||
| // null columns. The presence of null columns in one of the docs implies that it must have come before the doc | ||
| // with non-null columns. | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[1] = 1; | ||
| persistedComparables[0] = 1; | ||
| persistedComparables[2] = 1; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, -1); | ||
|
|
||
| // persist doc where existing doc has more than one, but not all, non-null comparison values, but _this_ doc has | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[0] = 1; | ||
| newComparables[2] = 2; | ||
| persistedComparables[0] = 1; | ||
| persistedComparables[2] = 1; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 1); | ||
|
|
||
| // persist doc with non-null value where existing doc had null value in same column previously (but multiple | ||
| // non-null in other columns) | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[0] = 1; | ||
| newComparables[1] = 1; | ||
| newComparables[2] = 1; | ||
| persistedComparables[0] = 1; | ||
| persistedComparables[2] = 1; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 1); | ||
|
|
||
| // reject doc where existing doc has all non-null comparison values, but _this_ doc has 2 null values. | ||
| // The presence of null columns in one of the docs implies that it must have come before the doc with non-null | ||
| // columns. | ||
| nullFill(newComparables, persistedComparables); | ||
| newComparables[1] = 1; | ||
| Arrays.fill(persistedComparables, 1); | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, -1); | ||
|
|
||
| // Persist doc where existing doc has all non-null comparison values, but _this_ doc has a larger value. | ||
| nullFill(newComparables, persistedComparables); | ||
| Arrays.fill(newComparables, 1); | ||
| Arrays.fill(persistedComparables, 1); | ||
| newComparables[1] = 2; | ||
| comparisonResult = toBeIngested.compareTo(alreadyPersisted); | ||
| Assert.assertEquals(comparisonResult, 1); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.