Skip to content

Commit d1e5357

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 13639 b: refs/heads/autosynth-dlp c: 3bfe25e h: refs/heads/master i: 13637: fece563 13635: d875ed2 13631: c15e0ce
1 parent 155bac7 commit d1e5357

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
@@ -104,7 +104,7 @@ refs/tags/v0.60.0: 4cd518d0612329f8a8e53484eef4cd1651e32855
104104
refs/tags/v0.61.0: e4b526656bb1bf5eefd0ee578b7405147821225e
105105
refs/tags/v0.62.0: bbede7385d48ba08f487bdd29ec10668ace96396
106106
refs/heads/0.60.0-alpha: 10939381ffe0b8da32db4fe3087c86e3aa7f3e55
107-
refs/heads/autosynth-dlp: 344fdac3aff9dad6052fec9ccde3085bb42e55b6
107+
refs/heads/autosynth-dlp: 3bfe25e44ed85a95c3a943647df23144223cd06e
108108
refs/heads/autosynth-logging: f8794c50a64f62b167cddf42513d133547679e01
109109
refs/heads/dupes: 3478c5d81fd242d0e985656645a679420a2060c2
110110
refs/tags/v0.63.0: 94f19b71d40f46b36120e7b9d78a1a3d41bfcbd6

branches/autosynth-dlp/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-dlp/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)