Skip to content

Commit a247afa

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 20575 b: refs/heads/autosynth-websecurityscanner c: 3bfe25e h: refs/heads/master i: 20573: 3d5befa 20571: df70906 20567: 913b4dd 20559: fafb720 20543: f200c22
1 parent 2682bc4 commit a247afa

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ refs/heads/autosynth-speech: 75d6c62a9d07d3a3642980502a25d07fbde0f232
143143
refs/heads/autosynth-tasks: 5d6a4f686ffef2080506d3b613fc7563a8bba1cb
144144
refs/heads/autosynth-texttospeech: 2dcc5dc22be0f456caa1b6a8a4bcdace2641239c
145145
refs/heads/autosynth-trace: 8804c46bfe147702ee9c95669f17f42d3790cf23
146-
refs/heads/autosynth-websecurityscanner: 344fdac3aff9dad6052fec9ccde3085bb42e55b6
146+
refs/heads/autosynth-websecurityscanner: 3bfe25e44ed85a95c3a943647df23144223cd06e
147147
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64
148148
refs/heads/elharo-patch-1: ce159ef828d3c545991ff78e7b6e0d912a9453e9
149149
refs/heads/mrschmidt-numericadd: 96509abadf6190b7886d57fdd9b090da55f5171c

branches/autosynth-websecurityscanner/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.Serializable;
2626
import java.math.BigDecimal;
2727
import java.util.ArrayList;
28+
import java.util.Date;
2829
import java.util.List;
2930
import javax.annotation.Nullable;
3031
import org.threeten.bp.Instant;
@@ -256,6 +257,8 @@ private static <T> StandardSQLTypeName classToType(Class<T> type) {
256257
return StandardSQLTypeName.FLOAT64;
257258
} else if (BigDecimal.class.isAssignableFrom(type)) {
258259
return StandardSQLTypeName.NUMERIC;
260+
} else if (Date.class.isAssignableFrom(type)) {
261+
return StandardSQLTypeName.DATE;
259262
}
260263
throw new IllegalArgumentException("Unsupported object type for QueryParameter: " + type);
261264
}
@@ -310,6 +313,9 @@ private static <T> String valueToStringOrNull(T value, StandardSQLTypeName type)
310313
// verify that the String is in the right format
311314
checkFormat(value, dateFormatter);
312315
return (String) value;
316+
} else if (value instanceof Date) {
317+
com.google.cloud.Date date = com.google.cloud.Date.fromJavaUtilDate((Date) value);
318+
return date.toString();
313319
}
314320
break;
315321
case TIME:

branches/autosynth-websecurityscanner/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryParameterValueTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import com.google.api.services.bigquery.model.QueryParameterType;
2222
import java.math.BigDecimal;
23+
import java.text.ParseException;
24+
import java.util.Date;
2325
import java.util.List;
2426
import org.junit.Test;
2527

@@ -204,6 +206,17 @@ public void testDate() {
204206
assertThat(value.getArrayValues()).isNull();
205207
}
206208

209+
@Test
210+
public void testStandardDate() throws ParseException {
211+
com.google.cloud.Date gcDate = com.google.cloud.Date.parseDate("2016-09-18");
212+
Date date = com.google.cloud.Date.toJavaUtilDate(gcDate);
213+
QueryParameterValue value = QueryParameterValue.of(date, Date.class);
214+
assertThat(value.getValue()).isEqualTo("2016-09-18");
215+
assertThat(value.getType()).isEqualTo(StandardSQLTypeName.DATE);
216+
assertThat(value.getArrayType()).isNull();
217+
assertThat(value.getArrayValues()).isNull();
218+
}
219+
207220
@Test(expected = IllegalArgumentException.class)
208221
public void testInvalidDate() {
209222
// not supposed to have the time

0 commit comments

Comments
 (0)