Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:25.4.0')
implementation platform('com.google.cloud:libraries-bom:26.0.0')

implementation 'com.google.cloud:google-cloud-bigquery'
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ public static QueryParameterValue string(String value) {
return of(value, StandardSQLTypeName.STRING);
}

/** Creates a {@code QueryParameterValue} object with a type of GEOGRAPHY. */
public static QueryParameterValue geography(String value) {
return of(value, StandardSQLTypeName.GEOGRAPHY);
}

/**
* Creates a {@code QueryParameterValue} object with a type of JSON. Currently, this is only
* supported in INSERT, not in query as a filter
Expand Down Expand Up @@ -369,6 +374,8 @@ private static <T> StandardSQLTypeName classToType(Class<T> type) {
return StandardSQLTypeName.BOOL;
} else if (String.class.isAssignableFrom(type)) {
return StandardSQLTypeName.STRING;
} else if (String.class.isAssignableFrom(type)) {
return StandardSQLTypeName.GEOGRAPHY;
} else if (Integer.class.isAssignableFrom(type)) {
return StandardSQLTypeName.INT64;
} else if (Long.class.isAssignableFrom(type)) {
Expand Down Expand Up @@ -422,6 +429,8 @@ private static <T> String valueToStringOrNull(T value, StandardSQLTypeName type)
break;
case STRING:
return value.toString();
case GEOGRAPHY:
return value.toString();
case JSON:
if (value instanceof String || value instanceof JsonObject) return value.toString();
case INTERVAL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ public void testString() {
assertThat(value.getArrayValues()).isNull();
}

@Test
public void testGeography() {
QueryParameterValue value = QueryParameterValue.geography("POINT(-122.350220 47.649154)");
assertThat(value.getValue()).isEqualTo("POINT(-122.350220 47.649154)");
assertThat(value.getType()).isEqualTo(StandardSQLTypeName.GEOGRAPHY);
assertThat(value.getArrayType()).isNull();
assertThat(value.getArrayValues()).isNull();
}

@Test
public void testJson() {
QueryParameterValue value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3655,6 +3655,28 @@ public void testBytesParameter() throws Exception {
assertEquals(1, rowCount);
}

@Test
public void testGeographyParameter() throws Exception {
// Issues a simple ST_DISTANCE using two geopoints, one being a named geography parameter.
String query =
"SELECT ST_DISTANCE(ST_GEOGFROMTEXT(\"POINT(-122.335503 47.625536)\"), @geo) < 3000 as within3k";
QueryParameterValue geoParameterValue =
QueryParameterValue.geography("POINT(-122.3509153 47.6495389)");
QueryJobConfiguration config =
QueryJobConfiguration.newBuilder(query)
.setDefaultDataset(DatasetId.of(DATASET))
.setUseLegacySql(false)
.addNamedParameter("geo", geoParameterValue)
.build();
TableResult result = bigquery.query(config);
int rowCount = 0;
for (FieldValueList row : result.getValues()) {
rowCount++;
assertEquals(true, row.get(0).getBooleanValue());
}
assertEquals(1, rowCount);
}

@Test
public void testListJobs() {
Page<Job> jobs = bigquery.listJobs();
Expand Down