swaroopak commented on a change in pull request #728: PHOENIX-5765 Add unit 
test for PrepareIndexMutationsForRebuild
URL: https://github.com/apache/phoenix/pull/728#discussion_r394550717
 
 

 ##########
 File path: 
phoenix-core/src/test/java/org/apache/phoenix/index/PrepareIndexMutationsForRebuildTest.java
 ##########
 @@ -0,0 +1,732 @@
+/*
+ * 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.phoenix.index;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.IndexRebuildRegionScanner;
+import org.apache.phoenix.hbase.index.IndexRegionObserver;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.BaseConnectionlessQueryTest;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTableKey;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class PrepareIndexMutationsForRebuildTest extends 
BaseConnectionlessQueryTest {
+    private static String ROW_KEY = "k1";
+    private static String TABLE_NAME = "dataTable";
+    private static String INDEX_NAME = "idx";
+
+    class SetupInfo {
+        public IndexMaintainer indexMaintainer;
+        public PTable pDataTable;
+    }
+
+    /**
+     * Get the index maintainer and phoenix table definition of data table.
+     * @param tableName
+     * @param indexName
+     * @param columns
+     * @param indexColumns
+     * @param pk
+     * @param includeColumns
+     * @return
+     * @throws Exception
+     */
+    private SetupInfo setup(String tableName,
+                            String indexName,
+                            String columns,
+                            String indexColumns,
+                            String pk,
+                            String includeColumns) throws Exception {
+        try(Connection conn = DriverManager.getConnection(getUrl())) {
+
+            String fullTableName = 
SchemaUtil.getTableName(SchemaUtil.normalizeIdentifier(""), 
SchemaUtil.normalizeIdentifier(tableName));
+            String fullIndexName = 
SchemaUtil.getTableName(SchemaUtil.normalizeIdentifier(""), 
SchemaUtil.normalizeIdentifier(indexName));
+
+            // construct the data table and index based from the parameters
+            String str1 = String.format("CREATE TABLE %1$s (%2$s CONSTRAINT pk 
PRIMARY KEY (%3$s)) COLUMN_ENCODED_BYTES=0",
+                    fullTableName,
+                    columns,
+                    pk);
+            conn.createStatement().execute(str1);
+
+            String str2 = String.format("CREATE INDEX %1$s ON %2$s (%3$s)",
+                    fullIndexName,
+                    fullTableName,
+                    indexColumns);
+            if (!includeColumns.isEmpty())
+                str2 += " INCLUDE (" + includeColumns + ")";
 
 Review comment:
   why not use string buffer instead?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to