RussellSpitzer commented on a change in pull request #1633: URL: https://github.com/apache/iceberg/pull/1633#discussion_r507898230
########## File path: aws/src/main/java/org/apache/iceberg/aws/glue/IcebergToGlueConverter.java ########## @@ -0,0 +1,66 @@ +/* + * 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.iceberg.aws.glue; + +import java.util.Map; +import java.util.regex.Pattern; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.exceptions.NoSuchNamespaceException; +import software.amazon.awssdk.services.glue.model.DatabaseInput; + +public class IcebergToGlueConverter { + + private IcebergToGlueConverter() { + } + + private static final Pattern GLUE_DB_PATTERN = Pattern.compile("^[a-z0-9_]{1,252}$"); + + + private static boolean isValidNamespace(Namespace namespace) { + if (namespace.levels().length != 1) { + return false; + } + String dbName = namespace.level(0); + return dbName != null && GLUE_DB_PATTERN.matcher(dbName).find(); + } + + /** + * A database name cannot be longer than 252 characters. + * The only acceptable characters are lowercase letters, numbers, and the underscore character. + * More details: https://docs.aws.amazon.com/athena/latest/ug/glue-best-practices.html + * @param namespace namespace + * @return if namespace can be accepted by Glue + * @throws NoSuchNamespaceException no such namespace + */ + public static String toDatabaseName(Namespace namespace) { + if (!isValidNamespace(namespace)) { + throw new NoSuchNamespaceException( + "Bad namespace name %s, must be 1-232 chars of lowercase letters, numbers, underscore", namespace); Review comment: Exception message pattern ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org