Dippatel98 commented on code in PR #27366: URL: https://github.com/apache/beam/pull/27366#discussion_r1258437648
########## sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubUtils.java: ########## @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.io.gcp.pubsub; + +import com.google.cloud.pubsub.v1.SchemaServiceClient; +import com.google.cloud.pubsub.v1.SubscriptionAdminClient; +import com.google.cloud.pubsub.v1.TopicAdminClient; +import com.google.pubsub.v1.Encoding; +import com.google.pubsub.v1.Schema; +import com.google.pubsub.v1.Topic; +import java.io.IOException; +import org.apache.beam.sdk.io.gcp.common.ProtoSchemaUtils; +import org.apache.beam.sdk.schemas.utils.AvroUtils; +import org.apache.beam.sdk.schemas.utils.JsonUtils; +import org.apache.beam.sdk.transforms.SerializableFunction; +import org.apache.beam.sdk.values.KV; +import org.apache.beam.sdk.values.Row; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** A utility class for working with Google Cloud Pub/Sub topics and subscriptions. */ +public class PubsubUtils { + + /** + * Retrieves the schema and data conversion function for a Pub/Sub topic. + * + * @param topicName the name of the Pub/Sub topic + * @param subscriptionName the name of the subscription to the topic (optional) + * @return a {@link KV} object containing the schema and data conversion function + * @throws IOException if an error occurs while retrieving the schema from Pub/Sub + * @throws IllegalArgumentException if the schema or encoding is not supported + */ + public static KV<org.apache.beam.sdk.schemas.Schema, SerializableFunction<byte[], Row>> Review Comment: The method in question uses `com.google.cloud.pubsub.v1.TopicAdminClient` to query the pubsub service for Topic metadata. I don't think we have a test client for that, the only other way would be to create actual topics like an integration test. Would that be considered acceptable? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
