Skip to content

Commit

Permalink
Destination S3V2: Fix: Avro names starting with numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
johnny-schmidt committed Dec 23, 2024
1 parent 773bc45 commit cc86e19
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class Transformations {
.joinToString(separator = ".")
}

fun toAvroSafeName(name: String) = toAlphanumericAndUnderscore(name)
fun toAvroSafeName(name: String): String {
val stripped = toAlphanumericAndUnderscore(name)
return if (stripped.substring(0, 1).matches("[A-Za-z_]".toRegex())) {
stripped
} else {
"_$stripped"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.cdk.load.data

import org.junit.jupiter.api.Test

class TransformationsTest {
@Test
fun `test avro illegal start character`() {
val unsafeName = "1d_view"
assert(Transformations.toAvroSafeName(unsafeName) == "_1d_view")
}

@Test
fun `test avro special characters`() {
val unsafeName = "1d_view!@#$%^&*()"
assert(Transformations.toAvroSafeName(unsafeName) == "_1d_view__________")
}
}

0 comments on commit cc86e19

Please sign in to comment.