ayushtkn commented on code in PR #4155:
URL: https://github.com/apache/hive/pull/4155#discussion_r1169807803


##########
ql/src/test/queries/clientnegative/alter_external_acid.q:
##########
@@ -4,6 +4,6 @@ set 
hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
 
 create external table acid_external (a int, b varchar(128)) clustered by (b) 
into 2 buckets stored as orc;
 
-alter table acid_external set TBLPROPERTIES ('transactional'='true');
+alter table acid_external convert to Acid;

Review Comment:
   Modified a insert-only q test, to have this covered, added explain for it as 
well



##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/convert/AlterTableConvertOperation.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.ddl.table.convert;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.hadoop.hive.ql.ddl.DDLOperationContext;
+import org.apache.hadoop.hive.ql.ddl.table.AbstractAlterTableOperation;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Partition;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+import java.util.Map;
+
+import static 
org.apache.hadoop.hive.metastore.TransactionalValidationListener.DEFAULT_TRANSACTIONAL_PROPERTY;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_IS_TRANSACTIONAL;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES;
+
+/**
+ * Operation process of ALTER TABLE ... CONVERT command
+ */
+public class AlterTableConvertOperation extends 
AbstractAlterTableOperation<AlterTableConvertDesc> {
+
+  private enum ConversionFormats {
+    ICEBERG(ImmutableMap.of(META_TABLE_STORAGE, 
"org.apache.iceberg.mr.hive.HiveIcebergStorageHandler")),
+    ACID(ImmutableMap.of(TABLE_IS_TRANSACTIONAL, "true", 
TABLE_TRANSACTIONAL_PROPERTIES,
+        DEFAULT_TRANSACTIONAL_PROPERTY));
+
+    private final Map<String, String> properties;
+
+    ConversionFormats(Map<String, String> properties) {
+      this.properties = properties;
+    }
+
+
+    public Map<String, String> properties() {
+      return properties;
+    }
+  }
+
+  public AlterTableConvertOperation(DDLOperationContext context, 
AlterTableConvertDesc desc) {
+    super(context, desc);
+  }
+
+  @Override
+  protected void doAlteration(Table table, Partition partition) throws 
HiveException {
+    // Add the covert type
+    String convertType = desc.getConvertSpec().getTargetType();
+    ConversionFormats format = 
ConversionFormats.valueOf(convertType.toUpperCase());

Review Comment:
   if the enum doesn't have that type, it will throw us out over here.



##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/convert/AlterTableConvertOperation.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.ddl.table.convert;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.hadoop.hive.ql.ddl.DDLOperationContext;
+import org.apache.hadoop.hive.ql.ddl.table.AbstractAlterTableOperation;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Partition;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+import java.util.Map;
+
+import static 
org.apache.hadoop.hive.metastore.TransactionalValidationListener.DEFAULT_TRANSACTIONAL_PROPERTY;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_IS_TRANSACTIONAL;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES;
+
+/**
+ * Operation process of ALTER TABLE ... CONVERT command
+ */
+public class AlterTableConvertOperation extends 
AbstractAlterTableOperation<AlterTableConvertDesc> {
+
+  private enum ConversionFormats {
+    ICEBERG(ImmutableMap.of(META_TABLE_STORAGE, 
"org.apache.iceberg.mr.hive.HiveIcebergStorageHandler")),
+    ACID(ImmutableMap.of(TABLE_IS_TRANSACTIONAL, "true", 
TABLE_TRANSACTIONAL_PROPERTIES,
+        DEFAULT_TRANSACTIONAL_PROPERTY));

Review Comment:
   yes, added a test(modified existing)



##########
iceberg/iceberg-handler/src/test/queries/negative/alter_acid_table_to_iceberg_failure.q:
##########
@@ -3,4 +3,4 @@ set 
hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
 
 drop table tbl_orc;
 create table tbl_orc (a int, b string) stored as orc 
tblproperties('transactional'='true');
-alter table tbl_orc set tblproperties 
('storage_handler'='org.apache.iceberg.mr.hive.HiveIcebergStorageHandler');
\ No newline at end of file
+alter table tbl_orc convert to iceberg;

Review Comment:
   The TBLPROPERTIES stuff is there in the ``TestHiveIcebergMigration``, and 
all other validation cases as well. I changed to use our covert stuff. Creating 
new table as we discussed offline doesn't look feasible and is more or less 
like a copy



##########
iceberg/iceberg-handler/src/test/results/positive/llap/llap_iceberg_read_orc.q.out:
##########
@@ -422,12 +422,12 @@ POSTHOOK: type: ALTERTABLE_ADDCOLS
 POSTHOOK: Input: default@llap_orders
 POSTHOOK: Output: default@llap_orders
 PREHOOK: query: INSERT INTO llap_orders VALUES
-(22, 99, 9, 'EU', 'DE', timestamp('2021-01-04 19:55:46.129'), 'München')
+(22, 99, 9, 'EU', 'DE', timestamp('2021-01-04 19:55:46.129'), 'M��nchen')

Review Comment:
   yahh, It got messed up while I tried to regenerate the q file :(, tried to 
revert such line manually 



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

Reply via email to