You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/06/01 19:18:32 UTC

[GitHub] [hive] vihangk1 commented on a change in pull request #2336: HIVE-24987: Introduce a exception list to skip incompatible column change check

vihangk1 commented on a change in pull request #2336:
URL: https://github.com/apache/hive/pull/2336#discussion_r643416465



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/DefaultIncompatibleTableChangeHandler.java
##########
@@ -0,0 +1,116 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.metastore;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default incompatible table change handler. This is invoked by the {@link
+ * HiveAlterHandler} when a table is altered to check if the column type changes if any
+ * are allowed or not.
+ */
+public class DefaultIncompatibleTableChangeHandler implements
+    IMetaStoreIncompatibleChangeHandler {
+
+  private static final Logger LOG = LoggerFactory
+      .getLogger(DefaultIncompatibleTableChangeHandler.class);
+  private static final DefaultIncompatibleTableChangeHandler INSTANCE =
+      new DefaultIncompatibleTableChangeHandler();
+
+  private DefaultIncompatibleTableChangeHandler() {
+  }
+
+  public static DefaultIncompatibleTableChangeHandler get() {
+    return INSTANCE;
+  }
+
+  /**
+   * Checks if the column type changes in the oldTable and newTable are allowed or not. In
+   * addition to checking if the incompatible changes are allowed or not, this also checks
+   * if the table serde library belongs to a list of table serdes which support making any
+   * column type changes.
+   *
+   * @param conf     The configuration which if incompatible col type changes are allowed
+   *                 or not.
+   * @param oldTable The instance of the table being altered.
+   * @param newTable The new instance of the table which represents the altered state of
+   *                 the table.
+   * @throws InvalidOperationException
+   */
+  @Override
+  public void allowChange(Configuration conf, Table oldTable, Table newTable)
+      throws InvalidOperationException {
+    if (!MetastoreConf.getBoolVar(conf,
+        MetastoreConf.ConfVars.DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES)) {
+      // incompatible column changes are allowed for all
+      return;
+    }
+    if (oldTable.getTableType().equals(TableType.VIRTUAL_VIEW.toString())) {
+      // Views derive the column type from the base table definition. So the view
+      // definition can be altered to change the column types. The column type
+      // compatibility checks should be done only for non-views.
+      return;
+    }
+    checkColTypeChangeCompatible(conf, oldTable, newTable);
+  }
+
+  private void checkColTypeChangeCompatible(Configuration conf, Table oldTable,

Review comment:
       Yes, agreed. This was left here because of git conflicts. Thanks for spotting that.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org