phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anoopsamj...@apache.org
Subject git commit: PHOENIX-1102 Query Finds No Rows When Using Multiple Column Families in where clause. (Anoop)
Date Tue, 22 Jul 2014 17:19:29 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master e5869b57b -> 545abe535


PHOENIX-1102 Query Finds No Rows When Using Multiple Column Families in where clause. (Anoop)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/545abe53
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/545abe53
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/545abe53

Branch: refs/heads/master
Commit: 545abe5357a6e1a5d61d9d5516dca463893b6f6b
Parents: e5869b5
Author: anoopsjohn <anoopsamjohn@gmail.com>
Authored: Tue Jul 22 22:48:50 2014 +0530
Committer: anoopsjohn <anoopsamjohn@gmail.com>
Committed: Tue Jul 22 22:48:50 2014 +0530

----------------------------------------------------------------------
 .../end2end/ColumnProjectionOptimizationIT.java | 16 +++++++++
 .../MultiCFCQKeyValueComparisonFilter.java      | 19 +----------
 .../filter/MultiCQKeyValueComparisonFilter.java | 19 ++++-------
 .../filter/MultiKeyValueComparisonFilter.java   | 11 +++++++
 .../java/org/apache/phoenix/query/BaseTest.java | 34 ++++++++++++++++++--
 5 files changed, 66 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/545abe53/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
index 6fe7aec..ccdc7b7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
@@ -37,6 +37,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
@@ -307,4 +308,19 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT
{
             admin.close();
         }
     }
+
+    @Test
+    public void testSelectWithConditionOnMultiCF() throws Exception {
+        initMultiCFTable(getUrl());
+        Connection conn = DriverManager.getConnection(getUrl());
+        String query = "SELECT c.db_cpu_utilization FROM MULTI_CF WHERE a.unique_user_count
= ? and b.unique_org_count = ?";
+        PreparedStatement statement = conn.prepareStatement(query);
+        statement.setInt(1, 1);
+        statement.setInt(2, 1);
+        ResultSet rs = statement.executeQuery();
+        boolean b = rs.next();
+        assertTrue(b);
+        assertEquals(BigDecimal.valueOf(40.1), rs.getBigDecimal(1));
+        assertFalse(rs.next());
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/545abe53/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCFCQKeyValueComparisonFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCFCQKeyValueComparisonFilter.java
b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCFCQKeyValueComparisonFilter.java
index 71aff46..9147f1a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCFCQKeyValueComparisonFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCFCQKeyValueComparisonFilter.java
@@ -18,12 +18,10 @@
 package org.apache.phoenix.filter;
 
 import java.io.IOException;
-import java.util.TreeSet;
 
 import org.apache.hadoop.hbase.exceptions.DeserializationException;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Writables;
-
 import org.apache.phoenix.expression.Expression;
 
 
@@ -31,13 +29,12 @@ import org.apache.phoenix.expression.Expression;
  *
  * Filter that evaluates WHERE clause expression, used in the case where there
  * are references to multiple column qualifiers over multiple column families.
- *
+ * Also there same qualifier names in different families.
  * 
  * @since 0.1
  */
 public class MultiCFCQKeyValueComparisonFilter extends MultiKeyValueComparisonFilter {
     private final ImmutablePairBytesPtr ptr = new ImmutablePairBytesPtr();
-    private TreeSet<byte[]> cfSet;
 
     public MultiCFCQKeyValueComparisonFilter() {
     }
@@ -47,12 +44,6 @@ public class MultiCFCQKeyValueComparisonFilter extends MultiKeyValueComparisonFi
     }
 
     @Override
-    protected void init() {
-        cfSet = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
-        super.init();
-    }
-
-    @Override
     protected Object setColumnKey(byte[] cf, int cfOffset, int cfLength,
             byte[] cq, int cqOffset, int cqLength) {
         ptr.set(cf, cfOffset, cfLength, cq, cqOffset, cqLength);
@@ -125,14 +116,6 @@ public class MultiCFCQKeyValueComparisonFilter extends MultiKeyValueComparisonFi
         }
     }
 
-
-    @SuppressWarnings("all") // suppressing missing @Override since this doesn't exist for
HBase 0.94.4
-    public boolean isFamilyEssential(byte[] name) {
-        // Only the column families involved in the expression are essential.
-        // The others are for columns projected in the select expression.
-        return cfSet.contains(name);
-    }
-    
     public static MultiCFCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws
DeserializationException {
         try {
             return (MultiCFCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new
MultiCFCQKeyValueComparisonFilter());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/545abe53/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCQKeyValueComparisonFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCQKeyValueComparisonFilter.java
b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCQKeyValueComparisonFilter.java
index 2962c62..5fa5035 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCQKeyValueComparisonFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiCQKeyValueComparisonFilter.java
@@ -20,23 +20,20 @@ package org.apache.phoenix.filter;
 import java.io.IOException;
 
 import org.apache.hadoop.hbase.exceptions.DeserializationException;
-import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Writables;
-
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 
 /**
  *
  * Filter that evaluates WHERE clause expression, used in the case where there
- * are references to multiple column qualifiers over a single column family.
+ * are references to multiple unique column qualifiers over one or more column families.
  *
  * 
  * @since 0.1
  */
 public class MultiCQKeyValueComparisonFilter extends MultiKeyValueComparisonFilter {
     private ImmutableBytesPtr ptr = new ImmutableBytesPtr();
-    private byte[] cf;
 
     public MultiCQKeyValueComparisonFilter() {
     }
@@ -55,21 +52,17 @@ public class MultiCQKeyValueComparisonFilter extends MultiKeyValueComparisonFilt
     @Override
     protected Object newColumnKey(byte[] cf, int cfOffset, int cfLength, byte[] cq, int cqOffset,
             int cqLength) {
+        byte[] cfKey;
         if (cfOffset == 0 && cf.length == cfLength) {
-            this.cf = cf;
+            cfKey = cf;
         } else {
-            this.cf = new byte[cfLength];
-            System.arraycopy(cf, cfOffset, this.cf, 0, cfLength);
+            cfKey = new byte[cfLength];
+            System.arraycopy(cf, cfOffset, cfKey, 0, cfLength);
         }
+        cfSet.add(cfKey);
         return new ImmutableBytesPtr(cq, cqOffset, cqLength);
     }
 
-
-    @SuppressWarnings("all") // suppressing missing @Override since this doesn't exist for
HBase 0.94.4
-    public boolean isFamilyEssential(byte[] name) {
-        return Bytes.compareTo(cf, name) == 0;
-    }
-    
     public static MultiCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws
DeserializationException {
         try {
             return (MultiCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new MultiCQKeyValueComparisonFilter());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/545abe53/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
index 989cc5a..7df3b27 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
@@ -21,6 +21,7 @@ import java.io.DataInput;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.TreeSet;
 
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.KeyValue;
@@ -47,6 +48,7 @@ public abstract class MultiKeyValueComparisonFilter extends BooleanExpressionFil
 
     private Boolean matchedColumn;
     protected final IncrementalResultTuple inputTuple = new IncrementalResultTuple();
+    protected TreeSet<byte[]> cfSet;
 
     public MultiKeyValueComparisonFilter() {
     }
@@ -181,6 +183,7 @@ public abstract class MultiKeyValueComparisonFilter extends BooleanExpressionFil
     }
     
     protected void init() {
+        cfSet = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
         TraverseAllExpressionVisitor<Void> visitor = new TraverseAllExpressionVisitor<Void>()
{
             @Override
             public Void visit(KeyValueColumnExpression expression) {
@@ -239,6 +242,14 @@ public abstract class MultiKeyValueComparisonFilter extends BooleanExpressionFil
         super.reset();
     }
 
+    @SuppressWarnings("all")
+    // suppressing missing @Override since this doesn't exist for HBase 0.94.4
+    public boolean isFamilyEssential(byte[] name) {
+        // Only the column families involved in the expression are essential.
+        // The others are for columns projected in the select expression.
+        return cfSet.contains(name);
+    }
+
     @Override
     public void readFields(DataInput input) throws IOException {
         super.readFields(input);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/545abe53/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index a3c01bb..e4f0918 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -100,9 +100,9 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
 import java.util.Properties;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -1005,7 +1005,37 @@ public abstract class BaseTest {
             conn.close();
         }
     }
-    
+
+    protected static void initMultiCFTable(String url) throws Exception {
+        ensureTableCreated(url, MULTI_CF_NAME);
+
+        Connection conn = DriverManager.getConnection(url);
+        try {
+            PreparedStatement stmt = conn.prepareStatement(
+                    "upsert into " +
+                    "MULTI_CF(" +
+                    "    id, " +
+                    "    a.unique_user_count, " +
+                    "    b.unique_org_count, " +
+                    "    c.db_cpu_utilization) " +
+                    "VALUES (?, ?, ?, ?)");
+            stmt.setString(1, "id1");
+            stmt.setInt(2, 1);
+            stmt.setInt(3, 1);
+            stmt.setBigDecimal(4, BigDecimal.valueOf(40.1));
+            stmt.execute();
+
+            stmt.setString(1, "id2");
+            stmt.setInt(2, 2);
+            stmt.setInt(3, 2);
+            stmt.setBigDecimal(4, BigDecimal.valueOf(20.9));
+            stmt.execute();
+            conn.commit();
+        } finally {
+            conn.close();
+        }
+    }
+
     protected static void initTablesWithArrays(String tenantId, Date date, Long ts, boolean
useNull, String url) throws Exception {
         Properties props = new Properties();
         if (ts != null) {


Mime
View raw message