[ 
https://issues.apache.org/jira/browse/HIVE-25034?focusedWorklogId=599164&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-599164
 ]

ASF GitHub Bot logged work on HIVE-25034:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/May/21 11:55
            Start Date: 19/May/21 11:55
    Worklog Time Spent: 10m 
      Work Description: marton-bod commented on a change in pull request #2243:
URL: https://github.com/apache/hive/pull/2243#discussion_r635167120



##########
File path: 
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergCTASHook.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.mr.hive;
+
+import java.util.Properties;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.hooks.QueryLifeTimeHook;
+import org.apache.hadoop.hive.ql.hooks.QueryLifeTimeHookContext;
+import org.apache.iceberg.mr.Catalogs;
+import org.apache.iceberg.mr.InputFormatConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HiveIcebergCTASHook implements QueryLifeTimeHook {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(HiveIcebergCTASHook.class);
+
+  @Override
+  public void beforeCompile(QueryLifeTimeHookContext ctx) {
+
+  }
+
+  @Override
+  public void afterCompile(QueryLifeTimeHookContext ctx, boolean hasError) {
+    if (hasError) {
+      checkAndRollbackIcebergCTAS(ctx);
+    }
+  }
+
+  @Override
+  public void beforeExecution(QueryLifeTimeHookContext ctx) {
+
+  }
+
+  @Override
+  public void afterExecution(QueryLifeTimeHookContext ctx, boolean hasError) {
+    if (hasError) {
+      checkAndRollbackIcebergCTAS(ctx);
+    }
+  }
+
+  private void checkAndRollbackIcebergCTAS(QueryLifeTimeHookContext ctx) {
+    HiveConf conf = ctx.getHiveConf();
+    String queryId = conf.getVar(HiveConf.ConfVars.HIVEQUERYID);
+    if 
(conf.getBoolean(String.format(InputFormatConfig.IS_CTAS_QUERY_TEMPLATE, 
queryId), false)) {
+      try {
+        String tableName = 
conf.get(String.format(InputFormatConfig.CTAS_TABLE_NAME_TEMPLATE, queryId));
+        LOG.info("Dropping the following CTAS target table as part of 
rollback: {}", tableName);
+        Properties props = new Properties();
+        props.put(Catalogs.NAME, tableName);
+        Catalogs.dropTable(conf, props);

Review comment:
       Good point. As discussed, the table properties of the target table 
should contain the catalog_name (and the corresponding fields such as type), so 
we should drop the table from the correct catalog.




-- 
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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 599164)
    Time Spent: 4h  (was: 3h 50m)

> Implement CTAS for Iceberg
> --------------------------
>
>                 Key: HIVE-25034
>                 URL: https://issues.apache.org/jira/browse/HIVE-25034
>             Project: Hive
>          Issue Type: New Feature
>            Reporter: Marton Bod
>            Assignee: Marton Bod
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 4h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to