You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2022/10/04 06:02:04 UTC
[phoenix] branch 5.1 updated: PHOENIX-5894 Table versus Table Full Outer join on Salted tables not … (#1395)
This is an automated email from the ASF dual-hosted git repository.
stoty pushed a commit to branch 5.1
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.1 by this push:
new 8f0bade551 PHOENIX-5894 Table versus Table Full Outer join on Salted tables not … (#1395)
8f0bade551 is described below
commit 8f0bade5518f188b296073c8917a0b4a2846c877
Author: Rajeshbabu Chintaguntla <ch...@gmail.com>
AuthorDate: Thu Feb 17 11:43:34 2022 +0530
PHOENIX-5894 Table versus Table Full Outer join on Salted tables not … (#1395)
PHOENIX-5894 Table versus Table Full Outer join on Salted tables not working
Co-authored-by: Rajeshbabu Chintaguntla <ra...@apache.org>
---
.../phoenix/end2end/join/HashJoinMoreIT.java | 55 ++++++++++++++++++++--
.../org/apache/phoenix/compile/JoinCompiler.java | 12 +++--
2 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index ace4025b2d..226e0e3ae1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -21,21 +21,18 @@ import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNull;
import java.sql.Array;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
-import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.Properties;
-import org.apache.phoenix.compile.QueryPlan;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
import org.apache.phoenix.end2end.ParallelStatsDisabledTest;
-import org.apache.phoenix.execute.HashJoinPlan;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.TestUtil;
@@ -437,6 +434,56 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testFullJoinOnSaltedTables() throws Exception {
+ String tempTable1 = generateUniqueName();
+ String tempTable2 = generateUniqueName();
+
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ try {
+ conn.createStatement().execute("CREATE TABLE "+ tempTable1 + "(" +
+ " PRODUCT_ID VARCHAR NOT NULL," +
+ " PRODUCT_NAME VARCHAR NOT NULL," +
+ " SUPPLIER_ID VARCHAR," +
+ " CATEGORY_ID VARCHAR," +
+ " CONSTRAINT PRODUCTS_NEW_PK PRIMARY KEY (PRODUCT_ID,PRODUCT_NAME)) " +
+ " DEFAULT_COLUMN_FAMILY='CF',COLUMN_ENCODED_BYTES=1, SALT_BUCKETS = 2");
+ conn.createStatement().execute("CREATE TABLE "+ tempTable2+" (" +
+ " ORDER_ID VARCHAR NOT NULL," +
+ " PRODUCT_ID VARCHAR NOT NULL," +
+ " UNIT_PRICE VARCHAR," +
+ " CONSTRAINT ORDER_DETAILS_NEW_PK PRIMARY KEY (ORDER_ID,PRODUCT_ID))" +
+ " DEFAULT_COLUMN_FAMILY='CF',COLUMN_ENCODED_BYTES=1, SALT_BUCKETS = 2");
+ Statement statement = conn.createStatement();
+ statement.execute("UPSERT INTO "+tempTable1+" values ( '1', 'Chai', '8', '1')");
+ statement.execute("UPSERT INTO "+tempTable1+" values ( '11', 'Queso Cabrales', '5', '4')");
+ statement.execute("UPSERT INTO "+tempTable2+" values ( '10248', '11', '14')");
+ statement.execute("UPSERT INTO "+tempTable2+" values ( '10248', '42', '9.8')");
+ statement.execute("UPSERT INTO "+tempTable2+" values ( '10249', '14', '18.6')");
+ conn.commit();
+ ResultSet rs = statement.executeQuery("SELECT PROD.PRODUCT_ID, OD.ORDER_ID" +
+ " FROM "+tempTable1+" PROD" +
+ " FULL OUTER JOIN "+ tempTable2+" OD ON PROD.PRODUCT_ID=OD.PRODUCT_ID" +
+ " ORDER BY PROD.PRODUCT_ID");
+ assertTrue(rs.next());
+ assertEquals("1", rs.getString(1));
+ assertNull(rs.getString(2));
+ assertTrue(rs.next());
+ assertEquals("11",rs.getString(1));
+ assertEquals(rs.getString(2), "10248");
+ assertTrue(rs.next());
+ assertNull(rs.getString(1));
+ assertEquals(rs.getString(2), "10249");
+ assertTrue(rs.next());
+ assertNull(rs.getString(1));
+ assertEquals(rs.getString(2), "10248");
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
@Test
public void testSubqueryWithoutData() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index 543a391ad0..63bf078b5d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1527,15 +1527,20 @@ public class JoinCompiler {
Preconditions.checkArgument(left.getType() == PTableType.PROJECTED);
Preconditions.checkArgument(right.getType() == PTableType.PROJECTED);
List<PColumn> merged = Lists.<PColumn> newArrayList();
+ int startingPosition = left.getBucketNum() == null ? 0 : 1;
if (type == JoinType.Full) {
- for (PColumn c : left.getColumns()) {
+ for (int i = startingPosition; i < left.getColumns().size(); i++) {
+ PColumn c = left.getColumns().get(i);
merged.add(new ProjectedColumn(c.getName(), c.getFamilyName(),
c.getPosition(), true, ((ProjectedColumn) c).getSourceColumnRef(), SchemaUtil.isPKColumn(c) ? null : c.getName().getBytes()));
}
} else {
merged.addAll(left.getColumns());
+ if (left.getBucketNum() != null) {
+ merged.remove(0);
+ }
}
- int position = merged.size();
+ int position = merged.size() + startingPosition;
for (PColumn c : right.getColumns()) {
if (!SchemaUtil.isPKColumn(c)) {
PColumn column = new ProjectedColumn(c.getName(), c.getFamilyName(),
@@ -1544,9 +1549,6 @@ public class JoinCompiler {
merged.add(column);
}
}
- if (left.getBucketNum() != null) {
- merged.remove(0);
- }
return new PTableImpl.Builder()
.setType(left.getType())
.setState(left.getIndexState())