kasakrisz commented on a change in pull request #1561: URL: https://github.com/apache/hive/pull/1561#discussion_r504609534
########## File path: ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java ########## @@ -1871,6 +1876,17 @@ public RelNode apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlu } perfLogger.perfLogEnd(this.getClass().getName(), PerfLogger.OPTIMIZER, "Calcite: Plan generation"); + if (conf.getBoolVar(ConfVars.HIVE_MATERIALIZED_VIEW_ENABLE_AUTO_REWRITING_BY_QUERY_TEXT) && + !getQB().isMaterializedView() && !ctx.isLoadingMaterializedView() && !getQB().isCTAS() && + getQB().hasTableDefined()) { + unparseTranslator.applyTranslations(ctx.getTokenRewriteStream()); + String expandedQueryText = ctx.getTokenRewriteStream().toString(ast.getTokenStartIndex(), ast.getTokenStopIndex()); + RelOptMaterialization relOptMaterialization = db.getMaterialization(expandedQueryText); Review comment: I rewrote this: - `MaterializedViewCahce` stores all materializations for each query text - lookup returns with a list of materializations for a given query text or empty list if none exists. - iterate through all materializations and return with the first one where `validateMaterializedViewsFromRegistry` returns true ########## File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/MaterializedViews.java ########## @@ -0,0 +1,149 @@ +/* + * 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.hadoop.hive.ql.metadata; + +import org.apache.calcite.plan.RelOptMaterialization; +import org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveMaterializedViewUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +public class MaterializedViews { + private static final Logger LOG = LoggerFactory.getLogger(MaterializedViews.class); + + /* Key is the database name. Value a map from the qualified name to the view object. */ + private final ConcurrentMap<String, ConcurrentMap<String, RelOptMaterialization>> materializedViews = + new ConcurrentHashMap<>(); + // Map for looking up materialization by view query text + private final Map<String, RelOptMaterialization> sqlToMaterializedView = new ConcurrentHashMap<>(); Review comment: done ---------------------------------------------------------------- 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: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org