You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/03/13 18:00:11 UTC

[GitHub] [phoenix] priyankporwal commented on a change in pull request #733: PHOENIX-5732: Implement starttime, endtime in IndexTool for rebuild a…

priyankporwal commented on a change in pull request #733: PHOENIX-5732: Implement starttime, endtime in IndexTool for rebuild a…
URL: https://github.com/apache/phoenix/pull/733#discussion_r392377732
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolTimeRangeIT.java
 ##########
 @@ -0,0 +1,215 @@
+/*
+ * 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.end2end;
+
+import com.google.common.collect.Maps;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.EnvironmentEdge;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+
+public class IndexToolTimeRangeIT extends BaseUniqueNamesOwnClusterIT {
+    private static final String
+            CREATE_TABLE_DDL = "CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, "
+            + "VAL1 INTEGER, VAL2 INTEGER) COLUMN_ENCODED_BYTES=0";
+    public static final String CREATE_INDEX_DDL = "CREATE INDEX %s ON %s (VAL1) INCLUDE (VAL2)";
+    private static final String UPSERT_TABLE_DML = "UPSERT INTO %s VALUES(?,?,?)";
+
+    private static String dataTableFullName, indexTableFullName,
+            schemaName, dataTableName, indexTableName;
+    static CustomEnvironmentEdge customEdge = new CustomEnvironmentEdge();
+
+    @BeforeClass
+    public static synchronized void setup() throws Exception {
+        setupMiniCluster();
+        createTableAndIndex();
+        populateDataTable();
+    }
+
+    private static void createTableAndIndex() throws SQLException {
+        schemaName = generateUniqueName();
+        dataTableName = generateUniqueName();
+        dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        indexTableName = generateUniqueName();
+        indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        try (Connection conn = getConnection()) {
+            incrementEdgeByOne();
+            conn.createStatement().execute(String.format(CREATE_TABLE_DDL, dataTableFullName));
+            conn.commit();
+            incrementEdgeByOne();
+            conn.createStatement().execute(String.format(CREATE_INDEX_DDL, indexTableName,
+                    dataTableFullName));
+            conn.commit();
+        }
+    }
+
+    private static void incrementEdgeByOne() {
+        customEdge.incrementValue(1);
+        EnvironmentEdgeManager.injectEdge(customEdge);
+    }
+
+    private static void populateDataTable() throws SQLException {
+        try (Connection conn = getConnection()) {
+            //row 1-> time 4, row 2-> time 5, row 3-> time 6, row 4-> time 7, row 5-> time 8
+            for (int i=0; i<5; i++) {
+                incrementEdgeByOne();
+                PreparedStatement ps = conn.prepareStatement(
+                        String.format(UPSERT_TABLE_DML, dataTableFullName));
+                ps.setInt(1, i+1);
+                ps.setInt(2,(i+1)*10);
+                ps.setInt(3, (i+1)*100);
+                ps.execute();
+                conn.commit();
+            }
+        }
+    }
+
+    private static void setupMiniCluster() throws Exception {
+        Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(2);
+        serverProps.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
+        serverProps.put(QueryServices.MAX_SERVER_METADATA_CACHE_TIME_TO_LIVE_MS_ATTRIB,
+                Long.toString(5));
+        serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB,
+                QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
+        serverProps.put(QueryServices.INDEX_REBUILD_PAGE_SIZE_IN_ROWS, Long.toString(8));
+        Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(2);
+        clientProps.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, Boolean.toString(true));
+        clientProps.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
+        clientProps.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
+        clientProps.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.TRUE.toString());
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+    }
+
+    private int countRowsInIndex() throws SQLException {
+        incrementEdgeByOne();
+        String select = "SELECT COUNT(*) FROM "+indexTableFullName;
+        try(Connection conn = getConnection()) {
+            ResultSet rs = conn.createStatement().executeQuery(select);
+            while(rs.next()) {
+                return rs.getInt(1);
+            }
+        }
+        return -1;
+    }
+
+    private static Connection getConnection() throws SQLException {
+        return DriverManager.getConnection(getUrl(),
+                PropertiesUtil.deepCopy(TEST_PROPERTIES));
+    }
+
+    @Before
+    public void beforeTest() {
+        incrementEdgeByOne();
+    }
+
+    @Test
+    public void testValidTimeRange() throws Exception {
 
 Review comment:
   Nice set of tests @swaroopak! Is there an error-case test where starttime > endtime?

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


With regards,
Apache Git Services