Skip to content

Commit f101fad

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 20321 b: refs/heads/autosynth-scheduler c: 3bfe25e h: refs/heads/master i: 20319: 062ec61
1 parent 1a4214a commit f101fad

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
@@ -137,7 +137,7 @@ refs/heads/autosynth-kms: 2828edfe3d2c53dd6e71912eae8a53c87bf40c87
137137
refs/heads/autosynth-language: c3d990dd34d81e7e935041e7147fb9dd27f8a557
138138
refs/heads/autosynth-os-login: 092fdbed6d5317948f92b708e9f50dedd89fc666
139139
refs/heads/autosynth-redis: 9e1fe503973c7b4a9ba26afb1fcddc2a57ba795a
140-
refs/heads/autosynth-scheduler: 344fdac3aff9dad6052fec9ccde3085bb42e55b6
140+
refs/heads/autosynth-scheduler: 3bfe25e44ed85a95c3a943647df23144223cd06e
141141
refs/heads/autosynth-spanner: 9bff86d057df31e04c76d72865e8e073ac5794fb
142142
refs/heads/autosynth-speech: 75d6c62a9d07d3a3642980502a25d07fbde0f232
143143
refs/heads/autosynth-tasks: b0cdb991f3f75345151a3f68db1aab273dfc069b

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