|
| 1 | +/* |
| 2 | + * Copyright 2018 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.cloud.bigquery; |
| 17 | + |
| 18 | +import com.google.api.services.bigquery.model.QueryTimelineSample; |
| 19 | +import com.google.common.base.Function; |
| 20 | +import com.google.auto.value.AutoValue; |
| 21 | +import javax.annotation.Nullable; |
| 22 | + |
| 23 | +/** |
| 24 | + * A specific timeline sample. This instruments work progress at a given point in time, providing |
| 25 | + * information about work units active/pending/completed as well as cumulative slot-milliseconds. |
| 26 | + */ |
| 27 | +@AutoValue |
| 28 | +public abstract class TimelineSample { |
| 29 | + |
| 30 | + private static final long serialVersionUID = 1L; |
| 31 | + |
| 32 | + @AutoValue.Builder |
| 33 | + public abstract static class Builder { |
| 34 | + |
| 35 | + public abstract Builder setElapsedMs(Long elapsedMs); |
| 36 | + |
| 37 | + public abstract Builder setActiveUnits(Long activeUnits); |
| 38 | + |
| 39 | + public abstract Builder setCompletedUnits(Long completedUnits); |
| 40 | + |
| 41 | + public abstract Builder setPendingUnits(Long pendingUnits); |
| 42 | + |
| 43 | + public abstract Builder setSlotMillis(Long slotMillis); |
| 44 | + |
| 45 | + public abstract TimelineSample build(); |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns the sample time as milliseconds elapsed since the start of query execution. |
| 51 | + */ |
| 52 | + @Nullable |
| 53 | + public abstract Long getElapsedMs(); |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns the total number of work units currently being processed. |
| 57 | + */ |
| 58 | + @Nullable |
| 59 | + public abstract Long getActiveUnits(); |
| 60 | + |
| 61 | + /** |
| 62 | + * Returns the total number of work units completed by this query. |
| 63 | + */ |
| 64 | + @Nullable |
| 65 | + public abstract Long getCompletedUnits(); |
| 66 | + |
| 67 | + /** |
| 68 | + * Returns the number of work units remaining for the currently active stages. |
| 69 | + */ |
| 70 | + @Nullable |
| 71 | + public abstract Long getPendingUnits(); |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the cumulative slot-milliseconds consumed by the query. |
| 75 | + */ |
| 76 | + @Nullable |
| 77 | + public abstract Long getSlotMillis(); |
| 78 | + |
| 79 | + /** |
| 80 | + * return a builder for the {@TimelineSample} object. |
| 81 | + */ |
| 82 | + public abstract Builder toBuilder(); |
| 83 | + |
| 84 | + static Builder newBuilder() { |
| 85 | + return new AutoValue_TimelineSample.Builder(); |
| 86 | + } |
| 87 | + |
| 88 | + static TimelineSample fromPb(QueryTimelineSample sample) { |
| 89 | + Builder builder = newBuilder(); |
| 90 | + builder.setElapsedMs(sample.getElapsedMs()); |
| 91 | + builder.setActiveUnits(sample.getActiveUnits()); |
| 92 | + builder.setCompletedUnits(sample.getCompletedUnits()); |
| 93 | + builder.setPendingUnits(sample.getPendingUnits()); |
| 94 | + builder.setSlotMillis(sample.getTotalSlotMs()); |
| 95 | + return builder.build(); |
| 96 | + } |
| 97 | + |
| 98 | + QueryTimelineSample toPb() { |
| 99 | + QueryTimelineSample sample = new QueryTimelineSample() |
| 100 | + .setElapsedMs(getElapsedMs()) |
| 101 | + .setActiveUnits(getActiveUnits()) |
| 102 | + .setCompletedUnits(getCompletedUnits()) |
| 103 | + .setPendingUnits(getPendingUnits()) |
| 104 | + .setTotalSlotMs(getSlotMillis()); |
| 105 | + return sample; |
| 106 | + } |
| 107 | + |
| 108 | + static final Function<QueryTimelineSample, TimelineSample> FROM_PB_FUNCTION = |
| 109 | + new Function<QueryTimelineSample, TimelineSample>() { |
| 110 | + @Override |
| 111 | + public TimelineSample apply(QueryTimelineSample pb) { |
| 112 | + return TimelineSample.fromPb(pb); |
| 113 | + } |
| 114 | + }; |
| 115 | + |
| 116 | + static final Function<TimelineSample, QueryTimelineSample> TO_PB_FUNCTION = |
| 117 | + new Function<TimelineSample, QueryTimelineSample>() { |
| 118 | + @Override |
| 119 | + public QueryTimelineSample apply(TimelineSample sample) { |
| 120 | + return sample.toPb(); |
| 121 | + } |
| 122 | + }; |
| 123 | + |
| 124 | +} |
0 commit comments