-
Notifications
You must be signed in to change notification settings - Fork 132
feat: support unnamed parameters #3820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eebf2d0
feat: support unnamed parameters
sakthivelmanii 29a5c5a
Create staementfactory on-demand
sakthivelmanii 3f42072
Remove unused variable
sakthivelmanii 899400c
Update clirr for exposing newStatementFactory in the DatabaseClient i…
sakthivelmanii d677799
Address comments
sakthivelmanii cf7b397
Fix clirr issue with renaming
sakthivelmanii fb618d5
Addressed comments
sakthivelmanii 07e5569
Addressed comments
sakthivelmanii c8390b1
Addressed comments
sakthivelmanii 668be97
Added tests
sakthivelmanii 05713f3
Addressed comments
sakthivelmanii 0a7594c
Addressed comments
sakthivelmanii 1cd0c6e
Addressed comments
sakthivelmanii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerTypeConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner; | ||
|
||
import com.google.cloud.Date; | ||
import com.google.protobuf.ListValue; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.TemporalAccessor; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
final class SpannerTypeConverter { | ||
|
||
private static final ZoneId UTC_ZONE = ZoneId.of("UTC"); | ||
private static final DateTimeFormatter ISO_8601_DATE_FORMATTER = | ||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); | ||
|
||
static <T> Value createUntypedArrayValue(Stream<T> stream) { | ||
List<com.google.protobuf.Value> values = | ||
stream | ||
.map( | ||
val -> | ||
com.google.protobuf.Value.newBuilder() | ||
.setStringValue(String.valueOf(val)) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
return Value.untyped( | ||
com.google.protobuf.Value.newBuilder() | ||
.setListValue(ListValue.newBuilder().addAllValues(values).build()) | ||
.build()); | ||
} | ||
|
||
static <T extends TemporalAccessor> String convertToISO8601(T dateTime) { | ||
return ISO_8601_DATE_FORMATTER.format(dateTime); | ||
} | ||
|
||
static <T> Value createUntypedStringValue(T value) { | ||
return Value.untyped( | ||
com.google.protobuf.Value.newBuilder().setStringValue(String.valueOf(value)).build()); | ||
} | ||
|
||
static <T, U> Iterable<U> convertToTypedIterable( | ||
Function<T, U> func, T val, Iterator<?> iterator) { | ||
List<U> values = new ArrayList<>(); | ||
SpannerTypeConverter.processIterable(val, iterator, func, values::add); | ||
return values; | ||
} | ||
|
||
static <T> Iterable<T> convertToTypedIterable(T val, Iterator<?> iterator) { | ||
return convertToTypedIterable(v -> v, val, iterator); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
static <T, U> void processIterable( | ||
T val, Iterator<?> iterator, Function<T, U> func, Consumer<U> consumer) { | ||
consumer.accept(func.apply(val)); | ||
iterator.forEachRemaining(values -> consumer.accept(func.apply((T) values))); | ||
} | ||
|
||
static Date convertLocalDateToSpannerDate(LocalDate date) { | ||
return Date.fromYearMonthDay(date.getYear(), date.getMonthValue(), date.getDayOfMonth()); | ||
} | ||
|
||
static <T> Value createUntypedIterableValue( | ||
T value, Iterator<?> iterator, Function<T, String> func) { | ||
ListValue.Builder listValueBuilder = ListValue.newBuilder(); | ||
SpannerTypeConverter.processIterable( | ||
value, | ||
iterator, | ||
(val) -> com.google.protobuf.Value.newBuilder().setStringValue(func.apply(val)).build(), | ||
listValueBuilder::addValues); | ||
return Value.untyped( | ||
com.google.protobuf.Value.newBuilder().setListValue(listValueBuilder.build()).build()); | ||
} | ||
|
||
static ZonedDateTime atUTC(LocalDateTime localDateTime) { | ||
return atUTC(localDateTime.atZone(ZoneId.systemDefault())); | ||
} | ||
|
||
static ZonedDateTime atUTC(OffsetDateTime localDateTime) { | ||
return localDateTime.atZoneSameInstant(UTC_ZONE); | ||
} | ||
|
||
static ZonedDateTime atUTC(ZonedDateTime localDateTime) { | ||
return localDateTime.withZoneSameInstant(UTC_ZONE); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.