Skip to content

Commit b7d9ce7

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 15297 b: refs/heads/autosynth-bigtable c: 3bfe25e h: refs/heads/master i: 15295: 9499663
1 parent 0d6af6a commit b7d9ce7

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
@@ -126,7 +126,7 @@ refs/heads/autosynth-asset: cd8251de8c40e239ad24dcf9ed93ea2708a3eed5
126126
refs/heads/autosynth-automl: cced2f56bbef0499609073edbca6253e1df5e535
127127
refs/heads/autosynth-bigquerydatatransfer: a6667617707608b1dbfb02d59c22b5152f208da7
128128
refs/heads/autosynth-bigquerystorage: 14ab055598b943ae3f33f484e9fb1653355d08e7
129-
refs/heads/autosynth-bigtable: 344fdac3aff9dad6052fec9ccde3085bb42e55b6
129+
refs/heads/autosynth-bigtable: 3bfe25e44ed85a95c3a943647df23144223cd06e
130130
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
131131
refs/heads/autosynth-containeranalysis: 781fdb430a60f9a6491f116e31e4e10118157bdb
132132
refs/heads/autosynth-datastore: af1fb76aa3eee02fe6f31f8fa1c72a4f048d149b

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