[ https://issues.apache.org/jira/browse/PHOENIX-5322?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16926254#comment-16926254 ]
Kadir OZDEMIR commented on PHOENIX-5322: ---------------------------------------- We do not need to have two indexes (one at the base table and and the other on the view) to hit this exception. Having an index only on the base table is sufficient to reproduce the problem. It happens with both new and old index design on the master branch. > Upsert on a view of an indexed table fails with ArrayIndexOutOfBound Exception > ------------------------------------------------------------------------------ > > Key: PHOENIX-5322 > URL: https://issues.apache.org/jira/browse/PHOENIX-5322 > Project: Phoenix > Issue Type: Bug > Affects Versions: 4.14.2 > Reporter: Swaroopa Kadam > Assignee: Ankit Jain > Priority: Major > > {code:java} > // code placeholder > public void testUpstertOnViewWithIndexedTable() throws SQLException { > Properties prop = new Properties(); > Connection conn = DriverManager.getConnection(getUrl(), prop); > conn.setAutoCommit(true); > conn.createStatement().execute("CREATE TABLE IF NOT EXISTS us_population > (\n" + > " state CHAR(2) NOT NULL,\n" + > " city VARCHAR NOT NULL,\n" + > " population BIGINT,\n" + > " CONSTRAINT my_pk PRIMARY KEY (state, city)) > COLUMN_ENCODED_BYTES=0"); > PreparedStatement ps = conn.prepareStatement("UPSERT INTO us_population > VALUES('NY','New York',8143197)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population VALUES('CA','Los > Angeles',3844829)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population > VALUES('IL','Chicago',2842518)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population > VALUES('TX','Houston',2016582)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population > VALUES('PA','Philadelphia',1463281)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population > VALUES('AZ','Phoenix',1461575)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population VALUES('TX','San > Antonio',1256509)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population VALUES('CA','San > Diego',1255540)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population > VALUES('TX','Dallas',1213825)"); > ps.executeUpdate(); > ps = conn.prepareStatement("UPSERT INTO us_population VALUES('CA','San > Jose',912332)"); > ps.executeUpdate(); > conn.createStatement().execute("CREATE VIEW IF NOT EXISTS > us_population_gv" + > "(city_area INTEGER, avg_fam_size INTEGER) AS " + > "SELECT * FROM us_population WHERE state = 'CA'"); > conn.createStatement().execute("CREATE INDEX IF NOT EXISTS > us_population_gv_gi ON " + > "us_population_gv (city_area) INCLUDE (population)"); > conn.createStatement().execute("CREATE INDEX IF NOT EXISTS > us_population_gi ON " + > "us_population (population)"); > ps = conn.prepareStatement("UPSERT INTO > us_population_gv(state,city,population,city_area,avg_fam_size) " + > "VALUES('CA','Santa Barbara',912332,1300,4)"); > ps.executeUpdate(); > } > {code} > Exception: > java.lang.ArrayIndexOutOfBoundsException: -1 > at java.util.ArrayList.elementData(ArrayList.java:422) > at java.util.ArrayList.get(ArrayList.java:435) > at > org.apache.phoenix.index.IndexMaintainer.initCachedState(IndexMaintainer.java:1631) > at > org.apache.phoenix.index.IndexMaintainer.<init>(IndexMaintainer.java:564) > at > org.apache.phoenix.index.IndexMaintainer.create(IndexMaintainer.java:144) > at > org.apache.phoenix.schema.PTableImpl.getIndexMaintainer(PTableImpl.java:1499) > at > org.apache.phoenix.index.IndexMaintainer.serialize(IndexMaintainer.java:226) > at > org.apache.phoenix.index.IndexMaintainer.serializeServerMaintainedIndexes(IndexMaintainer.java:203) > at > org.apache.phoenix.index.IndexMaintainer.serialize(IndexMaintainer.java:187) > at > org.apache.phoenix.schema.PTableImpl.getIndexMaintainers(PTableImpl.java:1511) > at org.apache.phoenix.execute.MutationState.send(MutationState.java:963) > at > org.apache.phoenix.execute.MutationState.send(MutationState.java:1432) > at > org.apache.phoenix.execute.MutationState.commit(MutationState.java:1255) > at > org.apache.phoenix.jdbc.PhoenixConnection$3.call(PhoenixConnection.java:673) > at > org.apache.phoenix.jdbc.PhoenixConnection$3.call(PhoenixConnection.java:669) > at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53) > at > org.apache.phoenix.jdbc.PhoenixConnection.commit(PhoenixConnection.java:669) > at > org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:412) > at > org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:392) > at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53) > at > org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:391) > at > org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:379) > at > org.apache.phoenix.jdbc.PhoenixPreparedStatement.executeUpdate(PhoenixPreparedStatement.java:206) > at > org.apache.phoenix.end2end.ParameterizedAlterTableCascade2IT.testUpstertOnViewWithIndexedTable(ParameterizedAlterTableCascade2IT.java:55) > 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.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:68) > at > com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) > at > com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) > at > com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) -- This message was sent by Atlassian Jira (v8.3.2#803003)