FranMorilloAWS commented on code in PR #191: URL: https://github.com/apache/flink-connector-aws/pull/191#discussion_r2049063624
########## flink-catalog-aws-glue/src/main/java/org/apache/flink/table/catalog/glue/operations/GlueTableOperations.java: ########## @@ -0,0 +1,208 @@ +/* + * 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.flink.table.catalog.glue.operations; + +import org.apache.flink.table.catalog.CatalogTable; +import org.apache.flink.table.catalog.ObjectPath; +import org.apache.flink.table.catalog.exceptions.CatalogException; +import org.apache.flink.table.catalog.exceptions.TableNotExistException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.glue.GlueClient; +import software.amazon.awssdk.services.glue.model.*; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * Handles all table-related operations for the Glue catalog. + * Provides functionality for checking existence, listing, creating, getting, and dropping tables in AWS Glue. + */ +public class GlueTableOperations extends AbstractGlueOperations { + + /** + * Logger for logging table operations. + */ + private static final Logger LOG = LoggerFactory.getLogger(GlueTableOperations.class); + + /** + * Constructor for GlueTableOperations. + * Initializes the Glue client and catalog name. + * + * @param glueClient The Glue client to interact with AWS Glue. + * @param catalogName The name of the catalog. + */ + public GlueTableOperations(GlueClient glueClient, String catalogName) { + super(glueClient, catalogName); + } + + /** + * Checks whether a table exists in the Glue catalog. + * + * @param databaseName The name of the database where the table should exist. + * @param tableName The name of the table to check. + * @return true if the table exists, false otherwise. + */ + public boolean glueTableExists(String databaseName, String tableName) { + try { + glueClient.getTable(builder -> builder.databaseName(databaseName).name(tableName)); + return true; + } catch (EntityNotFoundException e) { + return false; + } catch (InvalidInputException | OperationTimeoutException | ResourceNumberLimitExceededException e) { + throw new CatalogException("Error checking table existence: " + databaseName + "." + tableName, e); + } catch (GlueException e) { + throw new CatalogException("Error checking table existence: " + databaseName + "." + tableName, e); + } + } + + /** + * Lists all tables in a given database. + * + * @param databaseName The name of the database from which to list tables. + * @return A list of table names. + * @throws CatalogException if there is an error fetching the table list. + */ + public List<String> listTables(String databaseName) { + try { + GetTablesRequest request = GetTablesRequest.builder() + .databaseName(databaseName) + .build(); + GetTablesResponse response = glueClient.getTables(request); + return response.tableList().stream() + .map(Table::name) + .collect(Collectors.toList()); + } catch (InvalidInputException e) { Review Comment: Implemented! -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org