Kevin Liew created PHOENIX-3397:
-----------------------------------

             Summary: Compiled ARRAY date-time literals cannot be parsed as 
literals
                 Key: PHOENIX-3397
                 URL: https://issues.apache.org/jira/browse/PHOENIX-3397
             Project: Phoenix
          Issue Type: Bug
    Affects Versions: 4.8.0
            Reporter: Kevin Liew
            Priority: Minor


We ran into an issue in PHOENIX-476 where: if you compile an ARRAY expression 
with date-time literals, store the resulting expression string in the 
metastore, and later try to parse it as a literal, you will get an error:

{code:java}
org.apache.phoenix.schema.TypeMismatchException: ERROR 203 (22005): Type 
mismatch. ERROR 203 (22005): Type mismatch. ERROR 203 (22005): Type mismatch. 
ERROR 203 (22005): Type mismatch. VARCHAR cannot be coerced to TIME

        at 
org.apache.phoenix.exception.SQLExceptionCode$1.newException(SQLExceptionCode.java:74)
        at 
org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:145)
        at 
org.apache.phoenix.util.ServerUtil.parseRemoteException(ServerUtil.java:129)
        at 
org.apache.phoenix.util.ServerUtil.parseServerExceptionOrNull(ServerUtil.java:118)
        at 
org.apache.phoenix.util.ServerUtil.parseServerException(ServerUtil.java:107)
        at 
org.apache.phoenix.iterate.BaseResultIterators.getIterators(BaseResultIterators.java:751)
        at 
org.apache.phoenix.iterate.BaseResultIterators.getIterators(BaseResultIterators.java:695)
        at 
org.apache.phoenix.iterate.ConcatResultIterator.getIterators(ConcatResultIterator.java:50)
        at 
org.apache.phoenix.iterate.ConcatResultIterator.currentIterator(ConcatResultIterator.java:97)
        at 
org.apache.phoenix.iterate.ConcatResultIterator.next(ConcatResultIterator.java:117)
        at 
org.apache.phoenix.jdbc.PhoenixResultSet.next(PhoenixResultSet.java:778)
        at 
org.apache.phoenix.end2end.DefaultColumnValueIT.testDefaultArrays(DefaultColumnValueIT.java:732)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at 
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at 
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
        at org.junit.rules.RunRules.evaluate(RunRules.java:20)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
        at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
        at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
        at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
{code}

This is due to the following code in ExpressionCompiler.
{code:java}
public Expression visitLeave(ArrayConstructorNode node, List<Expression> 
children) throws SQLException {
...
ArrayConstructorExpression arrayExpression = new 
ArrayConstructorExpression(children, arrayElemDataType, rowKeyOrderOptimizable);
        if (ExpressionUtil.isConstant(arrayExpression)) {
            for (int i = 0; i < children.size(); i++) {
                Expression child = children.get(i);
                child.evaluate(null, ptr);
                Object value = null;
                if (child.getDataType() == null) {
                    value = arrayElemDataType.toObject(ptr, 
theArrayElemDataType, child.getSortOrder());
                } else {
                    value = arrayElemDataType.toObject(ptr, 
child.getDataType(), child.getSortOrder());
                }
                elements[i] = LiteralExpression.newConstant(value, 
theArrayElemDataType, child.getDeterminism()).getValue();
            }
            Object value = 
PArrayDataType.instantiatePhoenixArray(arrayElemDataType, elements);
            return LiteralExpression.newConstant(value,
                    PDataType.fromTypeId(arrayElemDataType.getSqlType() + 
PDataType.ARRAY_TYPE_BASE), null, null, arrayExpression.getSortOrder(), 
Determinism.ALWAYS, rowKeyOrderOptimizable);
        }
{code}

This only happens with arrays and not scalar values.



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

Reply via email to