kuczoram commented on code in PR #5192:
URL: https://github.com/apache/hive/pull/5192#discussion_r1601151186


##########
ql/src/test/org/apache/hadoop/hive/ql/txn/compactor/TestCompactionQueryBuilderForMmCompaction.java:
##########
@@ -0,0 +1,475 @@
+/*
+ * 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.txn.compactor;
+
+import org.apache.hadoop.hive.common.ValidCompactorWriteIdList;
+import org.apache.hadoop.hive.metastore.api.*;
+import org.apache.hadoop.hive.ql.io.AcidDirectory;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class TestCompactionQueryBuilderForMmCompaction extends 
CompactionQueryBuilderTest {
+
+  @Test
+  public void testMajorCompactionCreateWithoutSourceTable() {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    String query = queryBuilder.build();
+    String expectedQuery =
+        "CREATE temporary external table comp_test_result_table TBLPROPERTIES 
('transactional'='false')";
+    Assert.assertEquals(expectedQuery, query);
+  }
+
+  @Test
+  public void testMajorCompactionCreateWithTablePropertiesWithLocation() {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    Table sourceTable = createSourceTableWithProperties();
+    queryBuilder.setSourceTab(sourceTable);
+    queryBuilder.setLocation(SOME_TEST_LOCATION);
+    String query = queryBuilder.build();
+    String expectedQuery =
+        "CREATE temporary external table comp_test_result_table(`column_1` 
string,`column_2` int,`column_3` boolean)  LOCATION 'some_test_path' 
TBLPROPERTIES ('property_1'='true', 'orc.property_2'='44', 
'transactional'='false')";
+    Assert.assertEquals(expectedQuery, query);
+  }
+
+  @Test
+  public void testMajorCompactionCreatePartitioned() {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    Table sourceTable = createSourceTable();
+    queryBuilder.setSourceTab(sourceTable);
+    queryBuilder.setPartitioned(true);
+    queryBuilder.setLocation(SOME_TEST_LOCATION);
+    String query = queryBuilder.build();
+    String expectedQuery =
+        "CREATE temporary external table comp_test_result_table(`column_1` 
string,`column_2` int,`column_3` boolean)  PARTITIONED BY (`file_name` STRING)  
LOCATION 'some_test_path' TBLPROPERTIES ('transactional'='false')";
+    Assert.assertEquals(expectedQuery, query);
+  }
+
+  @Test
+  public void testMajorCompactionCreateWithBucketedSourceTable() throws 
HiveException {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    Table sourceTable = createSourceTableBucketed();
+    queryBuilder.setSourceTab(sourceTable);
+    String query = queryBuilder.build();
+    String expectedQuery =
+        "CREATE temporary external table comp_test_result_table(`column_1` 
string,`column_2` int,`column_3` boolean) CLUSTERED BY (column_1,column_3) INTO 
4 BUCKETS TBLPROPERTIES ('transactional'='false')";
+    Assert.assertEquals(expectedQuery, query);
+  }
+
+  @Test
+  public void testMajorCompactionCreateWithBucketedSortedSourceTable() throws 
HiveException {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    Table sourceTable = createSourceTableBucketedSorted();
+    queryBuilder.setSourceTab(sourceTable);
+    String query = queryBuilder.build();
+    String expectedQuery =
+        "CREATE temporary external table comp_test_result_table(`column_1` 
string,`column_2` int,`column_3` boolean) CLUSTERED BY (column_1,column_3) 
SORTED BY (column_1 DESC, column_2 ASC) INTO 4 BUCKETS TBLPROPERTIES 
('transactional'='false')";
+    Assert.assertEquals(expectedQuery, query);
+  }
+
+  @Test
+  public void testMajorCompactionCreateWithStorageDescriptor() throws 
HiveException {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    Table sourceTable = createSourceTable();
+    queryBuilder.setSourceTab(sourceTable);
+    StorageDescriptor storageDescriptor = createStorageDescriptor();
+    queryBuilder.setStorageDescriptor(storageDescriptor);
+    String query = queryBuilder.build();
+    String expectedQuery =
+        "CREATE temporary external table comp_test_result_table(`column_1` 
string,`column_2` int,`column_3` boolean)  ROW FORMAT SERDE 
'/some/test/serialization_lib'WITH SERDEPROPERTIES ( \n" + "  
'test_param_1'='test_value', \n" + "  'test_param_2'='test_value')STORED AS 
INPUTFORMAT 'some.test.InputFormat' OUTPUTFORMAT 'some.test.OutputFormat' 
TBLPROPERTIES ('transactional'='false')";
+    Assert.assertEquals(expectedQuery, query);
+  }
+
+  @Test
+  public void testMajorCompactionCreateWithSkewedByClause() throws 
HiveException {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    Table sourceTable = createSourceTable();
+    StorageDescriptor storageDescriptor = sourceTable.getSd();
+    SkewedInfo skewedInfo = new SkewedInfo();
+    skewedInfo.addToSkewedColNames("column_1");
+    List<String> skewedColValues = new ArrayList<>();
+    skewedColValues.add("value1");
+    skewedColValues.add("value2");
+    skewedColValues.add("value3");
+    skewedInfo.addToSkewedColValues(skewedColValues);
+    storageDescriptor.setSkewedInfo(skewedInfo);
+    storageDescriptor.setStoredAsSubDirectories(true);
+    sourceTable.setSd(storageDescriptor);
+    queryBuilder.setSourceTab(sourceTable);
+    String query = queryBuilder.build();
+    String expectedQuery =
+        "CREATE temporary external table comp_test_result_table(`column_1` 
string,`column_2` int,`column_3` boolean)  SKEWED BY (column_1) ON 
('value1','value2','value3')) STORED AS DIRECTORIES TBLPROPERTIES 
('transactional'='false')";
+    Assert.assertEquals(expectedQuery, query);
+  }
+
+  @Test
+  public void testMajorCompactionCreateWithNonNativeTable() throws 
HiveException {
+    CompactionQueryBuilder queryBuilder = 
getMmMajorCompactionQueryBuilderForCreate();
+    Table sourceTable = createSourceTable();
+    Map<String, String> parameters = new HashMap<>();
+    parameters.put("storage_handler", "test_storage_handler");
+    sourceTable.setParameters(parameters);
+    queryBuilder.setSourceTab(sourceTable);
+    StorageDescriptor storageDescriptor = createStorageDescriptor();
+    queryBuilder.setStorageDescriptor(storageDescriptor);
+    Exception exception = assertThrows(RuntimeException.class, () -> {
+      queryBuilder.build();
+    });

Review Comment:
   Thanks for the hint, I replaced these.



-- 
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: gitbox-unsubscr...@hive.apache.org

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

Reply via email to