[ https://issues.apache.org/jira/browse/PHOENIX-3488?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15672054#comment-15672054 ]
Eric Lomore commented on PHOENIX-3488: -------------------------------------- [~maryannxue], I believe I have a working patch for this. Before I create a PR, I wanted to raise an issue I noticed -- when doing multiple joins where only one of the joins is a PK the use of count(distinct x) fails both before and after my patch. While this query isn't necessarily logical (the count is always 1), it is valid. My patch is here for reference (includes the case below, and is annotated appropriately): https://github.com/bloomberg/phoenix/commit/ee361f98c73af82d798580f63a06aa6a30d43111 {code} select organization_id, b_string, count(distinct entity_id) from atable group by organization_id, b_string {code} {code} java.lang.AssertionError: Internal error: Error while applying rule PhoenixOrderedAggregateRule, args [rel#64710:PhoenixServerAggregate.SERVERAGG.[](input=rel#64709:Subset#5877.SERVER.[],group={0, 2},EXPR$2=COUNT($1),isOrdered=false)] at org.apache.calcite.util.Util.newInternal(Util.java:792) at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:236) at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:803) at org.apache.calcite.tools.Programs$5.run(Programs.java:300) at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:351) at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:155) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:280) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:195) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:737) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:600) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:570) at org.apache.phoenix.calcite.PhoenixPrepareImpl.prepareSql(PhoenixPrepareImpl.java:223) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:215) at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:594) at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:615) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:148) at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218) at org.apache.calcite.jdbc.PhoenixCalciteFactory$PhoenixCalciteStatement.executeQuery(PhoenixCalciteFactory.java:349) at org.apache.phoenix.calcite.BaseCalciteIT$Sql.checkExplain(BaseCalciteIT.java:181) at org.apache.phoenix.calcite.BaseCalciteIT$Sql.explainIs(BaseCalciteIT.java:172) at org.apache.phoenix.calcite.CalciteIT.testCountDistinct(CalciteIT.java:880) 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.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.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) Caused by: java.lang.AssertionError: Internal error: Error occurred while applying rule PhoenixOrderedAggregateRule at org.apache.calcite.util.Util.newInternal(Util.java:792) at org.apache.calcite.plan.volcano.VolcanoRuleCall.transformTo(VolcanoRuleCall.java:148) at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:225) at org.apache.phoenix.calcite.rules.PhoenixOrderedAggregateRule.onMatch(PhoenixOrderedAggregateRule.java:54) at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:213) ... 52 more Caused by: java.lang.StackOverflowError at com.google.common.collect.UnmodifiableIterator.<init>(UnmodifiableIterator.java:32) at com.google.common.collect.UnmodifiableListIterator.<init>(UnmodifiableListIterator.java:34) at com.google.common.collect.AbstractIndexedListIterator.<init>(AbstractIndexedListIterator.java:68) at com.google.common.collect.Iterators$13.<init>(Iterators.java:1155) at com.google.common.collect.Iterators.forArray(Iterators.java:1155) at com.google.common.collect.RegularImmutableList.listIterator(RegularImmutableList.java:96) at com.google.common.collect.ImmutableList.listIterator(ImmutableList.java:334) at com.google.common.collect.ImmutableList.listIterator(ImmutableList.java:62) at com.google.common.collect.Lists.indexOfImpl(Lists.java:969) at com.google.common.collect.ImmutableList.indexOf(ImmutableList.java:348) at GeneratedMetadataHandler_DistinctRowCount.getDistinctRowCount_$(Unknown Source) at GeneratedMetadataHandler_DistinctRowCount.getDistinctRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getDistinctRowCount(RelMetadataQuery.java:700) at org.apache.calcite.rel.metadata.RelMdDistinctRowCount.getDistinctRowCount(RelMdDistinctRowCount.java:292) at GeneratedMetadataHandler_DistinctRowCount.getDistinctRowCount_$(Unknown Source) at GeneratedMetadataHandler_DistinctRowCount.getDistinctRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getDistinctRowCount(RelMetadataQuery.java:700) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:35) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.SingleRel.estimateRowCount(SingleRel.java:68) at org.apache.calcite.rel.core.Aggregate.estimateRowCount(Aggregate.java:294) at org.apache.phoenix.calcite.metadata.PhoenixRelMdRowCount.getRowCount(PhoenixRelMdRowCount.java:40) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) at org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:201) at org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71) at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source) at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source) {code} > Support COUNT(DISTINCT x) in Phoenix-Calcite Integration > -------------------------------------------------------- > > Key: PHOENIX-3488 > URL: https://issues.apache.org/jira/browse/PHOENIX-3488 > Project: Phoenix > Issue Type: Improvement > Reporter: Eric Lomore > Assignee: Eric Lomore > Labels: calcite > -- This message was sent by Atlassian JIRA (v6.3.4#6332)