Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class QueryJobConfiguration extends JobConfiguration {
private final Boolean useQueryCache;
private final Boolean flattenResults;
private final Boolean dryRun;
private final Boolean useLegacySql;

/**
* Priority levels for a query. If not specified the priority is assumed to be
Expand Down Expand Up @@ -87,6 +88,7 @@ public static final class Builder
private Boolean useQueryCache;
private Boolean flattenResults;
private Boolean dryRun;
private Boolean useLegacySql;

private Builder() {
super(Type.QUERY);
Expand All @@ -106,6 +108,7 @@ private Builder(QueryJobConfiguration jobConfiguration) {
this.useQueryCache = jobConfiguration.useQueryCache;
this.flattenResults = jobConfiguration.flattenResults;
this.dryRun = jobConfiguration.dryRun;
this.useLegacySql = jobConfiguration.useLegacySql;
}

private Builder(com.google.api.services.bigquery.model.JobConfiguration configurationPb) {
Expand All @@ -115,6 +118,7 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
allowLargeResults = queryConfigurationPb.getAllowLargeResults();
useQueryCache = queryConfigurationPb.getUseQueryCache();
flattenResults = queryConfigurationPb.getFlattenResults();
useLegacySql = queryConfigurationPb.getUseLegacySql();
dryRun = configurationPb.getDryRun();
if (queryConfigurationPb.getDestinationTable() != null) {
destinationTable = TableId.fromPb(queryConfigurationPb.getDestinationTable());
Expand Down Expand Up @@ -293,6 +297,20 @@ public Builder dryRun(Boolean dryRun) {
return this;
}

/**
* Sets whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
* Standard SQL</a>. When set to {@code false}, the values of
* {@link #allowLargeResults(Boolean)} and {@link #flattenResults(Boolean)} are ignored; query
* will be run as if {@link #allowLargeResults(Boolean)} is {@code true} and
* {@link #flattenResults(Boolean)} is {@code false}. If not set, legacy SQL dialect is used.
* This property is experimental and might be subject to change.
*/
public Builder useLegacySql(Boolean useLegacySql) {
this.useLegacySql = useLegacySql;
return this;
}

public QueryJobConfiguration build() {
return new QueryJobConfiguration(this);
}
Expand All @@ -313,6 +331,7 @@ private QueryJobConfiguration(Builder builder) {
this.tableDefinitions =
builder.tableDefinitions != null ? ImmutableMap.copyOf(builder.tableDefinitions) : null;
this.dryRun = builder.dryRun;
this.useLegacySql = builder.useLegacySql;
}

/**
Expand Down Expand Up @@ -426,6 +445,18 @@ public Boolean dryRun() {
return dryRun;
}

/**
* Returns whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
* Standard SQL</a>. When set to {@code false}, the values of {@link #allowLargeResults()} and
* {@link #flattenResults()} are ignored; query will be run as if {@link #allowLargeResults()} is
* {@code true} and {@link #flattenResults()} is {@code false}. If not set, legacy SQL dialect is
* used. This property is experimental and might be subject to change.
*/
public Boolean useLegacySql() {
return useLegacySql;
}

@Override
public Builder toBuilder() {
return new Builder(this);
Expand All @@ -445,7 +476,8 @@ ToStringHelper toStringHelper() {
.add("userDefinedFunctions", userDefinedFunctions)
.add("createDisposition", createDisposition)
.add("writeDisposition", writeDisposition)
.add("dryRun", dryRun);
.add("dryRun", dryRun)
.add("useLegacySql", useLegacySql);
}

@Override
Expand All @@ -459,7 +491,7 @@ public boolean equals(Object obj) {
public int hashCode() {
return Objects.hash(baseHashCode(), allowLargeResults, createDisposition, destinationTable,
defaultDataset, flattenResults, priority, query, tableDefinitions, useQueryCache,
userDefinedFunctions, writeDisposition, dryRun);
userDefinedFunctions, writeDisposition, dryRun, useLegacySql);
}

@Override
Expand Down Expand Up @@ -513,6 +545,9 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
if (writeDisposition != null) {
queryConfigurationPb.setWriteDisposition(writeDisposition.toString());
}
if (useLegacySql != null) {
queryConfigurationPb.setUseLegacySql(useLegacySql);
}
return configurationPb.setQuery(queryConfigurationPb);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public final class QueryRequest implements Serializable {
private final Long maxWaitTime;
private final Boolean dryRun;
private final Boolean useQueryCache;
private final Boolean useLegacySql;

public static final class Builder {

Expand All @@ -79,6 +80,7 @@ public static final class Builder {
private Long maxWaitTime;
private Boolean dryRun;
private Boolean useQueryCache;
private Boolean useLegacySql;

private Builder() {}

Expand Down Expand Up @@ -150,6 +152,17 @@ public Builder useQueryCache(Boolean useQueryCache) {
return this;
}

/**
* Sets whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
* Standard SQL</a>. If not set, legacy SQL dialect is used. This property is experimental and
* might be subject to change.
*/
public Builder useLegacySql(Boolean useLegacySql) {
this.useLegacySql = useLegacySql;
return this;
}

public QueryRequest build() {
return new QueryRequest(this);
}
Expand All @@ -162,6 +175,7 @@ private QueryRequest(Builder builder) {
maxWaitTime = builder.maxWaitTime;
dryRun = builder.dryRun;
useQueryCache = builder.useQueryCache;
useLegacySql = builder.useLegacySql;
}

/**
Expand Down Expand Up @@ -218,6 +232,16 @@ public Boolean useQueryCache() {
return useQueryCache;
}

/**
* Returns whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
* Standard SQL</a>. If not set, legacy SQL dialect is used. This property is experimental and
* might be subject to change.
*/
public Boolean useLegacySql() {
return useLegacySql;
}

/**
* Returns a builder for the {@code QueryRequest} object.
*/
Expand All @@ -228,7 +252,8 @@ public Builder toBuilder() {
.defaultDataset(defaultDataset)
.maxWaitTime(maxWaitTime)
.dryRun(dryRun)
.useQueryCache(useQueryCache);
.useQueryCache(useQueryCache)
.useLegacySql(useLegacySql);
}

@Override
Expand All @@ -240,12 +265,14 @@ public String toString() {
.add("maxWaitTime", maxWaitTime)
.add("dryRun", dryRun)
.add("useQueryCache", useQueryCache)
.add("useLegacySql", useLegacySql)
.toString();
}

@Override
public int hashCode() {
return Objects.hash(query, pageSize, defaultDataset, maxWaitTime, dryRun, useQueryCache);
return Objects.hash(query, pageSize, defaultDataset, maxWaitTime, dryRun, useQueryCache,
useLegacySql);
}

@Override
Expand Down Expand Up @@ -281,6 +308,9 @@ com.google.api.services.bigquery.model.QueryRequest toPb() {
if (useQueryCache != null) {
queryRequestPb.setUseQueryCache(useQueryCache);
}
if (useLegacySql != null) {
queryRequestPb.setUseLegacySql(useLegacySql);
}
return queryRequestPb;
}

Expand Down Expand Up @@ -315,6 +345,9 @@ static QueryRequest fromPb(com.google.api.services.bigquery.model.QueryRequest q
if (queryRequestPb.getUseQueryCache() != null) {
builder.useQueryCache(queryRequestPb.getUseQueryCache());
}
if (queryRequestPb.getUseLegacySql() != null) {
builder.useLegacySql(queryRequestPb.getUseLegacySql());
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class QueryJobConfigurationTest {
private static final boolean ALLOW_LARGE_RESULTS = true;
private static final boolean USE_QUERY_CACHE = false;
private static final boolean FLATTEN_RESULTS = true;
private static final boolean USE_LEGACY_SQL = true;
private static final List<UserDefinedFunction> USER_DEFINED_FUNCTIONS = ImmutableList.of(
UserDefinedFunction.inline("Function"), UserDefinedFunction.fromUri("URI"));
private static final QueryJobConfiguration QUERY_JOB_CONFIGURATION =
Expand All @@ -87,6 +88,7 @@ public class QueryJobConfigurationTest {
.flattenResults(FLATTEN_RESULTS)
.userDefinedFunctions(USER_DEFINED_FUNCTIONS)
.dryRun(true)
.useLegacySql(USE_LEGACY_SQL)
.build();

@Test
Expand Down Expand Up @@ -127,6 +129,7 @@ public void testBuilder() {
assertEquals(USER_DEFINED_FUNCTIONS, QUERY_JOB_CONFIGURATION.userDefinedFunctions());
assertEquals(WRITE_DISPOSITION, QUERY_JOB_CONFIGURATION.writeDisposition());
assertTrue(QUERY_JOB_CONFIGURATION.dryRun());
assertTrue(QUERY_JOB_CONFIGURATION.useLegacySql());
}

@Test
Expand Down Expand Up @@ -165,5 +168,6 @@ private void compareQueryJobConfiguration(QueryJobConfiguration expected,
assertEquals(expected.useQueryCache(), value.useQueryCache());
assertEquals(expected.userDefinedFunctions(), value.userDefinedFunctions());
assertEquals(expected.writeDisposition(), value.writeDisposition());
assertEquals(expected.useLegacySql(), value.useLegacySql());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Rule;
import org.junit.Test;
Expand All @@ -31,12 +32,14 @@ public class QueryRequestTest {
private static final Boolean DRY_RUN = false;
private static final Long PAGE_SIZE = 42L;
private static final Long MAX_WAIT_TIME = 42000L;
private static final Boolean USE_LEGACY_SQL = true;
private static final QueryRequest QUERY_REQUEST = QueryRequest.builder(QUERY)
.useQueryCache(USE_QUERY_CACHE)
.defaultDataset(DATASET_ID)
.dryRun(DRY_RUN)
.pageSize(PAGE_SIZE)
.maxWaitTime(MAX_WAIT_TIME)
.useLegacySql(USE_LEGACY_SQL)
.build();

@Rule
Expand Down Expand Up @@ -67,6 +70,7 @@ public void testBuilder() {
assertEquals(DRY_RUN, QUERY_REQUEST.dryRun());
assertEquals(PAGE_SIZE, QUERY_REQUEST.pageSize());
assertEquals(MAX_WAIT_TIME, QUERY_REQUEST.maxWaitTime());
assertTrue(QUERY_REQUEST.useLegacySql());
thrown.expect(NullPointerException.class);
QueryRequest.builder(null);
}
Expand All @@ -80,6 +84,7 @@ public void testOf() {
assertNull(request.dryRun());
assertNull(request.pageSize());
assertNull(request.maxWaitTime());
assertNull(request.useLegacySql());
thrown.expect(NullPointerException.class);
QueryRequest.of(null);
}
Expand All @@ -104,5 +109,6 @@ private void compareQueryRequest(QueryRequest expected, QueryRequest value) {
assertEquals(expected.dryRun(), value.dryRun());
assertEquals(expected.pageSize(), value.pageSize());
assertEquals(expected.maxWaitTime(), value.maxWaitTime());
assertEquals(expected.useLegacySql(), value.useLegacySql());
}
}