-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,032 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
api/src/main/java/org/apache/iceberg/util/DataFileSet.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,113 @@ | ||
/* | ||
* 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.util; | ||
|
||
import java.util.Objects; | ||
import org.apache.iceberg.DataFile; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Iterables; | ||
|
||
public class DataFileSet extends WrapperSet<DataFile> { | ||
private static final ThreadLocal<DataFileWrapper> WRAPPERS = | ||
ThreadLocal.withInitial(() -> DataFileWrapper.wrap(null)); | ||
|
||
private DataFileSet() { | ||
// needed for serialization/deserialization | ||
} | ||
|
||
private DataFileSet(Iterable<Wrapper<DataFile>> wrappers) { | ||
super(wrappers); | ||
} | ||
|
||
public static DataFileSet create() { | ||
return new DataFileSet(); | ||
} | ||
|
||
public static DataFileSet of(Iterable<? extends DataFile> iterable) { | ||
return new DataFileSet( | ||
Iterables.transform( | ||
iterable, | ||
obj -> { | ||
Preconditions.checkNotNull(obj, "Invalid object: null"); | ||
return DataFileWrapper.wrap(obj); | ||
})); | ||
} | ||
|
||
@Override | ||
protected Wrapper<DataFile> wrapper() { | ||
return WRAPPERS.get(); | ||
} | ||
|
||
@Override | ||
protected Wrapper<DataFile> wrap(DataFile dataFile) { | ||
return DataFileWrapper.wrap(dataFile); | ||
} | ||
|
||
@Override | ||
protected Class<DataFile> elementClass() { | ||
return DataFile.class; | ||
} | ||
|
||
private static class DataFileWrapper implements Wrapper<DataFile> { | ||
private DataFile file; | ||
|
||
private DataFileWrapper(DataFile file) { | ||
this.file = file; | ||
} | ||
|
||
private static DataFileWrapper wrap(DataFile dataFile) { | ||
return new DataFileWrapper(dataFile); | ||
} | ||
|
||
@Override | ||
public DataFile get() { | ||
return file; | ||
} | ||
|
||
@Override | ||
public Wrapper<DataFile> set(DataFile dataFile) { | ||
this.file = dataFile; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (!(o instanceof DataFileWrapper)) { | ||
return false; | ||
} | ||
|
||
DataFileWrapper that = (DataFileWrapper) o; | ||
return Objects.equals(file.location(), that.file.location()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(file.location()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return file.location(); | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
api/src/main/java/org/apache/iceberg/util/DeleteFileSet.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,114 @@ | ||
/* | ||
* 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.util; | ||
|
||
import java.util.Objects; | ||
import org.apache.iceberg.DeleteFile; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Iterables; | ||
|
||
public class DeleteFileSet extends WrapperSet<DeleteFile> { | ||
private static final ThreadLocal<DeleteFileWrapper> WRAPPERS = | ||
ThreadLocal.withInitial(() -> DeleteFileWrapper.wrap(null)); | ||
|
||
private DeleteFileSet() { | ||
// needed for serialization/deserialization | ||
} | ||
|
||
private DeleteFileSet(Iterable<Wrapper<DeleteFile>> wrappers) { | ||
super(wrappers); | ||
} | ||
|
||
public static DeleteFileSet create() { | ||
return new DeleteFileSet(); | ||
} | ||
|
||
public static DeleteFileSet of(Iterable<? extends DeleteFile> iterable) { | ||
return new DeleteFileSet( | ||
Iterables.transform( | ||
iterable, | ||
obj -> { | ||
Preconditions.checkNotNull(obj, "Invalid object: null"); | ||
return DeleteFileWrapper.wrap(obj); | ||
})); | ||
} | ||
|
||
@Override | ||
protected Wrapper<DeleteFile> wrapper() { | ||
return WRAPPERS.get(); | ||
} | ||
|
||
@Override | ||
protected Wrapper<DeleteFile> wrap(DeleteFile deleteFile) { | ||
return DeleteFileWrapper.wrap(deleteFile); | ||
} | ||
|
||
@Override | ||
protected Class<DeleteFile> elementClass() { | ||
return DeleteFile.class; | ||
} | ||
|
||
private static class DeleteFileWrapper implements Wrapper<DeleteFile> { | ||
private DeleteFile file; | ||
|
||
private DeleteFileWrapper(DeleteFile file) { | ||
this.file = file; | ||
} | ||
|
||
private static DeleteFileWrapper wrap(DeleteFile deleteFile) { | ||
return new DeleteFileWrapper(deleteFile); | ||
} | ||
|
||
@Override | ||
public DeleteFile get() { | ||
return file; | ||
} | ||
|
||
@Override | ||
public Wrapper<DeleteFile> set(DeleteFile deleteFile) { | ||
this.file = deleteFile; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (!(o instanceof DeleteFileWrapper)) { | ||
return false; | ||
} | ||
|
||
DeleteFileWrapper that = (DeleteFileWrapper) o; | ||
// this needs to be updated once deletion vector support is added | ||
return Objects.equals(file.location(), that.file.location()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(file.location()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return file.location(); | ||
} | ||
} | ||
} |
Oops, something went wrong.