[
https://issues.apache.org/jira/browse/PHOENIX-5865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17419147#comment-17419147
]
ASF GitHub Bot commented on PHOENIX-5865:
-----------------------------------------
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]
> column that has default value can not be correctly indexed
> ----------------------------------------------------------
>
> Key: PHOENIX-5865
> URL: https://issues.apache.org/jira/browse/PHOENIX-5865
> Project: Phoenix
> Issue Type: Bug
> Components: core
> Affects Versions: 5.0.0
> Reporter: junfei liang
> Assignee: Richárd Antal
> Priority: Major
> Attachments: IndexWithDefaultIT.patch
>
>
> # create a table with a column has default value
> create table data_table(
> pk VARCHAR, +
> c VARCHAR default '0',
> CONSTRAINT my_pk PRIMARY KEY (pk)
> 2. insert data into it
> upsert into data_table values('1','1')
> 3. create an index on the column
> CREATE INDEX idx_data_table ON data_table(pk, c)
> 4. check index table ,found data is wrong
> select * from idx_data_table
> found 0:c column value is '0' , but it should be 1.
> see attachment for details.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)