@@ -141,11 +141,7 @@ private PartitionedTableId getRecordTable(SinkRecord record, boolean autoCreateT
141
141
142
142
TableId baseTableId = topicsToBaseTableIds .get (record .topic ());
143
143
144
- BigQuery bigQuery = getBigQuery ();
145
- if (autoCreateTables && bigQuery .getTable (baseTableId ) == null ) {
146
- getSchemaManager (bigQuery ).createTable (baseTableId , record .topic ());
147
- logger .info ("Table {} does not exist, auto-created table for topic {}" , baseTableId , record .topic ());
148
- }
144
+ maybeCreateTable (record , baseTableId , autoCreateTables );
149
145
150
146
PartitionedTableId .Builder builder = new PartitionedTableId .Builder (baseTableId );
151
147
if (useMessageTimeDatePartitioning ) {
@@ -162,6 +158,20 @@ private PartitionedTableId getRecordTable(SinkRecord record, boolean autoCreateT
162
158
return builder .build ();
163
159
}
164
160
161
+ /**
162
+ * Create the table which doesn't exist in BigQuery for a (record's) topic when autoCreateTables config is set to true.
163
+ * @param record Kafka Sink Record to be streamed into BigQuery.
164
+ * @param baseTableId BaseTableId in BigQuery.
165
+ * @param autoCreateTables If this config is set to true, auto-creating the table that doesn't not exist.
166
+ */
167
+ private void maybeCreateTable (SinkRecord record , TableId baseTableId , boolean autoCreateTables ) {
168
+ BigQuery bigQuery = getBigQuery ();
169
+ if (autoCreateTables && bigQuery .getTable (baseTableId ) == null ) {
170
+ getSchemaManager (bigQuery ).createTable (baseTableId , record .topic ());
171
+ logger .info ("Table {} does not exist, auto-created table for topic {}" , baseTableId , record .topic ());
172
+ }
173
+ }
174
+
165
175
private RowToInsert getRecordRow (SinkRecord record ) {
166
176
Map <String , Object > convertedRecord = recordConverter .convertRecord (record , KafkaSchemaRecordType .VALUE );
167
177
Optional <String > kafkaKeyFieldName = config .getKafkaKeyFieldName ();
0 commit comments