Skip to content

Commit 4b47359

Browse files
fix compiler errors
1 parent 2dabf9a commit 4b47359

File tree

5 files changed

+167
-83
lines changed

5 files changed

+167
-83
lines changed

airbyte-cdk/java/airbyte-cdk/azure-destinations/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
compileKotlin {
2+
compilerOptions {
3+
allWarningsAsErrors = false
4+
}
5+
}
6+
17
dependencies {
28
implementation project(':airbyte-cdk:java:airbyte-cdk:dependencies')
39
implementation project(':airbyte-cdk:java:airbyte-cdk:core')

airbyte-cdk/java/airbyte-cdk/azure-destinations/src/main/kotlin/io/airbyte/cdk/integrations/destination/jdbc/copy/azure/AzureBlobStorageConfig.kt

+14-13
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@ package io.airbyte.cdk.integrations.destination.jdbc.copy.azure
66
import com.fasterxml.jackson.databind.JsonNode
77
import java.util.*
88

9-
class AzureBlobStorageConfig(private val endpointDomainName: String?,
10-
val accountName: String,
11-
val containerName: String,
12-
val sasToken: String) {
13-
fun getEndpointDomainName(): String {
14-
return endpointDomainName ?: DEFAULT_STORAGE_ENDPOINT_DOMAIN_NAME
15-
}
9+
class AzureBlobStorageConfig(
10+
val endpointDomainName: String = DEFAULT_STORAGE_ENDPOINT_DOMAIN_NAME,
11+
val accountName: String,
12+
val containerName: String,
13+
val sasToken: String
14+
) {
1615

1716
val endpointUrl: String
18-
get() = String.format(Locale.ROOT, "https://%s.%s", accountName, getEndpointDomainName())
17+
get() = String.format(Locale.ROOT, "https://%s.%s", accountName, endpointDomainName)
1918

2019
companion object {
2120
private const val DEFAULT_STORAGE_ENDPOINT_DOMAIN_NAME = "blob.core.windows.net"
2221

2322
fun getAzureBlobConfig(config: JsonNode): AzureBlobStorageConfig {
2423
return AzureBlobStorageConfig(
25-
if (config["azure_blob_storage_endpoint_domain_name"] == null) DEFAULT_STORAGE_ENDPOINT_DOMAIN_NAME
26-
else config["azure_blob_storage_endpoint_domain_name"].asText(),
27-
config["azure_blob_storage_account_name"].asText(),
28-
config["azure_blob_storage_container_name"].asText(),
29-
config["azure_blob_storage_sas_token"].asText())
24+
if (config["azure_blob_storage_endpoint_domain_name"] == null)
25+
DEFAULT_STORAGE_ENDPOINT_DOMAIN_NAME
26+
else config["azure_blob_storage_endpoint_domain_name"].asText(),
27+
config["azure_blob_storage_account_name"].asText(),
28+
config["azure_blob_storage_container_name"].asText(),
29+
config["azure_blob_storage_sas_token"].asText()
30+
)
3031
}
3132
}
3233
}

airbyte-cdk/java/airbyte-cdk/azure-destinations/src/main/kotlin/io/airbyte/cdk/integrations/destination/jdbc/copy/azure/AzureBlobStorageStreamCopier.kt

+112-50
Original file line numberDiff line numberDiff line change
@@ -17,65 +17,70 @@ import io.airbyte.cdk.integrations.destination.jdbc.copy.StreamCopier
1717
import io.airbyte.commons.json.Jsons
1818
import io.airbyte.protocol.models.v0.AirbyteRecordMessage
1919
import io.airbyte.protocol.models.v0.DestinationSyncMode
20-
import org.apache.commons.csv.CSVFormat
21-
import org.apache.commons.csv.CSVPrinter
22-
import org.slf4j.Logger
23-
import org.slf4j.LoggerFactory
2420
import java.io.*
2521
import java.nio.charset.StandardCharsets
2622
import java.sql.SQLException
2723
import java.sql.Timestamp
2824
import java.time.Instant
2925
import java.util.*
3026
import java.util.function.Consumer
27+
import org.apache.commons.csv.CSVFormat
28+
import org.apache.commons.csv.CSVPrinter
29+
import org.slf4j.Logger
30+
import org.slf4j.LoggerFactory
31+
32+
abstract class AzureBlobStorageStreamCopier(
33+
protected val stagingFolder: String,
34+
private val destSyncMode: DestinationSyncMode,
35+
protected val schemaName: String,
36+
protected val streamName: String,
37+
private val specializedBlobClientBuilder: SpecializedBlobClientBuilder,
38+
protected val db: JdbcDatabase,
39+
protected val azureBlobConfig: AzureBlobStorageConfig,
40+
private val nameTransformer: StandardNameTransformer,
41+
private val sqlOperations: SqlOperations
42+
) : StreamCopier {
43+
protected var filenameGenerator: StagingFilenameGenerator =
44+
StagingFilenameGenerator(
45+
streamName,
46+
GlobalDataSizeConstants.DEFAULT_MAX_BATCH_SIZE_BYTES.toLong()
47+
)
48+
protected val azureStagingFiles: MutableSet<String> = HashSet()
3149

32-
abstract class AzureBlobStorageStreamCopier(protected val stagingFolder: String,
33-
private val destSyncMode: DestinationSyncMode,
34-
protected val schemaName: String,
35-
protected val streamName: String,
36-
private val specializedBlobClientBuilder: SpecializedBlobClientBuilder,
37-
protected val db: JdbcDatabase,
38-
protected val azureBlobConfig: AzureBlobStorageConfig,
39-
private val nameTransformer: StandardNameTransformer,
40-
private val sqlOperations: SqlOperations) : StreamCopier {
41-
protected var filenameGenerator: StagingFilenameGenerator = StagingFilenameGenerator(streamName, GlobalDataSizeConstants.DEFAULT_MAX_BATCH_SIZE_BYTES.toLong())
42-
protected val azureStagingFiles: MutableSet<String?> = HashSet()
43-
44-
@get:VisibleForTesting
45-
val tmpTableName: String = nameTransformer.getTmpTableName(streamName)
50+
@get:VisibleForTesting val tmpTableName: String = nameTransformer.getTmpTableName(streamName)
4651
protected val activeStagingWriterFileNames: MutableSet<String?> = HashSet()
4752
private val csvPrinters = HashMap<String?, CSVPrinter>()
4853
private val blobClients = HashMap<String?, AppendBlobClient>()
4954
override var currentFile: String? = null
50-
private set
51-
52-
fun getAzureStagingFiles(): Set<String?> {
53-
return azureStagingFiles
54-
}
5555

5656
@Throws(Exception::class)
5757
override fun write(id: UUID?, recordMessage: AirbyteRecordMessage?, azureFileName: String?) {
5858
if (csvPrinters.containsKey(azureFileName)) {
59-
csvPrinters[azureFileName]!!.printRecord(id,
60-
Jsons.serialize(recordMessage!!.data),
61-
Timestamp.from(Instant.ofEpochMilli(recordMessage.emittedAt)))
59+
csvPrinters[azureFileName]!!.printRecord(
60+
id,
61+
Jsons.serialize(recordMessage!!.data),
62+
Timestamp.from(Instant.ofEpochMilli(recordMessage.emittedAt))
63+
)
6264
}
6365
}
6466

6567
override fun prepareStagingFile(): String? {
6668
currentFile = prepareAzureStagingFile()
69+
val currentFile = this.currentFile!!
6770
if (!azureStagingFiles.contains(currentFile)) {
6871
azureStagingFiles.add(currentFile)
6972
activeStagingWriterFileNames.add(currentFile)
7073

71-
val appendBlobClient = specializedBlobClientBuilder
72-
.blobName(currentFile)
73-
.buildAppendBlobClient()
74+
val appendBlobClient =
75+
specializedBlobClientBuilder.blobName(currentFile).buildAppendBlobClient()
7476
blobClients[currentFile] = appendBlobClient
7577
appendBlobClient.create(true)
7678

7779
val bufferedOutputStream =
78-
BufferedOutputStream(appendBlobClient.blobOutputStream, Math.toIntExact(GlobalDataSizeConstants.MAX_FILE_SIZE))
80+
BufferedOutputStream(
81+
appendBlobClient.blobOutputStream,
82+
Math.toIntExact(GlobalDataSizeConstants.MAX_FILE_SIZE)
83+
)
7984
val writer = PrintWriter(bufferedOutputStream, true, StandardCharsets.UTF_8)
8085
try {
8186
csvPrinters[currentFile] = CSVPrinter(writer, CSVFormat.DEFAULT)
@@ -87,7 +92,12 @@ abstract class AzureBlobStorageStreamCopier(protected val stagingFolder: String,
8792
}
8893

8994
private fun prepareAzureStagingFile(): String {
90-
return java.lang.String.join("/", stagingFolder, schemaName, filenameGenerator.stagingFilename)
95+
return java.lang.String.join(
96+
"/",
97+
stagingFolder,
98+
schemaName,
99+
filenameGenerator.stagingFilename
100+
)
91101
}
92102

93103
@Throws(Exception::class)
@@ -107,22 +117,48 @@ abstract class AzureBlobStorageStreamCopier(protected val stagingFolder: String,
107117

108118
@Throws(Exception::class)
109119
override fun createTemporaryTable() {
110-
LOGGER.info("Preparing tmp table in destination for stream: {}, schema: {}, tmp table name: {}.", streamName, schemaName, tmpTableName)
120+
LOGGER.info(
121+
"Preparing tmp table in destination for stream: {}, schema: {}, tmp table name: {}.",
122+
streamName,
123+
schemaName,
124+
tmpTableName
125+
)
111126
sqlOperations.createTableIfNotExists(db, schemaName, tmpTableName)
112127
}
113128

114129
@Throws(Exception::class)
115130
override fun copyStagingFileToTemporaryTable() {
116-
LOGGER.info("Starting copy to tmp table: {} in destination for stream: {}, schema: {}.", tmpTableName, streamName, schemaName)
131+
LOGGER.info(
132+
"Starting copy to tmp table: {} in destination for stream: {}, schema: {}.",
133+
tmpTableName,
134+
streamName,
135+
schemaName
136+
)
117137
for (azureStagingFile in azureStagingFiles) {
118-
copyAzureBlobCsvFileIntoTable(db, getFullAzurePath(azureStagingFile), schemaName, tmpTableName, azureBlobConfig)
138+
copyAzureBlobCsvFileIntoTable(
139+
db,
140+
getFullAzurePath(azureStagingFile),
141+
schemaName,
142+
tmpTableName,
143+
azureBlobConfig
144+
)
119145
}
120-
LOGGER.info("Copy to tmp table {} in destination for stream {} complete.", tmpTableName, streamName)
146+
LOGGER.info(
147+
"Copy to tmp table {} in destination for stream {} complete.",
148+
tmpTableName,
149+
streamName
150+
)
121151
}
122152

123153
private fun getFullAzurePath(azureStagingFile: String?): String {
124-
return ("azure://" + azureBlobConfig.accountName + "." + azureBlobConfig.endpointDomainName
125-
+ "/" + azureBlobConfig.containerName + "/" + azureStagingFile)
154+
return ("azure://" +
155+
azureBlobConfig.accountName +
156+
"." +
157+
azureBlobConfig.endpointDomainName +
158+
"/" +
159+
azureBlobConfig.containerName +
160+
"/" +
161+
azureStagingFile)
126162
}
127163

128164
@Throws(Exception::class)
@@ -137,11 +173,20 @@ abstract class AzureBlobStorageStreamCopier(protected val stagingFolder: String,
137173

138174
@Throws(Exception::class)
139175
override fun generateMergeStatement(destTableName: String?): String? {
140-
LOGGER.info("Preparing to merge tmp table {} to dest table: {}, schema: {}, in destination.", tmpTableName, destTableName, schemaName)
176+
LOGGER.info(
177+
"Preparing to merge tmp table {} to dest table: {}, schema: {}, in destination.",
178+
tmpTableName,
179+
destTableName,
180+
schemaName
181+
)
141182
val queries = StringBuilder()
142183
if (destSyncMode == DestinationSyncMode.OVERWRITE) {
143184
queries.append(sqlOperations.truncateTableQuery(db, schemaName, destTableName))
144-
LOGGER.info("Destination OVERWRITE mode detected. Dest table: {}, schema: {}, truncated.", destTableName, schemaName)
185+
LOGGER.info(
186+
"Destination OVERWRITE mode detected. Dest table: {}, schema: {}, truncated.",
187+
destTableName,
188+
schemaName
189+
)
145190
}
146191
queries.append(sqlOperations.insertTableQuery(db, schemaName, tmpTableName, destTableName))
147192
return queries.toString()
@@ -175,18 +220,22 @@ abstract class AzureBlobStorageStreamCopier(protected val stagingFolder: String,
175220
}
176221

177222
@Throws(SQLException::class)
178-
abstract fun copyAzureBlobCsvFileIntoTable(database: JdbcDatabase?,
179-
snowflakeAzureExternalStageName: String?,
180-
schema: String?,
181-
tableName: String?,
182-
config: AzureBlobStorageConfig?)
223+
abstract fun copyAzureBlobCsvFileIntoTable(
224+
database: JdbcDatabase?,
225+
snowflakeAzureExternalStageName: String?,
226+
schema: String?,
227+
tableName: String?,
228+
config: AzureBlobStorageConfig?
229+
)
183230

184231
companion object {
185-
private val LOGGER: Logger = LoggerFactory.getLogger(AzureBlobStorageStreamCopier::class.java)
232+
private val LOGGER: Logger =
233+
LoggerFactory.getLogger(AzureBlobStorageStreamCopier::class.java)
186234
fun attemptAzureBlobWriteAndDelete(config: AzureBlobStorageConfig) {
187235
var appendBlobClient: AppendBlobClient? = null
188236
try {
189-
appendBlobClient = SpecializedBlobClientBuilder()
237+
appendBlobClient =
238+
SpecializedBlobClientBuilder()
190239
.endpoint(config.endpointUrl)
191240
.sasToken(config.sasToken)
192241
.containerName(config.containerName)
@@ -205,21 +254,34 @@ abstract class AzureBlobStorageStreamCopier(protected val stagingFolder: String,
205254
}
206255

207256
private fun listCreatedBlob(containerClient: BlobContainerClient) {
208-
containerClient.listBlobs().forEach(Consumer { blobItem: BlobItem -> LOGGER.info("Blob name: " + blobItem.name + "Snapshot: " + blobItem.snapshot) })
257+
containerClient
258+
.listBlobs()
259+
.forEach(
260+
Consumer { blobItem: BlobItem ->
261+
LOGGER.info(
262+
"Blob name: " + blobItem.name + "Snapshot: " + blobItem.snapshot
263+
)
264+
}
265+
)
209266
}
210267

211268
private fun writeTestDataIntoBlob(appendBlobClient: AppendBlobClient?) {
212269
val test = "test_data"
213270
LOGGER.info("Writing test data to Azure Blob storage: $test")
214-
val dataStream: InputStream = ByteArrayInputStream(test.toByteArray(StandardCharsets.UTF_8))
271+
val dataStream: InputStream =
272+
ByteArrayInputStream(test.toByteArray(StandardCharsets.UTF_8))
215273

216-
val blobCommittedBlockCount = appendBlobClient!!.appendBlock(dataStream, test.length.toLong())
274+
val blobCommittedBlockCount =
275+
appendBlobClient!!
276+
.appendBlock(dataStream, test.length.toLong())
217277
.blobCommittedBlockCount
218278

219279
LOGGER.info("blobCommittedBlockCount: $blobCommittedBlockCount")
220280
}
221281

222-
private fun getBlobContainerClient(appendBlobClient: AppendBlobClient?): BlobContainerClient {
282+
private fun getBlobContainerClient(
283+
appendBlobClient: AppendBlobClient?
284+
): BlobContainerClient {
223285
val containerClient = appendBlobClient!!.containerClient
224286
if (!containerClient.exists()) {
225287
containerClient.create()

airbyte-cdk/java/airbyte-cdk/azure-destinations/src/main/kotlin/io/airbyte/cdk/integrations/destination/jdbc/copy/azure/AzureBlobStorageStreamCopierFactory.kt

+34-19
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,54 @@ import io.airbyte.cdk.integrations.destination.jdbc.copy.StreamCopierFactory.Com
1313
import io.airbyte.protocol.models.v0.ConfiguredAirbyteStream
1414
import io.airbyte.protocol.models.v0.DestinationSyncMode
1515

16-
abstract class AzureBlobStorageStreamCopierFactory : StreamCopierFactory<AzureBlobStorageConfig?> {
17-
override fun create(configuredSchema: String?,
18-
azureBlobConfig: AzureBlobStorageConfig,
19-
stagingFolder: String?,
20-
configuredStream: ConfiguredAirbyteStream?,
21-
nameTransformer: StandardNameTransformer?,
22-
db: JdbcDatabase?,
23-
sqlOperations: SqlOperations?): StreamCopier? {
16+
abstract class AzureBlobStorageStreamCopierFactory : StreamCopierFactory<AzureBlobStorageConfig> {
17+
override fun create(
18+
configuredSchema: String?,
19+
azureBlobConfig: AzureBlobStorageConfig,
20+
stagingFolder: String?,
21+
configuredStream: ConfiguredAirbyteStream?,
22+
nameTransformer: StandardNameTransformer?,
23+
db: JdbcDatabase?,
24+
sqlOperations: SqlOperations?
25+
): StreamCopier? {
2426
try {
2527
val stream = configuredStream!!.stream
2628
val syncMode = configuredStream.destinationSyncMode
2729
val schema = getSchema(stream.namespace, configuredSchema!!, nameTransformer!!)
2830
val streamName = stream.name
2931

30-
val specializedBlobClientBuilder = SpecializedBlobClientBuilder()
32+
val specializedBlobClientBuilder =
33+
SpecializedBlobClientBuilder()
3134
.endpoint(azureBlobConfig.endpointUrl)
3235
.sasToken(azureBlobConfig.sasToken)
3336
.containerName(azureBlobConfig.containerName)
3437

35-
return create(stagingFolder, syncMode, schema, streamName, specializedBlobClientBuilder, db, azureBlobConfig, nameTransformer, sqlOperations)
38+
return create(
39+
stagingFolder,
40+
syncMode,
41+
schema,
42+
streamName,
43+
specializedBlobClientBuilder,
44+
db,
45+
azureBlobConfig,
46+
nameTransformer,
47+
sqlOperations
48+
)
3649
} catch (e: Exception) {
3750
throw RuntimeException(e)
3851
}
3952
}
4053

4154
@Throws(Exception::class)
42-
abstract fun create(stagingFolder: String?,
43-
syncMode: DestinationSyncMode?,
44-
schema: String?,
45-
streamName: String?,
46-
specializedBlobClientBuilder: SpecializedBlobClientBuilder?,
47-
db: JdbcDatabase?,
48-
azureBlobConfig: AzureBlobStorageConfig?,
49-
nameTransformer: StandardNameTransformer?,
50-
sqlOperations: SqlOperations?): StreamCopier?
55+
abstract fun create(
56+
stagingFolder: String?,
57+
syncMode: DestinationSyncMode?,
58+
schema: String?,
59+
streamName: String?,
60+
specializedBlobClientBuilder: SpecializedBlobClientBuilder?,
61+
db: JdbcDatabase?,
62+
azureBlobConfig: AzureBlobStorageConfig?,
63+
nameTransformer: StandardNameTransformer?,
64+
sqlOperations: SqlOperations?
65+
): StreamCopier?
5166
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.28.6
1+
version=0.28.7

0 commit comments

Comments
 (0)