richardantal commented on a change in pull request #1321:
URL: https://github.com/apache/phoenix/pull/1321#discussion_r714710133



##########
File path: 
phoenix-core/src/main/java/org/apache/phoenix/expression/function/DefaultValueExpression.java
##########
@@ -45,7 +45,7 @@ public DefaultValueExpression(List<Expression> children) 
throws SQLException {
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         boolean evaluated = children.get(0).evaluate(tuple, ptr);
-        if (evaluated) {
+        if (evaluated && ptr.getLength() > 0) {

Review comment:
       I think this DefaultValueExpression was not used before in case of 
indexes.
   This evaluate function is called here: 
https://github.com/apache/phoenix/blob/8c68fe435d0cc7d8bc69ccb05bc6536ba5647113/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java#L714
   Here we try to evaluate the first child, something like a 
KeyValueColumnExpression and if it was not successful we fall back to the 
defaultExpression.
   When we ran this on a column that had no value in it (it should be 
interpreted as the default value) this evaluate returned true.
   Examples of reading the score column:
   Row1: (id, no, total, score) values ('1111','1112', 1113, 1114)
   ```
   ptr.get(): [0, 0, 0, 19, 0, 0, 0, 4, 0, 4, 49, 49, 49, 49, 1, 48, -128, 13, 
0, 0, 1, 124, 18, 99, 16, -119, 4, -128, 0, 4, 90]
   ptr.getoffset() 27
   ptr.getLength(): 4
   ```
   It meanse the -128, 0, 4, 90 part will be in the built index Row.
   Row2 (id, no, total) values ('1121', '1122', 1123) - score should be default
   ```
   ptr.get():  [0, 0, 0, 19, 0, 0, 0, 0, 0, 4, 49, 49, 50, 49, 1, 48, -128, 13, 
0, 0, 1, 124, 18, 99, 16, -119, 4]
   ptr.getOffset() 27
   ptr.getLength() 0
   ```
   In this case we ended up writing this, with 0 Length
   
https://github.com/apache/phoenix/blob/8c68fe435d0cc7d8bc69ccb05bc6536ba5647113/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java#L728
   With my change we will fall back to the default value.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to