Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the schema of dry run query jobs. #3159

Merged
merged 1 commit into from
Apr 17, 2018
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 @@ -323,6 +323,7 @@ public static class QueryStatistics extends JobStatistics {
private final Long totalBytesBilled;
private final Long totalBytesProcessed;
private final List<QueryStage> queryPlan;
private final Schema schema;

static final class Builder extends JobStatistics.Builder<QueryStatistics, Builder> {

Expand All @@ -331,6 +332,7 @@ static final class Builder extends JobStatistics.Builder<QueryStatistics, Builde
private Long totalBytesBilled;
private Long totalBytesProcessed;
private List<QueryStage> queryPlan;
private Schema schema;

private Builder() {}

Expand All @@ -346,6 +348,9 @@ private Builder(com.google.api.services.bigquery.model.JobStatistics statisticsP
Lists.transform(
statisticsPb.getQuery().getQueryPlan(), QueryStage.FROM_PB_FUNCTION);
}
if (statisticsPb.getQuery().getSchema() != null) {
this.schema = Schema.fromPb(statisticsPb.getQuery().getSchema());
}
}
}

Expand Down Expand Up @@ -374,6 +379,11 @@ Builder setQueryPlan(List<QueryStage> queryPlan) {
return self();
}

Builder setSchema(Schema schema) {
this.schema = schema;
return self();
}

@Override
QueryStatistics build() {
return new QueryStatistics(this);
Expand All @@ -387,6 +397,7 @@ private QueryStatistics(Builder builder) {
this.totalBytesBilled = builder.totalBytesBilled;
this.totalBytesProcessed = builder.totalBytesProcessed;
this.queryPlan = builder.queryPlan;
this.schema = builder.schema;
}


Expand Down Expand Up @@ -437,14 +448,24 @@ public List<QueryStage> getQueryPlan() {
return queryPlan;
}


/**
* Returns the schema for the query result. Present only for successful dry run of
* non-legacy SQL queries.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

*/
public Schema getSchema() {
return schema;
}

@Override
ToStringHelper toStringHelper() {
return super.toStringHelper()
.add("billingTier", billingTier)
.add("cacheHit", cacheHit)
.add("totalBytesBilled", totalBytesBilled)
.add("totalBytesProcessed", totalBytesProcessed)
.add("queryPlan", queryPlan);
.add("queryPlan", queryPlan)
.add("schema", schema);
}

@Override
Expand All @@ -458,7 +479,7 @@ public final boolean equals(Object obj) {
@Override
public final int hashCode() {
return Objects.hash(baseHashCode(), billingTier, cacheHit, totalBytesBilled,
totalBytesProcessed, queryPlan);
totalBytesProcessed, queryPlan, schema);
}

@Override
Expand All @@ -471,6 +492,9 @@ com.google.api.services.bigquery.model.JobStatistics toPb() {
if (queryPlan != null) {
queryStatisticsPb.setQueryPlan(Lists.transform(queryPlan, QueryStage.TO_PB_FUNCTION));
}
if (schema != null) {
queryStatisticsPb.setSchema(schema.toPb());
}
return super.toPb().setQuery(queryStatisticsPb);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class JobStatisticsTest {
.setWriteRatioMax(10.10)
.build();
private static final List<QueryStage> QUERY_PLAN = ImmutableList.of(QUERY_STAGE);
private static final Schema SCHEMA = Schema.of(Field.of("column", LegacySQLTypeName.DATETIME));
private static final QueryStatistics QUERY_STATISTICS = QueryStatistics.newBuilder()
.setCreationTimestamp(CREATION_TIME)
.setEndTime(END_TIME)
Expand All @@ -98,6 +99,7 @@ public class JobStatisticsTest {
.setTotalBytesBilled(TOTAL_BYTES_BILLED)
.setTotalBytesProcessed(TOTAL_BYTES_PROCESSED)
.setQueryPlan(QUERY_PLAN)
.setSchema(SCHEMA)
.build();
private static final QueryStatistics QUERY_STATISTICS_INCOMPLETE = QueryStatistics.newBuilder()
.setCreationTimestamp(CREATION_TIME)
Expand Down Expand Up @@ -218,6 +220,7 @@ private void compareQueryStatistics(QueryStatistics expected, QueryStatistics va
assertEquals(expected.getTotalBytesBilled(), value.getTotalBytesBilled());
assertEquals(expected.getTotalBytesProcessed(), value.getTotalBytesProcessed());
assertEquals(expected.getQueryPlan(), value.getQueryPlan());
assertEquals(expected.getSchema(), value.getSchema());
}

private void compareStatistics(JobStatistics expected, JobStatistics value) {
Expand Down