Repository: lens Updated Branches: refs/heads/current-release-line 27ad9aa8f -> ac9a56fcd
LENS-1428 : Common measures are getting repeated in UnionQuery for JoinCandidate Project: http://git-wip-us.apache.org/repos/asf/lens/repo Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/ac9a56fc Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/ac9a56fc Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/ac9a56fc Branch: refs/heads/current-release-line Commit: ac9a56fcd828b0cbb6acee614c72f650a6cb78b8 Parents: 27ad9aa Author: Sushil Mohanty <sushil.k.moha...@gmail.com> Authored: Tue Jun 6 15:10:24 2017 +0530 Committer: sushilmohanty <sushilmoha...@apache.org> Committed: Tue Jun 6 15:10:24 2017 +0530 ---------------------------------------------------------------------- .../apache/lens/cube/metadata/CubeMetastoreClient.java | 2 +- .../java/org/apache/lens/cube/parse/Candidate.java | 9 +++++++++ .../org/apache/lens/cube/parse/CubeQueryContext.java | 5 +++++ .../java/org/apache/lens/cube/parse/JoinCandidate.java | 13 +++++++++++++ .../org/apache/lens/cube/parse/StorageCandidate.java | 7 +++++++ .../org/apache/lens/cube/parse/UnionQueryWriter.java | 6 ++---- 6 files changed, 37 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lens/blob/ac9a56fc/lens-cube/src/main/java/org/apache/lens/cube/metadata/CubeMetastoreClient.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/main/java/org/apache/lens/cube/metadata/CubeMetastoreClient.java b/lens-cube/src/main/java/org/apache/lens/cube/metadata/CubeMetastoreClient.java index 749e44c..5c05e53 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/metadata/CubeMetastoreClient.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/metadata/CubeMetastoreClient.java @@ -443,7 +443,7 @@ public class CubeMetastoreClient { if (get(timeLineKey) == null) { loadTimeLines(fact, storage, timeLineKey); } - log.info("timeline for {} is: {}", storage, get(timeLineKey)); + log.debug("timeline for {} is: {}", storage, get(timeLineKey)); // return the final value from memory return get(timeLineKey); // RESUME CHECKSTYLE CHECK DoubleCheckedLockingCheck http://git-wip-us.apache.org/repos/asf/lens/blob/ac9a56fc/lens-cube/src/main/java/org/apache/lens/cube/parse/Candidate.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/Candidate.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/Candidate.java index 2edeb41..0855ced 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/Candidate.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/Candidate.java @@ -355,4 +355,13 @@ public interface Candidate { } throw new IllegalArgumentException("Candidate doesn't have children and no suitable implementation found"); } + + default Set<Integer> decideMeasurePhrasesToAnswer(Set<Integer> measurePhraseIndices) throws LensException { + HashSet<Integer> allCovered = Sets.newHashSet(); + for (Candidate candidate : getChildren()) { + Set<Integer> covered = candidate.decideMeasurePhrasesToAnswer(measurePhraseIndices); + allCovered.addAll(covered); + } + return allCovered; + } } http://git-wip-us.apache.org/repos/asf/lens/blob/ac9a56fc/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryContext.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryContext.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryContext.java index 47bce65..b5330a7 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryContext.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryContext.java @@ -830,6 +830,11 @@ public class CubeQueryContext extends TracksQueriedColumns implements QueryAST, cand = iter.next(); log.info("Available Candidates:{}, picking up Candidate: {} for querying", candidates, cand); pickedCandidate = cand; + // Answerable common measures in JoinCandidate should be answered by one of the children, otherwise + // measure numbers will be added multiple times in the final union query. + Set<Integer> measureIndices = getQueriedPhrases().stream().filter(x -> x.hasMeasures(this)) + .map(QueriedPhraseContext::getPosition).collect(toSet()); + pickedCandidate.decideMeasurePhrasesToAnswer(measureIndices); } if (pickedCandidate == null) { throwNoCandidateFactException(); http://git-wip-us.apache.org/repos/asf/lens/blob/ac9a56fc/lens-cube/src/main/java/org/apache/lens/cube/parse/JoinCandidate.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/JoinCandidate.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/JoinCandidate.java index 038d689..c4049cd 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/JoinCandidate.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/JoinCandidate.java @@ -30,6 +30,7 @@ import org.apache.lens.cube.metadata.TimeRange; import org.apache.lens.server.api.error.LensException; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import lombok.Getter; /** @@ -177,6 +178,18 @@ public class JoinCandidate implements Candidate { return this; } + @Override + public Set<Integer> decideMeasurePhrasesToAnswer(Set<Integer> measureIndices) throws LensException { + Set<Integer> remaining = Sets.newHashSet(measureIndices); + Set<Integer> allCovered = Sets.newHashSet(); + for (Candidate child : children) { + Set<Integer> covered = child.decideMeasurePhrasesToAnswer(remaining); + allCovered.addAll(covered); + remaining = Sets.difference(remaining, covered); + } + return allCovered; + } + private String getToString() { return children.stream().map(Object::toString).collect(joining("; ", "JOIN[", "]")); } http://git-wip-us.apache.org/repos/asf/lens/blob/ac9a56fc/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageCandidate.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageCandidate.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageCandidate.java index 99c6cf6..3f5e2e5 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageCandidate.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageCandidate.java @@ -729,6 +729,7 @@ public class StorageCandidate implements Candidate, CandidateTable { @Override public boolean isDimAttributeEvaluable(String dim) throws LensException { + return getCubeQueryContext().getDeNormCtx() .addRefUsage(getCubeQueryContext(), this, dim, getCubeQueryContext().getCube().getName()); } @@ -955,4 +956,10 @@ public class StorageCandidate implements Candidate, CandidateTable { ast.copyFrom(getCubeQueryContext()); return new StorageCandidateHQLContext(this, Maps.newHashMap(dimsToQuery), ast, rootCubeQueryContext); } + + @Override + public Set<Integer> decideMeasurePhrasesToAnswer(Set<Integer> measureIndices) { + answerableMeasurePhraseIndices.retainAll(measureIndices); + return answerableMeasurePhraseIndices; + } } http://git-wip-us.apache.org/repos/asf/lens/blob/ac9a56fc/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java ---------------------------------------------------------------------- diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java index 6c0d91a..9412f27 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/UnionQueryWriter.java @@ -278,8 +278,7 @@ public class UnionQueryWriter extends SimpleHQLContext { * @throws LensException */ private ASTNode setDefaultValueInExprForAggregateNodes(ASTNode node, StorageCandidate sc) throws LensException { - if (HQLParser.isAggregateAST(node) - && isNodeNotAnswerableForStorageCandidate(sc, node)) { + if (HQLParser.isAggregateAST(node)) { node.setChild(1, getSelectExpr(null, null, true)); } for (int i = 0; i < node.getChildCount(); i++) { @@ -430,8 +429,7 @@ public class UnionQueryWriter extends SimpleHQLContext { // Select phrase is expression } else { for (StorageCandidateHQLContext sc : storageCandidates) { - if (phrase.isEvaluable(sc.getStorageCandidate()) - || sc.getStorageCandidate().getAnswerableMeasurePhraseIndices().contains(phrase.getPosition())) { + if (sc.getStorageCandidate().getAnswerableMeasurePhraseIndices().contains(phrase.getPosition())) { ASTNode exprWithOutAlias = (ASTNode) sc.getQueryAst().getSelectAST().getChild(i).getChild(0); storageCandidateToSelectAstMap.get(sc.getStorageCandidate().toString()). addChild(getSelectExpr(exprWithOutAlias, aliasNode, false));