-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GOBBLIN-1667] Create new predicate - ExistingPartitionSkipPredicate
Currently the hive.dataset.existing.entity.policy.ABORT will not abort if there is an existing partition. One option to resolve this is to support the ABORT configuration but that might be backwards incompatible, so introducing a new skip predicate called ExistingPartitionSkipPredicate that will skip any partition that already exists in the target table
- Loading branch information
1 parent
7aad1f9
commit 44d389c
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...va/org/apache/gobblin/data/management/copy/predicates/ExistingPartitionSkipPredicate.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,21 @@ | ||
package org.apache.gobblin.data.management.copy.predicates; | ||
|
||
import com.google.common.base.Predicate; | ||
import javax.annotation.Nullable; | ||
import org.apache.gobblin.data.management.copy.hive.HivePartitionFileSet; | ||
|
||
|
||
/** | ||
* This skip predicate will skip any partition that's already registered in the destination | ||
* hive table. | ||
*/ | ||
public class ExistingPartitionSkipPredicate implements Predicate<HivePartitionFileSet> { | ||
@Override | ||
public boolean apply(@Nullable HivePartitionFileSet input) { | ||
if (input == null) { | ||
return true; | ||
} | ||
|
||
return input.getExistingTargetPartition().isPresent(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...rg/apache/gobblin/data/management/copy/predicates/ExistingPartitionSkipPredicateTest.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,25 @@ | ||
package org.apache.gobblin.data.management.copy.predicates; | ||
|
||
import com.google.common.base.Optional; | ||
import org.apache.gobblin.data.management.copy.hive.HivePartitionFileSet; | ||
import org.apache.hadoop.hive.ql.metadata.Partition; | ||
import org.junit.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
|
||
public class ExistingPartitionSkipPredicateTest { | ||
ExistingPartitionSkipPredicate predicate = new ExistingPartitionSkipPredicate(); | ||
|
||
@Test | ||
public void shouldSkipHiveDatasetWithExistingPartition() { | ||
HivePartitionFileSet fileSetWithExistingPartition = mock(HivePartitionFileSet.class); | ||
HivePartitionFileSet fileSetWithoutExistingPartition = mock(HivePartitionFileSet.class); | ||
Partition partition = mock(Partition.class); | ||
when(fileSetWithExistingPartition.getExistingTargetPartition()).thenReturn(Optional.of(partition)); | ||
when(fileSetWithoutExistingPartition.getExistingTargetPartition()).thenReturn(Optional.absent()); | ||
Assert.assertTrue(predicate.apply(fileSetWithExistingPartition)); | ||
Assert.assertFalse(predicate.apply(fileSetWithoutExistingPartition)); | ||
} | ||
} |
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