-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Destination S3V2: Guard against name conflicts (#50407)
- Loading branch information
1 parent
671d4de
commit e4e4636
Showing
15 changed files
with
212 additions
and
29 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
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
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
51 changes: 51 additions & 0 deletions
51
.../src/test/kotlin/io/airbyte/cdk/load/file/object_storage/ObjectStoragePathFactoryUTest.kt
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,51 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.file.object_storage | ||
|
||
import io.airbyte.cdk.load.command.DestinationStream | ||
import io.airbyte.cdk.load.command.object_storage.ObjectStoragePathConfiguration | ||
import io.airbyte.cdk.load.command.object_storage.ObjectStoragePathConfigurationProvider | ||
import io.airbyte.cdk.load.file.TimeProvider | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
import org.junit.jupiter.api.Assertions.assertNull | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class ObjectStoragePathFactoryUTest { | ||
@MockK lateinit var stream: DestinationStream | ||
@MockK lateinit var pathConfigProvider: ObjectStoragePathConfigurationProvider | ||
@MockK lateinit var timeProvider: TimeProvider | ||
|
||
@BeforeEach | ||
fun setup() { | ||
every { stream.descriptor } returns DestinationStream.Descriptor("test", "stream") | ||
every { timeProvider.syncTimeMillis() } returns 0 | ||
every { timeProvider.currentTimeMillis() } returns 1 | ||
} | ||
|
||
@Test | ||
fun `test matcher with suffix`() { | ||
every { pathConfigProvider.objectStoragePathConfiguration } returns | ||
ObjectStoragePathConfiguration( | ||
"prefix", | ||
null, | ||
"path/", | ||
"ambiguous_filename", | ||
false, | ||
) | ||
val factory = ObjectStoragePathFactory(pathConfigProvider, null, null, timeProvider) | ||
|
||
val matcher = factory.getPathMatcher(stream, "(-\\d+)?") | ||
val match1 = matcher.match("prefix/path/ambiguous_filename") | ||
assertNotNull(match1) | ||
assertNull(match1?.customSuffix) | ||
val match2 = matcher.match("prefix/path/ambiguous_filename-1") | ||
assertNotNull(match2) | ||
assertEquals(match2?.customSuffix, "-1") | ||
} | ||
} |
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
...est/kotlin/io/airbyte/cdk/load/state/object_storage/ObjectStorageDestinationStateUTest.kt
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 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.state.object_storage | ||
|
||
import io.airbyte.cdk.load.command.DestinationStream | ||
import io.airbyte.cdk.load.file.object_storage.ObjectStorageClient | ||
import io.airbyte.cdk.load.file.object_storage.ObjectStoragePathFactory | ||
import io.airbyte.cdk.load.file.object_storage.PathMatcher | ||
import io.airbyte.cdk.load.file.object_storage.RemoteObject | ||
import io.mockk.coEvery | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class ObjectStorageDestinationStateUTest { | ||
data class MockObj(override val key: String, override val storageConfig: Unit = Unit) : | ||
RemoteObject<Unit> | ||
|
||
@MockK lateinit var stream: DestinationStream | ||
@MockK lateinit var client: ObjectStorageClient<*> | ||
@MockK lateinit var pathFactory: ObjectStoragePathFactory | ||
|
||
@BeforeEach | ||
fun setup() { | ||
every { stream.descriptor } returns DestinationStream.Descriptor("test", "stream") | ||
every { pathFactory.getPathMatcher(any(), any()) } answers | ||
{ | ||
val suffix = secondArg<String>() | ||
PathMatcher(Regex("([a-z]+)$suffix"), mapOf("suffix" to 2)) | ||
} | ||
every { pathFactory.getLongestStreamConstantPrefix(any(), any()) } returns "prefix/" | ||
} | ||
|
||
@Test | ||
fun `test that the fallback persister correctly infers the unique key to ordinal count`() = | ||
runTest { | ||
coEvery { client.list(any()) } returns | ||
flowOf( | ||
MockObj("dog"), | ||
MockObj("dog-1"), | ||
MockObj("dog-3"), | ||
MockObj("cat"), | ||
MockObj("turtle-100") | ||
) | ||
coEvery { client.getMetadata(any()) } returns mapOf("ab-generation-id" to "1") | ||
|
||
val persister = ObjectStorageFallbackPersister(client, pathFactory) | ||
val state = persister.load(stream) | ||
assertEquals(state.countByKey["dog"], 3L) | ||
assertEquals(state.countByKey["cat"], 0L) | ||
assertEquals(state.countByKey["turtle"], 100L) | ||
|
||
assertEquals(state.ensureUnique("dog"), "dog-4") | ||
assertEquals(state.ensureUnique("dog"), "dog-5") | ||
assertEquals(state.ensureUnique("cat"), "cat-1") | ||
assertEquals(state.ensureUnique("turtle"), "turtle-101") | ||
assertEquals(state.ensureUnique("turtle"), "turtle-102") | ||
assertEquals(state.ensureUnique("spider"), "spider") | ||
} | ||
} |
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.