-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Add data and delete writers in FileAppenderFactory. #1836
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
8 commits
Select commit
Hold shift + click to select a range
609049e
Core: Add data and delete writers in FileAppenderFactory.
openinx c1a1247
Minor fixes
openinx d6cebc6
Fix broken unit tests.
openinx 8006b63
Address comment
openinx b26898d
Minor changes
openinx 8e423fb
Align the exception messages
openinx 4b2b04b
Make the pathPosSchema to be private
openinx e6a8169
Address nit issues.
openinx 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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * 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.iceberg.io; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import org.apache.iceberg.DataFile; | ||
| import org.apache.iceberg.DataFiles; | ||
| import org.apache.iceberg.FileFormat; | ||
| import org.apache.iceberg.PartitionSpec; | ||
| import org.apache.iceberg.StructLike; | ||
| import org.apache.iceberg.encryption.EncryptionKeyMetadata; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
|
|
||
| public class DataWriter<T> implements Closeable { | ||
| private final FileAppender<T> appender; | ||
| private final FileFormat format; | ||
| private final String location; | ||
| private final PartitionSpec spec; | ||
| private final StructLike partition; | ||
| private final ByteBuffer keyMetadata; | ||
| private DataFile dataFile = null; | ||
|
|
||
| public DataWriter(FileAppender<T> appender, FileFormat format, String location, | ||
| PartitionSpec spec, StructLike partition, EncryptionKeyMetadata keyMetadata) { | ||
| this.appender = appender; | ||
| this.format = format; | ||
| this.location = location; | ||
| this.spec = spec; | ||
| this.partition = partition; | ||
| this.keyMetadata = keyMetadata != null ? keyMetadata.buffer() : null; | ||
| } | ||
|
|
||
| public void add(T row) { | ||
| appender.add(row); | ||
| } | ||
|
|
||
| public long length() { | ||
| return appender.length(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| if (dataFile == null) { | ||
| appender.close(); | ||
| this.dataFile = DataFiles.builder(spec) | ||
| .withFormat(format) | ||
| .withPath(location) | ||
| .withPartition(partition) | ||
| .withEncryptionKeyMetadata(keyMetadata) | ||
| .withFileSizeInBytes(appender.length()) | ||
| .withMetrics(appender.metrics()) | ||
| .withSplitOffsets(appender.splitOffsets()) | ||
| .build(); | ||
| } | ||
| } | ||
|
|
||
| public DataFile toDataFile() { | ||
| Preconditions.checkState(dataFile != null, "Cannot create data file from unclosed writer"); | ||
| return dataFile; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
core/src/main/java/org/apache/iceberg/io/DeleteSchemaUtil.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,48 @@ | ||
| /* | ||
| * 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.iceberg.io; | ||
|
|
||
| import org.apache.iceberg.MetadataColumns; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.types.Types; | ||
|
|
||
| public class DeleteSchemaUtil { | ||
| private DeleteSchemaUtil() { | ||
| } | ||
|
|
||
| private static Schema pathPosSchema(Schema rowSchema) { | ||
| return new Schema( | ||
| MetadataColumns.DELETE_FILE_PATH, | ||
| MetadataColumns.DELETE_FILE_POS, | ||
| Types.NestedField.required( | ||
| MetadataColumns.DELETE_FILE_ROW_FIELD_ID, "row", rowSchema.asStruct(), | ||
| MetadataColumns.DELETE_FILE_ROW_DOC)); | ||
| } | ||
|
|
||
| public static Schema pathPosSchema() { | ||
| return new Schema( | ||
| MetadataColumns.DELETE_FILE_PATH, | ||
| MetadataColumns.DELETE_FILE_POS); | ||
| } | ||
|
|
||
| public static Schema posDeleteSchema(Schema rowSchema) { | ||
| return rowSchema == null ? pathPosSchema() : pathPosSchema(rowSchema); | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.