[ 
https://issues.apache.org/jira/browse/PHOENIX-2138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14640601#comment-14640601
 ] 

James Taylor commented on PHOENIX-2138:
---------------------------------------

I see. I believe that an expression should only return a maxLength for non 
primitive types, so LiteralExpression is acting somewhat different here. Two 
potential lower level fixes come to mind:
- Change LiteralExpression to leave maxLength null if dataType.getByteSize() == 
null. I think there are two places you'd need to change. Change this if 
statement:
{code}
        if (maxLength == null) {
            maxLength = type == null || !type.isFixedWidth() ? null : 
type.getMaxLength(value);
        }
{code}
 Instead, use a null maxLength if type.getByteSize() != null:
{code}
        if (type == null || type.getByteSize() != null) {
            maxLength = null;
        }
{code}
and here, just always use null for maxLength
{code}
    private LiteralExpression(Object value, PDataType type, byte[] byteValue, 
Determinism determinism) {
        this(value, type, byteValue, null, null, SortOrder.getDefault(), 
determinism);
    }
{code}
Try running the unit tests, as I suspect it'll break some things, but it'd be 
good to understand what/why.
- Second, less-lower-level change would be to change the UpertCompiler call to 
pass null as the actualMaxLength if the data type is primitive. This seems less 
ideal, though, as then sometimes LiteralExpression would have a null maxLength 
and sometimes it wouldn't.
{code}
column.getDataType().coerceBytes(ptr, value, constantExpression.getDataType(), 
                            constantExpression.getDataType().getByteSize() == 
null ?nullconstantExpression.getMaxLength() : null, 
constantExpression.getScale(), constantExpression.getSortOrder(),
                            column.getMaxLength(), 
column.getScale(),column.getSortOrder(),
                            table.rowKeyOrderOptimizable());
{code}

> Non equality comparisons don't work for ARRAY type columns that are DESC in 
> row key
> -----------------------------------------------------------------------------------
>
>                 Key: PHOENIX-2138
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2138
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: James Taylor
>            Assignee: Dumindu Buddhika
>         Attachments: PHOENIX-2138_v1.patch, PHOENIX-2138_v2.patch
>
>
> An exception occurs when you attempt to query an array column declared as 
> DESC in the row key with <, >, <=, and >=.  Here's how to reproduce:
> {code}
> create table a (k varchar array primary key desc);
> upsert into a values (array['a']);
> select * from a where k >= array['a'];
> {code}
> The exception is:
> {code}
> java.lang.IllegalArgumentException
>       at java.nio.Buffer.position(Buffer.java:236)
>       at 
> org.apache.phoenix.schema.types.PArrayDataType.createPhoenixArray(PArrayDataType.java:1074)
>       at 
> org.apache.phoenix.schema.types.PArrayDataType.toObject(PArrayDataType.java:335)
>       at 
> org.apache.phoenix.schema.types.PVarcharArray.toObject(PVarcharArray.java:65)
>       at 
> org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:966)
>       at 
> org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:970)
>       at 
> org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:999)
>       at 
> org.apache.phoenix.schema.types.PDataType.toStringLiteral(PDataType.java:1072)
>       at 
> org.apache.phoenix.schema.types.PDataType.toStringLiteral(PDataType.java:1068)
>       at 
> org.apache.phoenix.iterate.ExplainTable.appendPKColumnValue(ExplainTable.java:182)
>       at 
> org.apache.phoenix.iterate.ExplainTable.appendScanRow(ExplainTable.java:257)
>       at 
> org.apache.phoenix.iterate.ExplainTable.appendKeyRanges(ExplainTable.java:273)
>       at 
> org.apache.phoenix.iterate.ExplainTable.explain(ExplainTable.java:122)
>       at 
> org.apache.phoenix.iterate.BaseResultIterators.explain(BaseResultIterators.java:713)
>       at 
> org.apache.phoenix.iterate.RoundRobinResultIterator.explain(RoundRobinResultIterator.java:153)
>       at 
> org.apache.phoenix.execute.BaseQueryPlan.getPlanSteps(BaseQueryPlan.java:406)
>       at 
> org.apache.phoenix.execute.BaseQueryPlan.iterator(BaseQueryPlan.java:263)
>       at 
> org.apache.phoenix.execute.BaseQueryPlan.iterator(BaseQueryPlan.java:161)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:265)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:255)
>       at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:254)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1435)
>       at sqlline.Commands.execute(Commands.java:822)
>       at sqlline.Commands.sql(Commands.java:732)
>       at sqlline.SqlLine.dispatch(SqlLine.java:808)
>       at sqlline.SqlLine.begin(SqlLine.java:681)
>       at sqlline.SqlLine.start(SqlLine.java:398)
>       at sqlline.SqlLine.main(SqlLine.java:292)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to