Skip to content

Commit 1cfdc29

Browse files
refactor: change class name
1 parent 7949ced commit 1cfdc29

File tree

6 files changed

+121
-112
lines changed

6 files changed

+121
-112
lines changed

src/main/java/com/influxdb/v3/client/internal/FlightSqlClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Stream<VectorSchemaRoot> execute(@Nonnull final String query,
110110
@Nonnull final QueryType queryType,
111111
@Nonnull final Map<String, Object> queryParameters,
112112
@Nonnull final Map<String, String> headers,
113-
final CallOption... callOption) {
113+
final CallOption... callOptions) {
114114

115115
Map<String, Object> ticketData = new HashMap<>() {{
116116
put("database", database);
@@ -130,10 +130,10 @@ Stream<VectorSchemaRoot> execute(@Nonnull final String query,
130130
}
131131

132132
HeaderCallOption headerCallOption = metadataHeader(headers);
133-
CallOption[] callOptions = concatCallOptions(callOption, headerCallOption);
133+
CallOption[] callOptionArray = concatCallOptions(callOptions, headerCallOption);
134134

135135
Ticket ticket = new Ticket(json.getBytes(StandardCharsets.UTF_8));
136-
FlightStream stream = client.getStream(ticket, callOptions);
136+
FlightStream stream = client.getStream(ticket, callOptionArray);
137137
FlightSqlIterator iterator = new FlightSqlIterator(stream);
138138

139139
Spliterator<VectorSchemaRoot> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.NONNULL);

src/main/java/com/influxdb/v3/client/internal/GrpcCallOption.java renamed to src/main/java/com/influxdb/v3/client/internal/GrpcCallOptions.java

Lines changed: 98 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@
3737
/**
3838
* The collection of runtime options for a new RPC call.
3939
*/
40-
public final class GrpcCallOption {
40+
public final class GrpcCallOptions {
4141

4242
private final Deadline deadline;
4343
private final Executor executor;
4444
private final String compressorName;
4545
private final Boolean waitForReady;
4646
private final Integer maxInboundMessageSize;
4747
private final Integer maxOutboundMessageSize;
48-
private final CallOption[] callOptionCallback;
48+
private final CallOption[] callOptions;
4949

50-
private GrpcCallOption(@Nonnull final Builder builder) {
50+
private GrpcCallOptions(@Nonnull final Builder builder) {
5151
this.deadline = builder.deadline;
5252
this.executor = builder.executor;
5353
this.compressorName = builder.compressorName;
5454
this.waitForReady = builder.waitForReady;
5555
this.maxInboundMessageSize = builder.maxInboundMessageSize;
5656
this.maxOutboundMessageSize = builder.maxOutboundMessageSize;
57-
this.callOptionCallback = builder.callOptions.toArray(new CallOption[0]);
57+
this.callOptions = builder.callOptions.toArray(new CallOption[0]);
5858
}
5959

6060
/**
@@ -124,16 +124,16 @@ public Integer getMaxOutboundMessageSize() {
124124
* @return the CallOption list
125125
*/
126126
@Nonnull
127-
public CallOption[] getCallOptionCallback() {
128-
return callOptionCallback;
127+
public CallOption[] getCallOptions() {
128+
return callOptions;
129129
}
130130

131131
@Override
132132
public boolean equals(final Object o) {
133133
if (o == null || getClass() != o.getClass()) {
134134
return false;
135135
}
136-
GrpcCallOption that = (GrpcCallOption) o;
136+
GrpcCallOptions that = (GrpcCallOptions) o;
137137
return Objects.equals(deadline, that.deadline)
138138
&& Objects.equals(executor, that.executor)
139139
&& Objects.equals(compressorName, that.compressorName)
@@ -174,7 +174,7 @@ public static final class Builder {
174174
private Executor executor;
175175
private String compressorName;
176176
private Boolean waitForReady;
177-
private Integer maxInboundMessageSize;
177+
private Integer maxInboundMessageSize = Integer.MAX_VALUE;
178178
private Integer maxOutboundMessageSize;
179179
private final List<CallOption> callOptions = new ArrayList<>();
180180

@@ -184,14 +184,7 @@ public static final class Builder {
184184
* @return this
185185
*/
186186
public Builder withDeadline(final @Nonnull Deadline deadline) {
187-
var callOption = new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
188-
@Override
189-
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
190-
return stub.withDeadline(deadline);
191-
}
192-
};
193187
this.deadline = deadline;
194-
callOptions.add(callOption);
195188
return this;
196189
}
197190

@@ -202,14 +195,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
202195
* @return this
203196
*/
204197
public Builder withExecutor(@Nonnull final Executor executor) {
205-
var callOption = new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
206-
@Override
207-
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
208-
return stub.withExecutor(executor);
209-
}
210-
};
211198
this.executor = executor;
212-
callOptions.add(callOption);
213199
return this;
214200
}
215201

@@ -224,14 +210,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
224210
* @return this
225211
*/
226212
public Builder withCompressorName(@Nonnull final String compressorName) {
227-
var callOption = new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
228-
@Override
229-
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
230-
return stub.withCompression(compressorName);
231-
}
232-
};
233213
this.compressorName = compressorName;
234-
callOptions.add(callOption);
235214
return this;
236215
}
237216

@@ -244,14 +223,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
244223
* @return this
245224
*/
246225
public Builder withWaitForReady() {
247-
var callOption = new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
248-
@Override
249-
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
250-
return stub.withWaitForReady();
251-
}
252-
};
253226
this.waitForReady = true;
254-
callOptions.add(callOption);
255227
return this;
256228
}
257229

@@ -262,14 +234,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
262234
* @return this
263235
*/
264236
public Builder withMaxInboundMessageSize(@Nonnull final Integer maxInboundMessageSize) {
265-
var callOption = new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
266-
@Override
267-
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
268-
return stub.withMaxInboundMessageSize(maxInboundMessageSize);
269-
}
270-
};
271237
this.maxInboundMessageSize = maxInboundMessageSize;
272-
callOptions.add(callOption);
273238
return this;
274239
}
275240

@@ -279,24 +244,106 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
279244
* @return this
280245
*/
281246
public Builder withMaxOutboundMessageSize(@Nonnull final Integer maxOutboundMessageSize) {
282-
var callOption = new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
247+
this.maxOutboundMessageSize = maxOutboundMessageSize;
248+
return this;
249+
}
250+
251+
private org.apache.arrow.flight.CallOptions.GrpcCallOption createDeadlineCallOption(
252+
final Deadline deadline) {
253+
return new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
254+
@Override
255+
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
256+
return stub.withDeadline(deadline);
257+
}
258+
};
259+
}
260+
261+
private org.apache.arrow.flight.CallOptions.GrpcCallOption createExecutorCallOption(
262+
final Executor executor) {
263+
return new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
264+
@Override
265+
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
266+
return stub.withExecutor(executor);
267+
}
268+
};
269+
}
270+
271+
private org.apache.arrow.flight.CallOptions.GrpcCallOption createCompressionCallOption(
272+
final String compressorName) {
273+
return new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
274+
@Override
275+
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
276+
return stub.withCompression(compressorName);
277+
}
278+
};
279+
}
280+
281+
private org.apache.arrow.flight.CallOptions.GrpcCallOption createWaitForReadyCallOption() {
282+
return new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
283+
@Override
284+
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
285+
return stub.withWaitForReady();
286+
}
287+
};
288+
}
289+
290+
private org.apache.arrow.flight.CallOptions.GrpcCallOption createMaxInboundMessageSizeCallOption(
291+
final Integer maxInboundMessageSize) {
292+
return new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
293+
@Override
294+
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
295+
return stub.withMaxInboundMessageSize(maxInboundMessageSize);
296+
}
297+
};
298+
}
299+
300+
private org.apache.arrow.flight.CallOptions.GrpcCallOption createMaxOutboundMessageSizeCallOption(
301+
final Integer maxOutboundMessageSize) {
302+
return new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
283303
@Override
284304
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
285305
return stub.withMaxOutboundMessageSize(maxOutboundMessageSize);
286306
}
287307
};
288-
this.maxOutboundMessageSize = maxOutboundMessageSize;
289-
callOptions.add(callOption);
290-
return this;
291308
}
292309

293310
/**
294-
* Build an instance of GrpcCallOption.
311+
* Build an instance of GrpcCallOptions.
295312
*
296-
* @return the GrpcCallOption instance
313+
* @return the GrpcCallOptions instance
297314
*/
298-
public GrpcCallOption build() {
299-
return new GrpcCallOption(this);
315+
public GrpcCallOptions build() {
316+
if (deadline != null) {
317+
var callOption = createDeadlineCallOption(deadline);
318+
callOptions.add(callOption);
319+
}
320+
321+
if (executor != null) {
322+
var callOption = createExecutorCallOption(executor);
323+
callOptions.add(callOption);
324+
}
325+
326+
if (compressorName != null) {
327+
var callOption = createCompressionCallOption(compressorName);
328+
callOptions.add(callOption);
329+
}
330+
331+
if (waitForReady != null) {
332+
var callOption = createWaitForReadyCallOption();
333+
callOptions.add(callOption);
334+
}
335+
336+
if (maxInboundMessageSize != null) {
337+
var callOption = createMaxInboundMessageSizeCallOption(maxInboundMessageSize);
338+
callOptions.add(callOption);
339+
}
340+
341+
if (maxOutboundMessageSize != null) {
342+
var callOption = createMaxOutboundMessageSizeCallOption(maxOutboundMessageSize);
343+
callOptions.add(callOption);
344+
}
345+
346+
return new GrpcCallOptions(this);
300347
}
301348
}
302349
}

src/main/java/com/influxdb/v3/client/internal/InfluxDBClientImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ private Stream<VectorSchemaRoot> queryData(@Nonnull final String query,
342342
}
343343
});
344344

345-
GrpcCallOption grpcCallOption = options.grpcCallOption();
346-
CallOption[] callOptions = grpcCallOption != null ? grpcCallOption.getCallOptionCallback() : null;
345+
GrpcCallOptions grpcCallOption = options.grpcCallOption();
346+
CallOption[] callOptions = grpcCallOption != null ? grpcCallOption.getCallOptions() : null;
347347
return flightSqlClient.execute(
348348
query,
349349
database,

src/main/java/com/influxdb/v3/client/query/QueryOptions.java

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import com.influxdb.v3.client.config.ClientConfig;
3030
import com.influxdb.v3.client.internal.Arguments;
31-
import com.influxdb.v3.client.internal.GrpcCallOption;
31+
import com.influxdb.v3.client.internal.GrpcCallOptions;
3232

3333
/**
3434
* Query API options.
@@ -62,7 +62,7 @@ public final class QueryOptions {
6262
private final String database;
6363
private final QueryType queryType;
6464
private final Map<String, String> headers;
65-
private GrpcCallOption grpcCallOption;
65+
private GrpcCallOptions grpcCallOption;
6666

6767
/**
6868
* Construct QueryAPI options. The query type is set to SQL.
@@ -147,57 +147,18 @@ public Map<String, String> headersSafe() {
147147
}
148148

149149
/**
150-
* The grpcCallOption pass to this function will be merged with the default grpcCallOption.
150+
* Sets the GrpcCallOptions object.
151151
* @param grpcCallOption the grpcCallOption
152152
*/
153-
public void setGrpcCallOption(@Nonnull final GrpcCallOption grpcCallOption) {
154-
GrpcCallOption.Builder builder = getDefaultGrpcCallOptsBuilder(grpcCallOption);
155-
156-
if (grpcCallOption.getMaxOutboundMessageSize() != null) {
157-
builder.withMaxOutboundMessageSize(grpcCallOption.getMaxOutboundMessageSize());
158-
}
159-
160-
if (grpcCallOption.getExecutor() != null) {
161-
builder.withExecutor(grpcCallOption.getExecutor());
162-
}
163-
164-
if (grpcCallOption.getWaitForReady() != null) {
165-
builder.withWaitForReady();
166-
}
167-
168-
if (grpcCallOption.getDeadline() != null) {
169-
builder.withDeadline(grpcCallOption.getDeadline());
170-
}
171-
172-
if (grpcCallOption.getCompressorName() != null) {
173-
builder.withCompressorName(grpcCallOption.getCompressorName());
174-
}
175-
176-
this.grpcCallOption = builder.build();
177-
}
178-
179-
/**
180-
* @param grpcCallOption the grpcCallOption.
181-
* @return the default grpc builder with some default options
182-
*/
183-
@Nonnull
184-
private static GrpcCallOption.Builder getDefaultGrpcCallOptsBuilder(@Nonnull final GrpcCallOption grpcCallOption) {
185-
GrpcCallOption.Builder builder = new GrpcCallOption.Builder();
186-
if (grpcCallOption.getMaxInboundMessageSize() != null) {
187-
builder.withMaxInboundMessageSize(grpcCallOption.getMaxInboundMessageSize());
188-
} else {
189-
// Set this for backward compatibility
190-
builder.withMaxInboundMessageSize(Integer.MAX_VALUE);
191-
}
192-
193-
return builder;
153+
public void setGrpcCallOption(@Nonnull final GrpcCallOptions grpcCallOption) {
154+
this.grpcCallOption = grpcCallOption;
194155
}
195156

196157
/**
197-
* @return grpc call options with some default options
158+
* @return the GrpcCallOptions object.
198159
*/
199160
@Nullable
200-
public GrpcCallOption grpcCallOption() {
161+
public GrpcCallOptions grpcCallOption() {
201162
return grpcCallOption;
202163
}
203164

src/test/java/com/influxdb/v3/client/internal/FlightSqlClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,15 @@ void concatCallOptions() throws Exception {
352352
Assertions.assertThat(callOptions).isNotNull();
353353
Assertions.assertThat(callOptions.length).isEqualTo(1);
354354

355-
GrpcCallOption grpcCallOption = new GrpcCallOption.Builder()
355+
GrpcCallOptions grpcCallOption = new GrpcCallOptions.Builder()
356356
.withMaxOutboundMessageSize(1)
357357
.withCompressorName("gzip")
358358
.build();
359359

360-
callOptions = flightSqlClient.concatCallOptions(grpcCallOption.getCallOptionCallback(), headerCallOption);
360+
callOptions = flightSqlClient.concatCallOptions(grpcCallOption.getCallOptions(), headerCallOption);
361361
Assertions.assertThat(callOptions).isNotNull();
362-
Assertions.assertThat(callOptions.length).isEqualTo(3);
362+
// This equals to 4 because we always have a default maxInboundMessageSize
363+
Assertions.assertThat(callOptions.length).isEqualTo(4);
363364
}
364365
}
365366

0 commit comments

Comments
 (0)