You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by "virajjasani (via GitHub)" <gi...@apache.org> on 2023/05/18 19:25:15 UTC

[GitHub] [phoenix] virajjasani commented on a diff in pull request #1607: PHOENIX-6910 Scans created during query compilation and execution aga…

virajjasani commented on code in PR #1607:
URL: https://github.com/apache/phoenix/pull/1607#discussion_r1198190984


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableMergeBucketsIT.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.salted;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class SaltedTableMergeBucketsIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testQuery() throws Exception {
+        String tableName = generateUniqueName();
+
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.FALSE.toString());
+        Connection connection = DriverManager.getConnection(getUrl(), props);
+        Statement statement = connection.createStatement();
+        statement.execute("CREATE TABLE " + tableName
+                + " (c1 VARCHAR NOT NULL, c2 VARCHAR NOT NULL, c3 VARCHAR NOT NULL,"
+                + " CONSTRAINT pk PRIMARY KEY(c1,c2,c3)) SALT_BUCKETS=11");

Review Comment:
   can we also add one non-key column c4?



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableMergeBucketsIT.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.salted;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class SaltedTableMergeBucketsIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testQuery() throws Exception {
+        String tableName = generateUniqueName();
+
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.FALSE.toString());
+        Connection connection = DriverManager.getConnection(getUrl(), props);
+        Statement statement = connection.createStatement();
+        statement.execute("CREATE TABLE " + tableName
+                + " (c1 VARCHAR NOT NULL, c2 VARCHAR NOT NULL, c3 VARCHAR NOT NULL,"
+                + " CONSTRAINT pk PRIMARY KEY(c1,c2,c3)) SALT_BUCKETS=11");
+        statement.execute(
+            " upsert into " + tableName + " values('20191211','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191212','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191213','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191214','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191215','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191216','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191217','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191218','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191219','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191220','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191221','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191222','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191223','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191224','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191225','HORTONWORKS_WEEKLY_TEST','v3')");
+        connection.commit();
+
+        Admin admin =
+                driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
+        List<RegionInfo> regions = admin.getRegions(TableName.valueOf(tableName));
+        for (int i = 0; i < regions.size() - 1; i+=2) {
+            admin.mergeRegionsAsync(regions.get(i).getEncodedNameAsBytes(),
+                regions.get(i + 1).getEncodedNameAsBytes(), false).get();
+        }

Review Comment:
   nit:
   ```
           for (int i = 0; i < regions.size() - 1; i += 2) {
               byte[][] regionsToMerge = new byte[2][];
               regionsToMerge[0] = regions.get(i).getEncodedNameAsBytes();
               regionsToMerge[1] = regions.get(i + 1).getEncodedNameAsBytes();
               admin.mergeRegionsAsync(regionsToMerge, false).get();
           }
   ```



##########
phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java:
##########
@@ -1119,12 +1124,21 @@ private List<List<Scan>> getParallelScans(byte[] startKey, byte[] stopKey) throw
                 int gpsComparedToEndKey = -1;
                 boolean everNotDelayed = false;
                 while (intersectWithGuidePosts && (endKey.length == 0 || (gpsComparedToEndKey=currentGuidePost.compareTo(endKey)) <= 0)) {
-                    Scan newScan = scanRanges.intersectScan(scan, currentKeyBytes, currentGuidePostBytes, keyOffset,
-                        false);
-                    if (newScan != null) {
-                        ScanUtil.setLocalIndexAttributes(newScan, keyOffset,
-                            regionInfo.getStartKey(), regionInfo.getEndKey(),
-                            newScan.getStartRow(), newScan.getStopRow());
+                    List<Scan> newScans =
+                            scanRanges.intersectScan(scan, currentKeyBytes, currentGuidePostBytes,
+                                keyOffset, false, splitPostfix, getTable().getBucketNum());
+                    for (Scan newScan : newScans) {
+                        if (newScan != null) {
+                            ScanUtil.setLocalIndexAttributes(newScan, keyOffset,
+                                regionInfo.getStartKey(), regionInfo.getEndKey(),
+                                newScan.getStartRow(), newScan.getStopRow());
+                            //TODO why are we passing endKey instead of startKey here ?
+                            scans =
+                                    addNewScan(parallelScans, scans, newScan, currentGuidePostBytes,
+                                        false, regionLocation);

Review Comment:
   here `currentGuidePostBytes` could be less than `endKey` right?



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableMergeBucketsIT.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.salted;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class SaltedTableMergeBucketsIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testQuery() throws Exception {
+        String tableName = generateUniqueName();
+
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.FALSE.toString());
+        Connection connection = DriverManager.getConnection(getUrl(), props);
+        Statement statement = connection.createStatement();
+        statement.execute("CREATE TABLE " + tableName
+                + " (c1 VARCHAR NOT NULL, c2 VARCHAR NOT NULL, c3 VARCHAR NOT NULL,"
+                + " CONSTRAINT pk PRIMARY KEY(c1,c2,c3)) SALT_BUCKETS=11");
+        statement.execute(
+            " upsert into " + tableName + " values('20191211','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191212','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191213','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191214','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191215','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191216','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191217','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191218','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191219','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191220','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191221','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191222','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191223','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191224','HORTONWORKS_WEEKLY_TEST','v3')");
+        statement.execute(
+            " upsert into " + tableName + " values('20191225','HORTONWORKS_WEEKLY_TEST','v3')");
+        connection.commit();
+
+        Admin admin =
+                driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
+        List<RegionInfo> regions = admin.getRegions(TableName.valueOf(tableName));
+        for (int i = 0; i < regions.size() - 1; i+=2) {
+            admin.mergeRegionsAsync(regions.get(i).getEncodedNameAsBytes(),
+                regions.get(i + 1).getEncodedNameAsBytes(), false).get();
+        }
+        ResultSet rs =
+                statement.executeQuery("select c1,c2,c3 from " + tableName
+                        + " where c1='20191211' and c2 like '%HORTONWORKS_WEEKLY_TEST%'");
+        assertTrue(rs.next());
+        rs =
+                statement.executeQuery("select c1,c2,c3 from " + tableName
+                        + " where c1='20191217' and c2 like '%HORTONWORKS_WEEKLY_TEST%'");
+        assertTrue(rs.next());

Review Comment:
   For both, shall we also add `assertFalse(rs.next())`?



-- 
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: issues-unsubscribe@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org