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

Samarth Jain commented on PHOENIX-4265:
---------------------------------------

I am slightly puzzled by this piece of code in WhereOptimizer:

{code}
for (int i = 0; i < 2; i++) {
            List<Expression> group = Lists.newArrayList();
            for (Expression expression : candidates) {
                PDataType type = expression.getDataType();
                group.add(LiteralExpression.newConstant(type.getSampleValue(), 
type));
            }
            sampleValues.add(group);
        }
{code}

The sample values are generated using a random generator. And then they are 
eventually used for pushing down key expressions into scan by using them in an 
InListExpression:

{code}
Expression testExpression = InListExpression.create(Lists.newArrayList(lhs, 
firstRhs, secondRhs), false, context.getTempPtr(), 
context.getCurrentTable().getTable().rowKeyOrderOptimizable());
            remaining = pushKeyExpressionsToScan(context, statement, 
testExpression);
{code}

When using row timestamp, these random values could result in invalid timestamp 
range causing the query to randomly fail with error like below:

{code}
java.lang.IllegalArgumentException: Timestamp cannot be negative. 
minStamp:-2644630825337824141, maxStamp:1811472903795337288
        at org.apache.hadoop.hbase.io.TimeRange.check(TimeRange.java:112)
        at org.apache.hadoop.hbase.io.TimeRange.<init>(TimeRange.java:100)
        at 
org.apache.phoenix.compile.ScanRanges.getAscTimeRange(ScanRanges.java:691)
        at 
org.apache.phoenix.compile.ScanRanges.getRowTimestampColumnRange(ScanRanges.java:661)
        at org.apache.phoenix.compile.ScanRanges.create(ScanRanges.java:87)
        at 
org.apache.phoenix.compile.WhereOptimizer.pushKeyExpressionsToScan(WhereOptimizer.java:305)
        at 
org.apache.phoenix.compile.WhereOptimizer.pushKeyExpressionsToScan(WhereOptimizer.java:104)
        at 
org.apache.phoenix.compile.WhereOptimizer.getKeyExpressionCombination(WhereOptimizer.java:385)
        at 
org.apache.phoenix.compile.QueryCompiler.getKeyExpressionCombinations(QueryCompiler.java:460)
        at 
org.apache.phoenix.compile.QueryCompiler.compileJoinQuery(QueryCompiler.java:314)
        at 
org.apache.phoenix.compile.QueryCompiler.compileSelect(QueryCompiler.java:200)
        at 
org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:157)
        at 
org.apache.phoenix.optimize.QueryOptimizer.addPlan(QueryOptimizer.java:304)
        at 
org.apache.phoenix.optimize.QueryOptimizer.getHintedQueryPlan(QueryOptimizer.java:196)
        at 
org.apache.phoenix.optimize.QueryOptimizer.getApplicablePlans(QueryOptimizer.java:137)
        at 
org.apache.phoenix.optimize.QueryOptimizer.optimize(QueryOptimizer.java:94)
        at 
org.apache.phoenix.optimize.QueryOptimizer.optimize(QueryOptimizer.java:80)
        at 
org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:307)
        at 
org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:1)
        at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
        at 
org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:289)
        at 
org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:283)
        at 
org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:1706)
        at 
org.apache.phoenix.end2end.UpsertSelectIT.testCodecUsedForRowTimestamp(UpsertSelectIT.java:1476)
{code}

[~jamestaylor] - are these random values are only used for the purpose of 
generating all applicable plans? And if so, would it be ok to make sure that 
the sampled values returned are positive?


> NPE when hinting index on table with ROW_TIMESTAMP
> --------------------------------------------------
>
>                 Key: PHOENIX-4265
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-4265
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: James Taylor
>
> See email discussion here: 
> https://lists.apache.org/thread.html/d87a508e5b4e2fc6b7110d861b71209d2385adaecd0152b790ee00e9@%3Cuser.phoenix.apache.org%3E
> I'm not able to repro with this unit test:
> {code}
>     @Test
>     public void testIndexHintOnTableWithRowTimestamp() throws Exception {
>         Connection conn = DriverManager.getConnection(getUrl());
>         try {
>             conn.createStatement().execute("CREATE IMMUTABLE TABLE t1 (k1 
> TIMESTAMP not null, k2 bigint not null, v bigint, constraint pk primary key 
> (k1 row_timestamp,k2 ))");
>             conn.createStatement().execute("CREATE INDEX idx ON t1 (v)");
>             conn.createStatement().execute("SELECT /*+ INDEX(T1 IDX) */ 
> K1,K2,V FROM t1 WHERE v = 5");
>         } finally {
>             conn.close();
>         }
>     }
> {code}
> FYI, due to the inability to keep an index in sync when there's a 
> ROW_TIMESTAMP column, as of 4.12 we're disallowing the creation of mutable 
> secondary indexes when a table has a ROW_TIMESTAMP column. Usually, since the 
> timestamp is part of the row key, the data table can be declared IMMUTABLE. 
> In this case, the index would still be allowed.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to