Skip to content

Commit c728f1c

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 14955 b: refs/heads/autosynth-automl c: 3bfe25e h: refs/heads/master i: 14953: 42ae832 14951: e49c903
1 parent b229342 commit c728f1c

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
@@ -123,7 +123,7 @@ refs/heads/spanner: b01127f885b4611bf1852abb0ce481eeb7fcc131
123123
refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b
124124
refs/tags/v0.69.0: 78f67a29e8b9c46ba01de566a2eae0fd1c03edea
125125
refs/heads/autosynth-asset: cd8251de8c40e239ad24dcf9ed93ea2708a3eed5
126-
refs/heads/autosynth-automl: 344fdac3aff9dad6052fec9ccde3085bb42e55b6
126+
refs/heads/autosynth-automl: 3bfe25e44ed85a95c3a943647df23144223cd06e
127127
refs/heads/autosynth-bigquerydatatransfer: 2a9f3938237f85a8919602d74011326580ff387f
128128
refs/heads/autosynth-bigquerystorage: 99aee05df348f39d98b6fb23c292006f1d2a6c28
129129
refs/heads/autosynth-bigtable: fa0d1de9e264d7ecac8a3abc3de7a8364cfaf427

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