-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Integrate deletion vector to reader and writer (#2958)
- Loading branch information
Showing
33 changed files
with
937 additions
and
171 deletions.
There are no files selected for viewing
This file contains 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 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
56 changes: 56 additions & 0 deletions
56
paimon-common/src/main/java/org/apache/paimon/lookup/LookupStrategy.java
This file contains 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,56 @@ | ||
/* | ||
* 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.paimon.lookup; | ||
|
||
/** Strategy for lookup. */ | ||
public enum LookupStrategy { | ||
NO_LOOKUP(false, false), | ||
|
||
CHANGELOG_ONLY(true, false), | ||
|
||
DELETION_VECTOR_ONLY(false, true), | ||
|
||
CHANGELOG_AND_DELETION_VECTOR(true, true); | ||
|
||
public final boolean needLookup; | ||
|
||
public final boolean produceChangelog; | ||
|
||
public final boolean deletionVector; | ||
|
||
LookupStrategy(boolean produceChangelog, boolean deletionVector) { | ||
this.produceChangelog = produceChangelog; | ||
this.deletionVector = deletionVector; | ||
this.needLookup = produceChangelog || deletionVector; | ||
} | ||
|
||
public static LookupStrategy from(boolean produceChangelog, boolean deletionVector) { | ||
for (LookupStrategy strategy : values()) { | ||
if (strategy.produceChangelog == produceChangelog | ||
&& strategy.deletionVector == deletionVector) { | ||
return strategy; | ||
} | ||
} | ||
throw new IllegalArgumentException( | ||
"Invalid combination of produceChangelog : " | ||
+ produceChangelog | ||
+ " and deletionVector : " | ||
+ deletionVector); | ||
} | ||
} |
This file contains 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
65 changes: 65 additions & 0 deletions
65
paimon-core/src/main/java/org/apache/paimon/deletionvectors/ApplyDeletionVectorReader.java
This file contains 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,65 @@ | ||
/* | ||
* 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.paimon.deletionvectors; | ||
|
||
import org.apache.paimon.reader.RecordReader; | ||
import org.apache.paimon.reader.RecordWithPositionIterator; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.apache.paimon.utils.Preconditions.checkArgument; | ||
|
||
/** A {@link RecordReader} which apply {@link DeletionVector} to filter record. */ | ||
public class ApplyDeletionVectorReader<T> implements RecordReader<T> { | ||
|
||
private final RecordReader<T> reader; | ||
|
||
private final DeletionVector deletionVector; | ||
|
||
public ApplyDeletionVectorReader(RecordReader<T> reader, DeletionVector deletionVector) { | ||
this.reader = reader; | ||
this.deletionVector = deletionVector; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public RecordIterator<T> readBatch() throws IOException { | ||
RecordIterator<T> batch = reader.readBatch(); | ||
|
||
if (batch == null) { | ||
return null; | ||
} | ||
|
||
checkArgument( | ||
batch instanceof RecordWithPositionIterator, | ||
"There is a bug, RecordIterator in ApplyDeletionVectorReader must be RecordWithPositionIterator"); | ||
|
||
RecordWithPositionIterator<T> batchWithPosition = (RecordWithPositionIterator<T>) batch; | ||
|
||
return batchWithPosition.filter( | ||
a -> !deletionVector.isDeleted(batchWithPosition.returnedPosition())); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
reader.close(); | ||
} | ||
} |
This file contains 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 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 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.