|
| 1 | +/* |
| 2 | + * Copyright 2022 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.auto.value.AutoValue; |
| 19 | +import java.io.Serializable; |
| 20 | +import java.util.Map; |
| 21 | +import javax.annotation.Nullable; |
| 22 | + |
| 23 | +/** Represents Remote Function Options. Options for a remote user-defined function. */ |
| 24 | +@AutoValue |
| 25 | +public abstract class RemoteFunctionOptions implements Serializable { |
| 26 | + |
| 27 | + private static final long serialVersionUID = -7334249450657429792L; |
| 28 | + |
| 29 | + @AutoValue.Builder |
| 30 | + public abstract static class Builder { |
| 31 | + |
| 32 | + /** |
| 33 | + * Sets Endpoint argument Endpoint of the user-provided remote service, e.g. |
| 34 | + * ```https://us-east1-my_gcf_project.cloudfunctions.net/remote_add``` |
| 35 | + */ |
| 36 | + public abstract Builder setEndpoint(String endpoint); |
| 37 | + |
| 38 | + /** |
| 39 | + * Fully qualified name of the user-provided connection object which holds the authentication |
| 40 | + * information to send requests to the remote service. Format: |
| 41 | + * ```\"projects/{projectId}/locations/{locationId}/connections/{connectionId}\"``` |
| 42 | + */ |
| 43 | + public abstract Builder setConnection(String connection); |
| 44 | + |
| 45 | + /** |
| 46 | + * User-defined context as a set of key/value pairs, which will be sent as function invocation |
| 47 | + * context together with batched arguments in the requests to the remote service. The total |
| 48 | + * number of bytes of keys and values must be less than 8KB. |
| 49 | + */ |
| 50 | + public abstract Builder setUserDefinedContext(Map<String, String> userDefinedContext); |
| 51 | + |
| 52 | + /** |
| 53 | + * Max number of rows in each batch sent to the remote service. If absent or if 0, BigQuery |
| 54 | + * dynamically decides the number of rows in a batch. |
| 55 | + */ |
| 56 | + public abstract Builder setMaxBatchingRows(Long maxBatchingRows); |
| 57 | + |
| 58 | + /** Creates a {@code RemoteFunctionOptions} object. */ |
| 59 | + public abstract RemoteFunctionOptions build(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns the endpoint of the user-provided service. |
| 64 | + * |
| 65 | + * @return String |
| 66 | + */ |
| 67 | + @Nullable |
| 68 | + public abstract String getEndpoint(); |
| 69 | + |
| 70 | + /** |
| 71 | + * Returns the fully qualified name of the user-provided connection object. |
| 72 | + * |
| 73 | + * @return String |
| 74 | + */ |
| 75 | + @Nullable |
| 76 | + public abstract String getConnection(); |
| 77 | + |
| 78 | + /** |
| 79 | + * Returns the user-defined context as a set of key/value pairs. |
| 80 | + * |
| 81 | + * @return Map<String, String> |
| 82 | + */ |
| 83 | + @Nullable |
| 84 | + public abstract Map<String, String> getUserDefinedContext(); |
| 85 | + |
| 86 | + /** |
| 87 | + * Returns max number of rows in each batch sent to the remote service. |
| 88 | + * |
| 89 | + * @return Long |
| 90 | + */ |
| 91 | + @Nullable |
| 92 | + public abstract Long getMaxBatchingRows(); |
| 93 | + |
| 94 | + /** |
| 95 | + * Returns a builder pre-populated using the current values of this {@code RemoteFunctionOptions}. |
| 96 | + */ |
| 97 | + public abstract RemoteFunctionOptions.Builder toBuilder(); |
| 98 | + |
| 99 | + /** Returns a builder for a {@Code RemoteFunctionOptions} object. */ |
| 100 | + public static RemoteFunctionOptions.Builder newBuilder() { |
| 101 | + return new AutoValue_RemoteFunctionOptions.Builder(); |
| 102 | + } |
| 103 | + |
| 104 | + public com.google.api.services.bigquery.model.RemoteFunctionOptions toPb() { |
| 105 | + com.google.api.services.bigquery.model.RemoteFunctionOptions remoteFunctionOptions = |
| 106 | + new com.google.api.services.bigquery.model.RemoteFunctionOptions(); |
| 107 | + if (getEndpoint() != null) { |
| 108 | + remoteFunctionOptions.setEndpoint(getEndpoint()); |
| 109 | + } |
| 110 | + if (getConnection() != null) { |
| 111 | + remoteFunctionOptions.setConnection(getConnection()); |
| 112 | + } |
| 113 | + if (getUserDefinedContext() != null) { |
| 114 | + remoteFunctionOptions.setUserDefinedContext(getUserDefinedContext()); |
| 115 | + } |
| 116 | + if (getMaxBatchingRows() != null) { |
| 117 | + remoteFunctionOptions.setMaxBatchingRows(getMaxBatchingRows()); |
| 118 | + } |
| 119 | + return remoteFunctionOptions; |
| 120 | + } |
| 121 | + |
| 122 | + static RemoteFunctionOptions fromPb( |
| 123 | + com.google.api.services.bigquery.model.RemoteFunctionOptions remoteFunctionOptionsPb) { |
| 124 | + RemoteFunctionOptions.Builder builder = newBuilder(); |
| 125 | + if (remoteFunctionOptionsPb.getEndpoint() != null) { |
| 126 | + builder.setEndpoint(remoteFunctionOptionsPb.getEndpoint()); |
| 127 | + } |
| 128 | + if (remoteFunctionOptionsPb.getConnection() != null) { |
| 129 | + builder.setConnection(remoteFunctionOptionsPb.getConnection()); |
| 130 | + } |
| 131 | + if (remoteFunctionOptionsPb.getUserDefinedContext() != null) { |
| 132 | + builder.setUserDefinedContext(remoteFunctionOptionsPb.getUserDefinedContext()); |
| 133 | + } |
| 134 | + if (remoteFunctionOptionsPb.getMaxBatchingRows() != null) { |
| 135 | + builder.setMaxBatchingRows(remoteFunctionOptionsPb.getMaxBatchingRows()); |
| 136 | + } |
| 137 | + return builder.build(); |
| 138 | + } |
| 139 | +} |
0 commit comments