Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb19ad76

Browse files
authored
feat(bigquery): enable use of GEOGRAPHY query params (#2158)
* feat(bigquery): enable use of GEOGRAPHY query params
1 parent970135b commitb19ad76

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ public static QueryParameterValue string(String value) {
258258
returnof(value,StandardSQLTypeName.STRING);
259259
}
260260

261+
/** Creates a {@code QueryParameterValue} object with a type of GEOGRAPHY. */
262+
publicstaticQueryParameterValuegeography(Stringvalue) {
263+
returnof(value,StandardSQLTypeName.GEOGRAPHY);
264+
}
265+
261266
/**
262267
* Creates a {@code QueryParameterValue} object with a type of JSON. Currently, this is only
263268
* supported in INSERT, not in query as a filter
@@ -369,6 +374,8 @@ private static <T> StandardSQLTypeName classToType(Class<T> type) {
369374
returnStandardSQLTypeName.BOOL;
370375
}elseif (String.class.isAssignableFrom(type)) {
371376
returnStandardSQLTypeName.STRING;
377+
}elseif (String.class.isAssignableFrom(type)) {
378+
returnStandardSQLTypeName.GEOGRAPHY;
372379
}elseif (Integer.class.isAssignableFrom(type)) {
373380
returnStandardSQLTypeName.INT64;
374381
}elseif (Long.class.isAssignableFrom(type)) {
@@ -422,6 +429,8 @@ private static <T> String valueToStringOrNull(T value, StandardSQLTypeName type)
422429
break;
423430
caseSTRING:
424431
returnvalue.toString();
432+
caseGEOGRAPHY:
433+
returnvalue.toString();
425434
caseJSON:
426435
if (valueinstanceofString ||valueinstanceofJsonObject)returnvalue.toString();
427436
caseINTERVAL:

‎google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryParameterValueTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ public void testString() {
196196
assertThat(value.getArrayValues()).isNull();
197197
}
198198

199+
@Test
200+
publicvoidtestGeography() {
201+
QueryParameterValuevalue =QueryParameterValue.geography("POINT(-122.350220 47.649154)");
202+
assertThat(value.getValue()).isEqualTo("POINT(-122.350220 47.649154)");
203+
assertThat(value.getType()).isEqualTo(StandardSQLTypeName.GEOGRAPHY);
204+
assertThat(value.getArrayType()).isNull();
205+
assertThat(value.getArrayValues()).isNull();
206+
}
207+
199208
@Test
200209
publicvoidtestJson() {
201210
QueryParameterValuevalue =

‎google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3655,6 +3655,28 @@ public void testBytesParameter() throws Exception {
36553655
assertEquals(1,rowCount);
36563656
}
36573657

3658+
@Test
3659+
publicvoidtestGeographyParameter()throwsException {
3660+
// Issues a simple ST_DISTANCE using two geopoints, one being a named geography parameter.
3661+
Stringquery =
3662+
"SELECT ST_DISTANCE(ST_GEOGFROMTEXT(\"POINT(-122.335503 47.625536)\"), @geo) < 3000 as within3k";
3663+
QueryParameterValuegeoParameterValue =
3664+
QueryParameterValue.geography("POINT(-122.3509153 47.6495389)");
3665+
QueryJobConfigurationconfig =
3666+
QueryJobConfiguration.newBuilder(query)
3667+
.setDefaultDataset(DatasetId.of(DATASET))
3668+
.setUseLegacySql(false)
3669+
.addNamedParameter("geo",geoParameterValue)
3670+
.build();
3671+
TableResultresult =bigquery.query(config);
3672+
introwCount =0;
3673+
for (FieldValueListrow :result.getValues()) {
3674+
rowCount++;
3675+
assertEquals(true,row.get(0).getBooleanValue());
3676+
}
3677+
assertEquals(1,rowCount);
3678+
}
3679+
36583680
@Test
36593681
publicvoidtestListJobs() {
36603682
Page<Job>jobs =bigquery.listJobs();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp