shounakmk219 commented on code in PR #12417: URL: https://github.com/apache/pinot/pull/12417#discussion_r1514117098
########## pinot-common/src/main/java/org/apache/pinot/common/utils/DatabaseUtils.java: ########## @@ -0,0 +1,86 @@ +/** + * 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.pinot.common.utils; + +import java.util.Objects; +import javax.annotation.Nullable; +import javax.ws.rs.core.HttpHeaders; +import org.apache.commons.lang3.StringUtils; +import org.apache.pinot.spi.utils.CommonConstants; + + +public class DatabaseUtils { + private DatabaseUtils() { + } + + /** + * Construct the fully qualified table name i.e. {databaseName}.{tableName} from given table name and database name + * @param tableName table/schema name + * @param databaseName database name + * @return translated table name. Throws {@link IllegalStateException} if {@code tableName} contains more than 1 dot + * or if {@code tableName} has database prefix, and it does not match with {@code databaseName} + */ + public static String translateTableName(String tableName, @Nullable String databaseName) { + if (tableName == null) { + throw new IllegalArgumentException("'tableName' cannot be null"); + } + String[] tableSplit = StringUtils.split(tableName, '.'); + switch (tableSplit.length) { + case 1: + // do not concat the database name prefix if it's a 'default' database + if (StringUtils.isNotEmpty(databaseName) && !databaseName.equalsIgnoreCase(CommonConstants.DEFAULT_DATABASE)) { Review Comment: We need a database to occupy the existing tables which don't have any database prefix that's why introducing this reserved `default` database for tables that don't have the database prefix. And to maintain consistency within the `default` database we are skipping the `default.` prefix on table names. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org