PHOENIX-3917 RowProjector#getEstimatedRowByteSize() returns incorrect value 
(Biju Nair)


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 3d88882586b1d0d2b0f264067a6c9097cfec2faf
Parents: 777231a
Author: James Taylor <jamestay...@apache.org>
Authored: Thu Jun 8 17:09:49 2017 -0700
Committer: James Taylor <jamestay...@apache.org>
Committed: Fri Jun 9 11:20:30 2017 -0700

----------------------------------------------------------------------
 .../phoenix/compile/ProjectionCompiler.java     | 47 +++++++++++---------
 1 file changed, 25 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3d888825/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
index 4c4fb16..a147882 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
@@ -467,38 +467,41 @@ public class ProjectionCompiler {
             }
         }
 
+        boolean isProjectEmptyKeyValue = false;
+        if (isWildcard) {
+            projectAllColumnFamilies(table, scan);
+        } else {
+            isProjectEmptyKeyValue = where == null || 
LiteralExpression.isTrue(where) || where.requiresFinalEvaluation();
+            for (byte[] family : projectedFamilies) {
+                projectColumnFamily(table, scan, family);
+            }
+        }
+        
         // TODO make estimatedByteSize more accurate by counting the joined 
columns.
         int estimatedKeySize = 
table.getRowKeySchema().getEstimatedValueLength();
         int estimatedByteSize = 0;
         for (Map.Entry<byte[],NavigableSet<byte[]>> entry : 
scan.getFamilyMap().entrySet()) {
-            PColumnFamily family = table.getColumnFamily(entry.getKey());
-            if (entry.getValue() == null) {
-                for (PColumn column : family.getColumns()) {
-                    Integer maxLength = column.getMaxLength();
-                    int byteSize = column.getDataType().isFixedWidth() ? 
maxLength == null ? column.getDataType().getByteSize() : maxLength : 
RowKeySchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
-                    estimatedByteSize += SizedUtil.KEY_VALUE_SIZE + 
estimatedKeySize + byteSize;
-                }
-            } else {
-                for (byte[] cq : entry.getValue()) {
-                    //if (!Bytes.equals(cq, ByteUtil.EMPTY_BYTE_ARRAY) || 
cq.length > 0) {
-                        PColumn column = 
family.getPColumnForColumnQualifier(cq);
+            try {
+                PColumnFamily family = table.getColumnFamily(entry.getKey());
+                if (entry.getValue() == null) {
+                    for (PColumn column : family.getColumns()) {
                         Integer maxLength = column.getMaxLength();
                         int byteSize = column.getDataType().isFixedWidth() ? 
maxLength == null ? column.getDataType().getByteSize() : maxLength : 
RowKeySchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
                         estimatedByteSize += SizedUtil.KEY_VALUE_SIZE + 
estimatedKeySize + byteSize;
                     }
-                //}
-            }
-        }
-        boolean isProjectEmptyKeyValue = false;
-        if (isWildcard) {
-            projectAllColumnFamilies(table, scan);
-        } else {
-            isProjectEmptyKeyValue = where == null || 
LiteralExpression.isTrue(where) || where.requiresFinalEvaluation();
-            for (byte[] family : projectedFamilies) {
-                projectColumnFamily(table, scan, family);
+                } else {
+                    for (byte[] cq : entry.getValue()) {
+                            PColumn column = 
family.getPColumnForColumnQualifier(cq);
+                            Integer maxLength = column.getMaxLength();
+                            int byteSize = column.getDataType().isFixedWidth() 
? maxLength == null ? column.getDataType().getByteSize() : maxLength : 
RowKeySchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
+                            estimatedByteSize += SizedUtil.KEY_VALUE_SIZE + 
estimatedKeySize + byteSize;
+                        }
+                }
+            } catch (ColumnFamilyNotFoundException e) {
+                // Ignore as this can happen for local indexes when the data 
table has a column family, but there are no covered columns in the family
             }
         }
-        return new RowProjector(projectedColumns, estimatedByteSize, 
isProjectEmptyKeyValue, resolver.hasUDFs(), isWildcard);
+        return new RowProjector(projectedColumns, Math.max(estimatedKeySize, 
estimatedByteSize), isProjectEmptyKeyValue, resolver.hasUDFs(), isWildcard);
     }
 
     private static void projectAllColumnFamilies(PTable table, Scan scan) {

Reply via email to