You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "James Taylor (JIRA)" <ji...@apache.org> on 2016/03/28 17:18:25 UTC

[jira] [Commented] (PHOENIX-2803) Initializing ToCharFunction with the List constructor fails

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

James Taylor commented on PHOENIX-2803:
---------------------------------------

Thanks, [~tdsilva]. The patch looks good, but we should keep (but modify) the unit test that checks for ScalarFunction subclasses to implement a List<Expression> constructor. The reason is that we implement the clone() method on ScalarFunction by using reflection:
{code}
    public ScalarFunction clone(List<Expression> children) {
        try {
            // FIXME: we could potentially implement this on each subclass and not use reflection
            return getClass().getConstructor(List.class).newInstance(children);
        } catch (Exception e) {
            throw new RuntimeException(e); // Impossible, since it was originally constructed this way
        }
    }
{code}

If someone adds a new built-in function, but doesn't have this constructor, then we'd get a runtime exception here.

I think we should change the unit test to only check for a List<Expression> constructor if the class has not overridden the clone method.

> Initializing ToCharFunction with the List<Expression> constructor fails 
> ------------------------------------------------------------------------
>
>                 Key: PHOENIX-2803
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2803
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.7.0
>            Reporter: Thomas D'Silva
>            Assignee: Thomas D'Silva
>         Attachments: PHOENIX-2803.patch
>
>
> The following test can be used to repro
> {code}
> @Test
>     public void testToCharWithExpressionListConstructor() throws SQLException {
>         Connection conn = DriverManager.getConnection(getUrl());
>     	String ddl = "create table t (k varchar primary key, v integer[])";
>         conn.createStatement().execute(ddl);
>         conn.createStatement().executeQuery("select to_char(v[1]) from t");
>     }
> {code}
> throws this exception
> {code}
> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
> 	at org.apache.phoenix.expression.function.ScalarFunction.clone(ScalarFunction.java:44)
> 	at org.apache.phoenix.expression.visitor.CloneExpressionVisitor.visitLeave(CloneExpressionVisitor.java:106)
> 	at org.apache.phoenix.expression.visitor.ReplaceArrayFunctionExpressionVisitor.visitLeave(ReplaceArrayFunctionExpressionVisitor.java:44)
> 	at org.apache.phoenix.expression.visitor.CloneExpressionVisitor.visitLeave(CloneExpressionVisitor.java:1)
> 	at org.apache.phoenix.expression.function.ScalarFunction.accept(ScalarFunction.java:58)
> 	at org.apache.phoenix.compile.ProjectionCompiler.compile(ProjectionCompiler.java:462)
> 	at org.apache.phoenix.compile.QueryCompiler.compileSingleFlatQuery(QueryCompiler.java:546)
> 	at org.apache.phoenix.compile.QueryCompiler.compileSingleQuery(QueryCompiler.java:496)
> 	at org.apache.phoenix.compile.QueryCompiler.compileSelect(QueryCompiler.java:202)
> 	at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:158)
> 	at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:396)
> 	at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:1)
> 	at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:263)
> 	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:257)
> 	at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:1261)
> 	at org.apache.phoenix.end2end.ToCharFunctionIT.testToCharWithExpressionListConstructor(ToCharFunctionIT.java:250)
> 	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:497)
> 	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.RunBefores.evaluate(RunBefores.java:26)
> 	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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
> Caused by: java.lang.reflect.InvocationTargetException
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
> 	at org.apache.phoenix.expression.function.ScalarFunction.clone(ScalarFunction.java:42)
> 	... 46 more
> Caused by: java.lang.NullPointerException
> 	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
> 	at org.apache.phoenix.expression.function.ToCharFunction.<init>(ToCharFunction.java:66)
> 	at org.apache.phoenix.expression.function.ToCharFunction.<init>(ToCharFunction.java:61)
> 	... 51 more
> {code}



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