Skip to content

Commit 7337ec9

Browse files
committed
[bq] update BigQuery module to Spring boot 4
1 parent 2db69f0 commit 7337ec9

File tree

31 files changed

+275
-126
lines changed

31 files changed

+275
-126
lines changed

.github/workflows/spring-batch-bigquery.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
build:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v6
1818
- name: Set up JDK 17
19-
uses: actions/setup-java@v4
19+
uses: actions/setup-java@v5
2020
with:
2121
distribution: 'temurin'
2222
java-version: '17'

spring-batch-bigquery/pom.xml

100644100755
Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>org.springframework.boot</groupId>
2424
<artifactId>spring-boot-starter-parent</artifactId>
25-
<version>3.5.6</version>
25+
<version>4.0.0</version>
2626
<relativePath/>
2727
</parent>
2828

@@ -49,6 +49,10 @@
4949
</developer>
5050
</developers>
5151

52+
<properties>
53+
<avro.version>1.12.1</avro.version>
54+
</properties>
55+
5256
<scm>
5357
<url>https://github.com/spring-projects/spring-batch-extensions</url>
5458
<connection>git://github.com/spring-projects/spring-batch-extensions.git</connection>
@@ -60,7 +64,7 @@
6064
<dependency>
6165
<groupId>com.google.cloud</groupId>
6266
<artifactId>google-cloud-bigquery</artifactId>
63-
<version>2.51.0</version>
67+
<version>2.56.0</version>
6468
<exclusions>
6569
<!-- Avoid version conflicts -->
6670
<exclusion>
@@ -76,26 +80,48 @@
7680

7781
<!-- Optional -->
7882
<dependency>
79-
<groupId>com.fasterxml.jackson.dataformat</groupId>
83+
<groupId>tools.jackson.dataformat</groupId>
8084
<artifactId>jackson-dataformat-csv</artifactId>
8185
<optional>true</optional>
8286
</dependency>
87+
<dependency>
88+
<groupId>tools.jackson.core</groupId>
89+
<artifactId>jackson-databind</artifactId>
90+
<optional>true</optional>
91+
</dependency>
92+
<dependency>
93+
<groupId>tools.jackson.core</groupId>
94+
<artifactId>jackson-core</artifactId>
95+
<optional>true</optional>
96+
</dependency>
97+
8398
<dependency>
8499
<groupId>org.apache.parquet</groupId>
85100
<artifactId>parquet-avro</artifactId>
86-
<version>1.15.2</version>
101+
<version>1.16.0</version>
87102
<optional>true</optional>
88103
<exclusions>
89104
<exclusion>
90105
<groupId>org.slf4j</groupId>
91106
<artifactId>*</artifactId>
92107
</exclusion>
108+
<exclusion>
109+
<groupId>org.apache.avro</groupId>
110+
<artifactId>avro</artifactId>
111+
</exclusion>
93112
</exclusions>
94113
</dependency>
114+
<dependency>
115+
<groupId>org.apache.avro</groupId>
116+
<artifactId>avro</artifactId>
117+
<version>${avro.version}</version>
118+
<optional>true</optional>
119+
</dependency>
120+
95121
<dependency>
96122
<groupId>org.apache.hadoop</groupId>
97123
<artifactId>hadoop-common</artifactId>
98-
<version>3.4.1</version>
124+
<version>3.4.2</version>
99125
<optional>true</optional>
100126
<exclusions>
101127
<!-- End implementation should not be forced by library -->
@@ -125,6 +151,10 @@
125151
<groupId>org.xerial.snappy</groupId>
126152
<artifactId>snappy-java</artifactId>
127153
</exclusion>
154+
<exclusion>
155+
<groupId>commons-io</groupId>
156+
<artifactId>commons-io</artifactId>
157+
</exclusion>
128158
</exclusions>
129159
</dependency>
130160

@@ -152,6 +182,7 @@
152182
<dependency>
153183
<groupId>org.testcontainers</groupId>
154184
<artifactId>junit-jupiter</artifactId>
185+
<version>1.21.3</version>
155186
<scope>test</scope>
156187
<exclusions>
157188
<!-- Avoid version conflicts -->
@@ -164,7 +195,7 @@
164195
<dependency>
165196
<groupId>org.wiremock</groupId>
166197
<artifactId>wiremock-standalone</artifactId>
167-
<version>3.13.1</version>
198+
<version>3.13.2</version>
168199
<scope>test</scope>
169200
</dependency>
170201
<dependency>
@@ -201,6 +232,11 @@
201232
<goals>
202233
<goal>jar</goal>
203234
</goals>
235+
<configuration>
236+
<excludes>
237+
<exclude>org.springframework.batch.extensions.bigquery.common.generated.*</exclude>
238+
</excludes>
239+
</configuration>
204240
</execution>
205241
</executions>
206242
</plugin>
@@ -222,7 +258,7 @@
222258
<plugin>
223259
<groupId>org.codehaus.mojo</groupId>
224260
<artifactId>flatten-maven-plugin</artifactId>
225-
<version>1.7.1</version>
261+
<version>1.7.3</version>
226262
<executions>
227263
<execution>
228264
<id>flatten</id>
@@ -267,17 +303,35 @@
267303
<plugin>
268304
<groupId>org.apache.avro</groupId>
269305
<artifactId>avro-maven-plugin</artifactId>
270-
<version>1.12.0</version>
306+
<version>${avro.version}</version>
271307
<executions>
272308
<execution>
273-
<id>schemas</id>
274-
<phase>generate-sources</phase>
309+
<phase>generate-test-sources</phase>
275310
<goals>
276311
<goal>schema</goal>
277312
</goals>
278313
<configuration>
279-
<sourceDirectory>${project.basedir}/src/test/resources/</sourceDirectory>
280-
<outputDirectory>${project.basedir}/target/generated-test-sources/avro/</outputDirectory>
314+
<sourceDirectory>${project.basedir}/src/test/resources</sourceDirectory>
315+
<outputDirectory>${project.build.directory}/generated-test-sources/avro</outputDirectory>
316+
</configuration>
317+
</execution>
318+
</executions>
319+
</plugin>
320+
<!-- Copies classes from generated-test-sources to test-classes -->
321+
<plugin>
322+
<groupId>org.codehaus.mojo</groupId>
323+
<artifactId>build-helper-maven-plugin</artifactId>
324+
<version>3.6.1</version>
325+
<executions>
326+
<execution>
327+
<phase>generate-test-sources</phase>
328+
<goals>
329+
<goal>add-test-source</goal>
330+
</goals>
331+
<configuration>
332+
<sources>
333+
<source>${project.build.directory}/generated-test-sources/avro</source>
334+
</sources>
281335
</configuration>
282336
</execution>
283337
</executions>

spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/BigQueryQueryItemReader.java

100644100755
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.google.cloud.bigquery.QueryJobConfiguration;
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24-
import org.springframework.batch.item.ItemReader;
24+
import org.springframework.batch.infrastructure.item.ItemReader;
2525
import org.springframework.beans.factory.InitializingBean;
2626
import org.springframework.core.convert.converter.Converter;
2727
import org.springframework.util.Assert;
@@ -64,6 +64,12 @@ public class BigQueryQueryItemReader<T> implements ItemReader<T>, InitializingBe
6464

6565
private Iterator<FieldValueList> iterator;
6666

67+
/**
68+
* Default constructor
69+
*/
70+
public BigQueryQueryItemReader() {
71+
}
72+
6773
/**
6874
* BigQuery service, responsible for API calls.
6975
* @param bigQuery BigQuery service

spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/builder/BigQueryQueryItemReaderBuilder.java

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public class BigQueryQueryItemReaderBuilder<T> {
4848

4949
private Class<T> targetType;
5050

51+
/**
52+
* Default constructor
53+
*/
54+
public BigQueryQueryItemReaderBuilder() {
55+
}
56+
5157
/**
5258
* BigQuery service, responsible for API calls.
5359
* @param bigQuery BigQuery service

spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/builder/RecordMapper.java

100644100755
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ public final class RecordMapper<T> {
3535

3636
private final SimpleTypeConverter simpleConverter = new SimpleTypeConverter();
3737

38+
/**
39+
* Default constructor
40+
*/
41+
public RecordMapper() {
42+
}
43+
3844
/**
3945
* Generates a conversion from BigQuery response to a Java record.
40-
* @param targetType a Java record {@link Class}
46+
* @param targetType a {@link Record}
4147
* @return {@link Converter}
42-
* @see org.springframework.batch.item.file.mapping.RecordFieldSetMapper
48+
* @see org.springframework.batch.infrastructure.item.file.mapping.RecordFieldSetMapper
4349
*/
44-
public Converter<FieldValueList, T> generateMapper(Class<T> targetType) {
45-
Constructor<T> constructor = BeanUtils.getResolvableConstructor(targetType);
50+
public Converter<FieldValueList, T> generateMapper(final Class<T> targetType) {
51+
final Constructor<T> constructor = BeanUtils.getResolvableConstructor(targetType);
4652
Assert.isTrue(constructor.getParameterCount() > 0, "Record without fields is redundant");
4753

48-
String[] parameterNames = BeanUtils.getParameterNames(constructor);
49-
Class<?>[] parameterTypes = constructor.getParameterTypes();
50-
51-
Object[] args = new Object[parameterNames.length];
54+
final String[] parameterNames = BeanUtils.getParameterNames(constructor);
55+
final Class<?>[] parameterTypes = constructor.getParameterTypes();
56+
final Object[] args = new Object[parameterNames.length];
5257

5358
return source -> {
5459
if (args[0] == null) {

spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryItemWriterException.java

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.springframework.batch.extensions.bigquery.writer;
1818

19-
import org.springframework.batch.item.Chunk;
20-
import org.springframework.batch.item.ItemWriter;
21-
import org.springframework.batch.item.ItemWriterException;
19+
import org.springframework.batch.infrastructure.item.Chunk;
20+
import org.springframework.batch.infrastructure.item.ItemWriter;
21+
import org.springframework.batch.infrastructure.item.ItemWriterException;
2222

2323
/**
2424
* Unchecked {@link Exception} indicating that an error has occurred on during
@@ -35,15 +35,15 @@ public class BigQueryItemWriterException extends ItemWriterException {
3535
* @param message the message for this {@link Exception}
3636
* @param cause the other {@link Exception}
3737
*/
38-
public BigQueryItemWriterException(String message, Throwable cause) {
38+
public BigQueryItemWriterException(final String message, final Throwable cause) {
3939
super(message, cause);
4040
}
4141

4242
/**
4343
* Create a new {@link BigQueryItemWriterException} based on a message.
4444
* @param message the message for this {@link Exception}
4545
*/
46-
public BigQueryItemWriterException(String message) {
46+
public BigQueryItemWriterException(final String message) {
4747
super(message);
4848
}
4949

spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/loadjob/BigQueryLoadJobBaseItemWriter.java

100644100755
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616

1717
package org.springframework.batch.extensions.bigquery.writer.loadjob;
1818

19-
import com.google.cloud.bigquery.*;
19+
import com.google.cloud.bigquery.BigQuery;
20+
import com.google.cloud.bigquery.DatasetInfo;
21+
import com.google.cloud.bigquery.FormatOptions;
22+
import com.google.cloud.bigquery.Job;
23+
import com.google.cloud.bigquery.Table;
24+
import com.google.cloud.bigquery.TableDataWriteChannel;
25+
import com.google.cloud.bigquery.TableDefinition;
26+
import com.google.cloud.bigquery.TableId;
27+
import com.google.cloud.bigquery.WriteChannelConfiguration;
2028
import org.apache.commons.logging.Log;
2129
import org.apache.commons.logging.LogFactory;
2230
import org.springframework.batch.extensions.bigquery.writer.BigQueryItemWriterException;
23-
import org.springframework.batch.item.Chunk;
24-
import org.springframework.batch.item.ItemWriter;
31+
import org.springframework.batch.infrastructure.item.Chunk;
32+
import org.springframework.batch.infrastructure.item.ItemWriter;
2533
import org.springframework.beans.factory.InitializingBean;
2634
import org.springframework.util.Assert;
2735

@@ -43,6 +51,12 @@
4351
*/
4452
public abstract class BigQueryLoadJobBaseItemWriter<T> implements ItemWriter<T>, InitializingBean {
4553

54+
/**
55+
* Default constructor
56+
*/
57+
protected BigQueryLoadJobBaseItemWriter() {
58+
}
59+
4660
/** Logger that can be reused */
4761
protected final Log logger = LogFactory.getLog(getClass());
4862

0 commit comments

Comments
 (0)