-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-8982][Sort] Add Iceberg sink on flink 1.15 (#9035)
- Loading branch information
Showing
22 changed files
with
2,624 additions
and
17 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
66 changes: 66 additions & 0 deletions
66
...nectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/IcebergWritableMetadata.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,66 @@ | ||
/* | ||
* 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.inlong.sort.iceberg; | ||
|
||
import org.apache.inlong.sort.base.Constants; | ||
|
||
import org.apache.flink.table.api.DataTypes; | ||
import org.apache.flink.table.data.RowData; | ||
import org.apache.flink.table.types.DataType; | ||
|
||
import java.io.Serializable; | ||
|
||
public enum IcebergWritableMetadata { | ||
|
||
AUDIT_DATA_TIME( | ||
Constants.META_AUDIT_DATA_TIME, | ||
DataTypes.BIGINT().notNull(), | ||
(r, p) -> r.getLong(p)), | ||
|
||
NULL( | ||
"", | ||
DataTypes.NULL(), | ||
(r, p) -> null); | ||
|
||
private final String key; | ||
private final DataType dataType; | ||
private final MetadataConverter converter; | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public DataType getDataType() { | ||
return dataType; | ||
} | ||
|
||
public MetadataConverter getConverter() { | ||
return converter; | ||
} | ||
|
||
IcebergWritableMetadata(String key, DataType dataType, MetadataConverter converter) { | ||
this.key = key; | ||
this.dataType = dataType; | ||
this.converter = converter; | ||
} | ||
|
||
public interface MetadataConverter extends Serializable { | ||
|
||
Object read(RowData rowData, int pos); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...t-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/CommitSummary.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,96 @@ | ||
/* | ||
* 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.inlong.sort.iceberg.sink; | ||
|
||
import org.apache.iceberg.io.WriteResult; | ||
import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; | ||
|
||
import java.util.Arrays; | ||
import java.util.NavigableMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Copy from iceberg-flink:iceberg-flink-1.15:1.3.1 | ||
*/ | ||
class CommitSummary { | ||
|
||
private final AtomicLong dataFilesCount = new AtomicLong(); | ||
private final AtomicLong dataFilesRecordCount = new AtomicLong(); | ||
private final AtomicLong dataFilesByteCount = new AtomicLong(); | ||
private final AtomicLong deleteFilesCount = new AtomicLong(); | ||
private final AtomicLong deleteFilesRecordCount = new AtomicLong(); | ||
private final AtomicLong deleteFilesByteCount = new AtomicLong(); | ||
|
||
CommitSummary(NavigableMap<Long, WriteResult> pendingResults) { | ||
pendingResults | ||
.values() | ||
.forEach( | ||
writeResult -> { | ||
dataFilesCount.addAndGet(writeResult.dataFiles().length); | ||
Arrays.stream(writeResult.dataFiles()) | ||
.forEach( | ||
dataFile -> { | ||
dataFilesRecordCount.addAndGet(dataFile.recordCount()); | ||
dataFilesByteCount.addAndGet(dataFile.fileSizeInBytes()); | ||
}); | ||
deleteFilesCount.addAndGet(writeResult.deleteFiles().length); | ||
Arrays.stream(writeResult.deleteFiles()) | ||
.forEach( | ||
deleteFile -> { | ||
deleteFilesRecordCount.addAndGet(deleteFile.recordCount()); | ||
deleteFilesByteCount.addAndGet(deleteFile.fileSizeInBytes()); | ||
}); | ||
}); | ||
} | ||
|
||
long dataFilesCount() { | ||
return dataFilesCount.get(); | ||
} | ||
|
||
long dataFilesRecordCount() { | ||
return dataFilesRecordCount.get(); | ||
} | ||
|
||
long dataFilesByteCount() { | ||
return dataFilesByteCount.get(); | ||
} | ||
|
||
long deleteFilesCount() { | ||
return deleteFilesCount.get(); | ||
} | ||
|
||
long deleteFilesRecordCount() { | ||
return deleteFilesRecordCount.get(); | ||
} | ||
|
||
long deleteFilesByteCount() { | ||
return deleteFilesByteCount.get(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("dataFilesCount", dataFilesCount) | ||
.add("dataFilesRecordCount", dataFilesRecordCount) | ||
.add("dataFilesByteCount", dataFilesByteCount) | ||
.add("deleteFilesCount", deleteFilesCount) | ||
.add("deleteFilesRecordCount", deleteFilesRecordCount) | ||
.add("deleteFilesByteCount", deleteFilesByteCount) | ||
.toString(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/DeltaManifests.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,74 @@ | ||
/* | ||
* 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.inlong.sort.iceberg.sink; | ||
|
||
import org.apache.iceberg.ManifestFile; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Copy from iceberg-flink:iceberg-flink-1.15:1.3.1 | ||
*/ | ||
class DeltaManifests { | ||
|
||
private static final CharSequence[] EMPTY_REF_DATA_FILES = new CharSequence[0]; | ||
|
||
private final ManifestFile dataManifest; | ||
private final ManifestFile deleteManifest; | ||
private final CharSequence[] referencedDataFiles; | ||
|
||
DeltaManifests(ManifestFile dataManifest, ManifestFile deleteManifest) { | ||
this(dataManifest, deleteManifest, EMPTY_REF_DATA_FILES); | ||
} | ||
|
||
DeltaManifests( | ||
ManifestFile dataManifest, ManifestFile deleteManifest, CharSequence[] referencedDataFiles) { | ||
Preconditions.checkNotNull(referencedDataFiles, "Referenced data files shouldn't be null."); | ||
|
||
this.dataManifest = dataManifest; | ||
this.deleteManifest = deleteManifest; | ||
this.referencedDataFiles = referencedDataFiles; | ||
} | ||
|
||
ManifestFile dataManifest() { | ||
return dataManifest; | ||
} | ||
|
||
ManifestFile deleteManifest() { | ||
return deleteManifest; | ||
} | ||
|
||
CharSequence[] referencedDataFiles() { | ||
return referencedDataFiles; | ||
} | ||
|
||
List<ManifestFile> manifests() { | ||
List<ManifestFile> manifests = Lists.newArrayListWithCapacity(2); | ||
if (dataManifest != null) { | ||
manifests.add(dataManifest); | ||
} | ||
|
||
if (deleteManifest != null) { | ||
manifests.add(deleteManifest); | ||
} | ||
|
||
return manifests; | ||
} | ||
} |
Oops, something went wrong.