deepthi912 commented on code in PR #16626: URL: https://github.com/apache/pinot/pull/16626#discussion_r2286572244
########## pinot-common/src/main/java/org/apache/pinot/common/config/provider/TableCacheQueryValidator.java: ########## @@ -0,0 +1,251 @@ +/** + * 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.config.provider; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import javax.annotation.Nullable; +import org.apache.pinot.common.request.Expression; +import org.apache.pinot.spi.config.provider.LogicalTableConfigChangeListener; +import org.apache.pinot.spi.config.provider.SchemaChangeListener; +import org.apache.pinot.spi.config.provider.TableConfigChangeListener; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.data.FieldSpec; +import org.apache.pinot.spi.data.LogicalTableConfig; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.utils.CommonConstants.Segment.BuiltInVirtualColumn; +import org.apache.pinot.spi.utils.TimestampIndexUtils; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A static implementation that works with pre-loaded table configs and schemas jsons. + * This is useful for validation scenarios where you want to test query compilation against a specific + * set of table configs and schemas without needing a live cluster. + */ +public class TableCacheQueryValidator implements TableCacheProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(TableCacheQueryValidator.class); + + + private final boolean _ignoreCase; + private final Map<String, TableConfig> _tableConfigMap = new HashMap<>(); + private final Map<String, Schema> _schemaMap = new HashMap<>(); + private final Map<String, LogicalTableConfig> _logicalTableConfigMap = new HashMap<>(); + private final Map<String, String> _tableNameMap = new HashMap<>(); + private final Map<String, String> _logicalTableNameMap = new HashMap<>(); + private final Map<String, Map<String, String>> _columnNameMaps = new HashMap<>(); + + public TableCacheQueryValidator(List<TableConfig> tableConfigs, List<Schema> schemas, boolean ignoreCase) { + this(tableConfigs, schemas, Collections.emptyList(), ignoreCase); + } + + public TableCacheQueryValidator(List<TableConfig> tableConfigs, List<Schema> schemas, + List<LogicalTableConfig> logicalTableConfigs, boolean ignoreCase) { + _ignoreCase = ignoreCase; + + for (TableConfig tableConfig : tableConfigs) { + String tableNameWithType = tableConfig.getTableName(); + String rawTableName = TableNameBuilder.extractRawTableName(tableNameWithType); + + _tableConfigMap.put(tableNameWithType, tableConfig); + + if (_ignoreCase) { + _tableNameMap.put(tableNameWithType.toLowerCase(), tableNameWithType); + _tableNameMap.put(rawTableName.toLowerCase(), rawTableName); + } else { + _tableNameMap.put(tableNameWithType, tableNameWithType); + _tableNameMap.put(rawTableName, rawTableName); + } + } + + // Initialize schemas + for (Schema schema : schemas) { + String schemaName = schema.getSchemaName(); + _schemaMap.put(schemaName, schema); + Map<String, String> columnNameMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); Review Comment: Hmm we don't need it, but added it to alphabetically order just similar to the one we have in `Schema` class - `_fieldSpecMap` -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
