-
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.
[compact] Support compact unaware bucket for combine_mode (#2858)
- Loading branch information
1 parent
3a64148
commit 29d13fd
Showing
29 changed files
with
1,781 additions
and
409 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
62 changes: 62 additions & 0 deletions
62
paimon-core/src/main/java/org/apache/paimon/append/MultiTableAppendOnlyCompactionTask.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,62 @@ | ||
/* | ||
* 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.append; | ||
|
||
import org.apache.paimon.catalog.Identifier; | ||
import org.apache.paimon.data.BinaryRow; | ||
import org.apache.paimon.io.DataFileMeta; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** Compaction task for multi table . */ | ||
public class MultiTableAppendOnlyCompactionTask extends AppendOnlyCompactionTask { | ||
|
||
private final Identifier tableIdentifier; | ||
|
||
public MultiTableAppendOnlyCompactionTask( | ||
BinaryRow partition, List<DataFileMeta> files, Identifier identifier) { | ||
super(partition, files); | ||
this.tableIdentifier = identifier; | ||
} | ||
|
||
public Identifier tableIdentifier() { | ||
return tableIdentifier; | ||
} | ||
|
||
public int hashCode() { | ||
return Objects.hash(partition(), compactBefore(), compactAfter(), tableIdentifier); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
MultiTableAppendOnlyCompactionTask that = (MultiTableAppendOnlyCompactionTask) o; | ||
return Objects.equals(partition(), that.partition()) | ||
&& Objects.equals(compactBefore(), that.compactBefore()) | ||
&& Objects.equals(compactAfter(), that.compactAfter()) | ||
&& Objects.equals(tableIdentifier, that.tableIdentifier); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
paimon-core/src/main/java/org/apache/paimon/io/IdentifierSerializer.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,47 @@ | ||
/* | ||
* 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.io; | ||
|
||
import org.apache.paimon.catalog.Identifier; | ||
import org.apache.paimon.data.BinaryString; | ||
import org.apache.paimon.data.GenericRow; | ||
import org.apache.paimon.data.InternalRow; | ||
import org.apache.paimon.utils.ObjectSerializer; | ||
|
||
/** Serializer for {@link Identifier}. */ | ||
public class IdentifierSerializer extends ObjectSerializer<Identifier> { | ||
|
||
public IdentifierSerializer() { | ||
super(Identifier.schema()); | ||
} | ||
|
||
@Override | ||
public InternalRow toRow(Identifier record) { | ||
return GenericRow.of( | ||
BinaryString.fromString(record.getDatabaseName()), | ||
BinaryString.fromString(record.getObjectName())); | ||
} | ||
|
||
@Override | ||
public Identifier fromRow(InternalRow rowData) { | ||
String databaseName = rowData.isNullAt(0) ? null : rowData.getString(0).toString(); | ||
String tableName = rowData.isNullAt(1) ? null : rowData.getString(1).toString(); | ||
return Identifier.create(databaseName, tableName); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
...n-core/src/main/java/org/apache/paimon/table/sink/MultiTableCompactionTaskSerializer.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,118 @@ | ||
/* | ||
* 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.table.sink; | ||
|
||
import org.apache.paimon.append.MultiTableAppendOnlyCompactionTask; | ||
import org.apache.paimon.data.serializer.VersionedSerializer; | ||
import org.apache.paimon.io.DataFileMetaSerializer; | ||
import org.apache.paimon.io.DataInputDeserializer; | ||
import org.apache.paimon.io.DataInputView; | ||
import org.apache.paimon.io.DataOutputView; | ||
import org.apache.paimon.io.DataOutputViewStreamWrapper; | ||
import org.apache.paimon.io.IdentifierSerializer; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.apache.paimon.utils.SerializationUtils.deserializeBinaryRow; | ||
import static org.apache.paimon.utils.SerializationUtils.serializeBinaryRow; | ||
|
||
/** Serializer for {@link MultiTableAppendOnlyCompactionTask}. */ | ||
public class MultiTableCompactionTaskSerializer | ||
implements VersionedSerializer<MultiTableAppendOnlyCompactionTask> { | ||
|
||
private static final int CURRENT_VERSION = 1; | ||
|
||
private final DataFileMetaSerializer dataFileSerializer; | ||
|
||
private final IdentifierSerializer identifierSerializer; | ||
|
||
public MultiTableCompactionTaskSerializer() { | ||
this.dataFileSerializer = new DataFileMetaSerializer(); | ||
this.identifierSerializer = new IdentifierSerializer(); | ||
} | ||
|
||
@Override | ||
public int getVersion() { | ||
return CURRENT_VERSION; | ||
} | ||
|
||
@Override | ||
public byte[] serialize(MultiTableAppendOnlyCompactionTask task) throws IOException { | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
DataOutputViewStreamWrapper view = new DataOutputViewStreamWrapper(out); | ||
serialize(task, view); | ||
return out.toByteArray(); | ||
} | ||
|
||
private void serialize(MultiTableAppendOnlyCompactionTask task, DataOutputView view) | ||
throws IOException { | ||
serializeBinaryRow(task.partition(), view); | ||
dataFileSerializer.serializeList(task.compactBefore(), view); | ||
identifierSerializer.serialize(task.tableIdentifier(), view); | ||
} | ||
|
||
@Override | ||
public MultiTableAppendOnlyCompactionTask deserialize(int version, byte[] serialized) | ||
throws IOException { | ||
checkVersion(version); | ||
DataInputDeserializer view = new DataInputDeserializer(serialized); | ||
return deserialize(view); | ||
} | ||
|
||
private MultiTableAppendOnlyCompactionTask deserialize(DataInputView view) throws IOException { | ||
return new MultiTableAppendOnlyCompactionTask( | ||
deserializeBinaryRow(view), | ||
dataFileSerializer.deserializeList(view), | ||
identifierSerializer.deserialize(view)); | ||
} | ||
|
||
public List<MultiTableAppendOnlyCompactionTask> deserializeList(int version, DataInputView view) | ||
throws IOException { | ||
checkVersion(version); | ||
int length = view.readInt(); | ||
List<MultiTableAppendOnlyCompactionTask> list = new ArrayList<>(length); | ||
for (int i = 0; i < length; i++) { | ||
list.add(deserialize(view)); | ||
} | ||
return list; | ||
} | ||
|
||
public void serializeList(List<MultiTableAppendOnlyCompactionTask> list, DataOutputView view) | ||
throws IOException { | ||
view.writeInt(list.size()); | ||
for (MultiTableAppendOnlyCompactionTask commitMessage : list) { | ||
serialize(commitMessage, view); | ||
} | ||
} | ||
|
||
private void checkVersion(int version) { | ||
if (version != CURRENT_VERSION) { | ||
throw new UnsupportedOperationException( | ||
"Expecting MultiTableCompactionTaskSerializer version to be " | ||
+ CURRENT_VERSION | ||
+ ", but found " | ||
+ version | ||
+ ".\nCompactionTask is not a compatible data structure. " | ||
+ "Please restart the job afresh (do not recover from savepoint)."); | ||
} | ||
} | ||
} |
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.