You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "Thomas D'Silva (JIRA)" <ji...@apache.org> on 2017/02/07 02:02:41 UTC

[jira] [Comment Edited] (PHOENIX-3648) Self Join on table with columns of the same name and different column families fails

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

Thomas D'Silva edited comment on PHOENIX-3648 at 2/7/17 2:02 AM:
-----------------------------------------------------------------

The test also passes if I make the following change to only use the {{TupleProjector.VALUE_COLUMN_FAMILY}} for pk columns. The explain plans don't change with this change. 

In the encodeColumns branch we validate that for each column family the column qualifiers are unique, so we need to make the following change.

{code}
-            PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName), 
-                    retainPKColumns && SchemaUtil.isPKColumn(sourceColumn) ? 
-                            null : PNameFactory.newName(VALUE_COLUMN_FAMILY), 
+            PName familyName =  SchemaUtil.isPKColumn(sourceColumn) ? (retainPKColumns ? null : PNameFactory.newName(VALUE_COLUMN_FAMILY)) : sourceColumn.getFamilyName();
+            PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName), familyName,
{code}


was (Author: tdsilva):
The test also passes if I make the following change to only use the {code}TupleProjector.VALUE_COLUMN_FAMILY{code} for pk columns. The explain plans don't change with this change. 

In the encodeColumns branch we validate that for each column family the column qualifiers are unique, so we need to make the following change.

{code}
-            PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName), 
-                    retainPKColumns && SchemaUtil.isPKColumn(sourceColumn) ? 
-                            null : PNameFactory.newName(VALUE_COLUMN_FAMILY), 
+            PName familyName =  SchemaUtil.isPKColumn(sourceColumn) ? (retainPKColumns ? null : PNameFactory.newName(VALUE_COLUMN_FAMILY)) : sourceColumn.getFamilyName();
+            PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName), familyName,
{code}

> Self Join on table with columns of the same name and different column families fails
> ------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-3648
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3648
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Thomas D'Silva
>            Assignee: Thomas D'Silva
>
> The following test fails when running the second join query. 
> {code}
> @Test
>     public void testSelfJoin() throws Exception {
>         try (Connection conn = DriverManager.getConnection(getUrl())) {
>             conn.createStatement().execute("create table t1 (varchar_pk VARCHAR NOT NULL primary key, a.varchar_col1 VARCHAR, b.varchar_col2 VARCHAR)");
>             conn.createStatement().execute("create table t2 (varchar_pk VARCHAR NOT NULL primary key, a.varchar_col1 VARCHAR, b.varchar_col1 VARCHAR)");
>             // verify no rows returned
>             ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM t1 x JOIN t1 y ON (x.varchar_pk = y.a.varchar_col1)");
>             assertFalse(rs.next());
>             rs = conn.createStatement().executeQuery("SELECT * FROM t2 x JOIN t2 y ON (x.varchar_pk = y.a.varchar_col1)");
>             assertFalse(rs.next());
>         } 
>     }
> {code}
> {code}
> org.apache.phoenix.schema.ColumnAlreadyExistsException: ERROR 514 (42892): A duplicate column name was detected in the object definition or ALTER TABLE statement. columnName=..T2.X.VARCHAR_COL1
> 	at org.apache.phoenix.schema.PTableImpl.init(PTableImpl.java:467)
> 	at org.apache.phoenix.schema.PTableImpl.<init>(PTableImpl.java:365)
> 	at org.apache.phoenix.schema.PTableImpl.makePTable(PTableImpl.java:335)
> 	at org.apache.phoenix.compile.TupleProjectionCompiler.createProjectedTable(TupleProjectionCompiler.java:179)
> 	at org.apache.phoenix.compile.JoinCompiler$Table.createProjectedTable(JoinCompiler.java:751)
> 	at org.apache.phoenix.compile.QueryCompiler.compileJoinQuery(QueryCompiler.java:267)
> 	at org.apache.phoenix.compile.QueryCompiler.compileSelect(QueryCompiler.java:200)
> 	at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:157)
> 	at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:417)
> 	at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:391)
> 	at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:277)
> 	at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:267)
> 	at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
> 	at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:266)
> 	at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:1427)
> 	at org.apache.phoenix.end2end.index.IndexExpressionIT.testSelfJoin(IndexExpressionIT.java:1554)
> 	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.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.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)
> {code}
> It fails because in TupleProjectionCompiler.createProjectedTable when we create the projected columns we set the column family name to TupleProjector.VALUE_COLUMN_FAMILY
> [~maryannxue], [~jamestaylor] Do you have any suggestions on how to fix this?
> {code}
> for (int i = position; i < sourceColumnRefs.size(); i++) {
>             ColumnRef sourceColumnRef = sourceColumnRefs.get(i);
>             PColumn sourceColumn = sourceColumnRef.getColumn();
>             String colName = sourceColumn.getName().getString();
>             String aliasedName = tableRef.getTableAlias() == null ? 
>                       SchemaUtil.getColumnName(table.getName().getString(), colName) 
>                     : SchemaUtil.getColumnName(tableRef.getTableAlias(), colName);
>             PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName), 
>                     retainPKColumns && SchemaUtil.isPKColumn(sourceColumn) ? 
>                             null : PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), 
>                     position++, sourceColumn.isNullable(), sourceColumnRef);
>             projectedColumns.add(column);
>         }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)