Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Fixing Expression resolver tests #21

Open
wants to merge 3 commits into
base: lens-1381
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,10 @@ private static CoveringInfo getMilliSecondCoveringInfo(Date from, Date to, long
}

static boolean isCoverableBy(Date from, Date to, Set<UpdatePeriod> intervals) {
for (UpdatePeriod period : intervals) {
if (getCoveringInfo(from, to, period).isCoverable()) {
return true;
}
}
return false;
return intervals.stream().anyMatch(period->isCoverableBy(from, to, period));
}
static boolean isCoverableBy(Date from, Date to, UpdatePeriod period) {
return getCoveringInfo(from, to, period).isCoverable();
}

public static int getTimeDiff(Date fromDate, Date toDate, UpdatePeriod updatePeriod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.Calendar;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import org.apache.lens.cube.error.LensCubeErrorCode;
Expand All @@ -48,10 +49,13 @@ public class TimeRange {
private ASTNode parent;
private int childIndex;

public boolean isCoverableBy(TreeSet<UpdatePeriod> updatePeriods) {
public boolean isCoverableBy(Set<UpdatePeriod> updatePeriods) {
return DateUtil.isCoverableBy(fromDate, toDate, updatePeriods);
}

public boolean isCoverableBy(UpdatePeriod updatePeriod) {
return DateUtil.isCoverableBy(fromDate, toDate, updatePeriod);
}

public static class TimeRangeBuilder {
private final TimeRange range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ String getBriefError(Set<CandidateTablePruneCause> causes) {
public enum SkipUpdatePeriodCode {
// invalid update period
INVALID,
// Query max interval is more than update period
QUERY_INTERVAL_BIGGER
//TODO: add property name this update period is greater than the Query max interval as provided by user
QUERY_INTERVAL_BIGGER_THAN_MAX,
// Query range is too small to be answered by this update period. It can only be answered by smaller update periods.
QUERY_INTERVAL_SMALL
}

// Used for Test cases only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ public boolean evaluateCompleteness(TimeRange timeRange, TimeRange parentTimeRan
boolean partColNotSupported = rangeParts.isEmpty();
String storageTableName = getName();

if (storagePruningMsgs.containsKey(storageTableName)) {
List<CandidateTablePruneCause> causes = storagePruningMsgs.get(storageTableName);
if (storagePruningMsgs.containsKey(this)) {
List<CandidateTablePruneCause> causes = storagePruningMsgs.get(this);
// Find the PART_COL_DOES_NOT_EXISTS
for (CandidateTablePruneCause cause : causes) {
if (cause.getCause().equals(CandidateTablePruneCode.PART_COL_DOES_NOT_EXIST)) {
Expand Down Expand Up @@ -744,4 +744,11 @@ public String getAliasForTable(String alias) {
}
return ret;
}

public boolean canCoverTimeRanges(CubeQueryContext cubeql) {
return cubeql.getTimeRanges().stream().allMatch(this::isTimeRangeCoverable);
}
public boolean isTimeRangeCoverable(TimeRange timeRange) {
return timeRange.isCoverableBy(getValidUpdatePeriods());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
/**
* Resolve storages and partitions of all candidate tables and prunes candidate tables with missing storages or
Expand All @@ -46,7 +48,7 @@ class StorageTableResolver implements ContextRewriter {
private final UpdatePeriod maxInterval;
// TODO union : Remove this. All partitions are stored in the StorageCandidate.
private final Map<String, Set<String>> nonExistingPartitions = new HashMap<>();
CubeMetastoreClient client;
private CubeMetastoreClient client;
private PHASE phase;
private float completenessThreshold;
private String completenessPartCol;
Expand Down Expand Up @@ -268,7 +270,6 @@ private void resolveStorageTable(CubeQueryContext cubeql) throws LensException {
boolean partitionColumnExists = client.partColExists(storageTable, range.getPartitionColumn());
valid = partitionColumnExists;
if (!partitionColumnExists) {
String timeDim = cubeql.getBaseCube().getTimeDimOfPartitionColumn(range.getPartitionColumn());
TimeRange fallBackRange = StorageUtil.getFallbackRange(range, sc.getFact().getName(), cubeql);
if (fallBackRange == null) {
log.info("No partitions for range:{}. fallback range: {}", range, fallBackRange);
Expand Down Expand Up @@ -299,17 +300,21 @@ private void resolveStorageTable(CubeQueryContext cubeql) throws LensException {
// Check for update period.
for (UpdatePeriod updatePeriod : sc.getFact().getUpdatePeriods().get(sc.getStorageName())) {
if (maxInterval != null && updatePeriod.compareTo(maxInterval) > 0) {
log.info("Skipping update period {} for fact {}", updatePeriod, sc.getFact());
skipUpdatePeriodCauses.put(updatePeriod.toString(), SkipUpdatePeriodCode.QUERY_INTERVAL_BIGGER);
continue;
}
if (validUpdatePeriods != null && !validUpdatePeriods.contains(updatePeriod.name().toLowerCase())) {
log.info("Skipping update period {} for fact {} for storage {}", updatePeriod, sc.getFact(), storageTable);
log.info("Skipping update period {} for fact {} since it's more than max interval supplied",
updatePeriod, sc.getFact());
skipUpdatePeriodCauses.put(updatePeriod.toString(), SkipUpdatePeriodCode.QUERY_INTERVAL_BIGGER_THAN_MAX);
} else if (validUpdatePeriods != null && !validUpdatePeriods.contains(updatePeriod.name().toLowerCase())) {
log.info("Skipping update period {} for fact {} for storage {} since it's invalid",
updatePeriod, sc.getFact(), storageTable);
skipUpdatePeriodCauses.put(updatePeriod.toString(), SkipUpdatePeriodCode.INVALID);
continue;
} else if (cubeql.getTimeRanges().stream().noneMatch(timeRange -> timeRange.isCoverableBy(updatePeriod))) {
log.info("Skipping update period {} for fact {} for storage {} since it's bigger than query range",
updatePeriod, sc.getFact(), storageTable);
skipUpdatePeriodCauses.put(updatePeriod.toString(), SkipUpdatePeriodCode.QUERY_INTERVAL_SMALL);
} else {
isStorageAdded = true;
sc.addValidUpdatePeriod(updatePeriod);
}
isStorageAdded = true;
sc.addValidUpdatePeriod(updatePeriod);
}
if (!isStorageAdded) {
cubeql.addStoragePruningMsg(sc, CandidateTablePruneCause.updatePeriodsRejected(skipUpdatePeriodCauses));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public void testFallbackPartCol() throws Exception {
getLensExceptionInRewrite("select msr12 from basecube where " + TWO_DAYS_RANGE, conf);
NoCandidateFactAvailableException ne = (NoCandidateFactAvailableException) exc;
PruneCauses.BriefAndDetailedError pruneCause = ne.getJsonMessage();
assertTrue(pruneCause.getBrief().contains("Missing partitions"));
assertTrue(pruneCause.getBrief().contains("Missing partitions")); // error in this.
assertEquals(pruneCause.getDetails().get("c4_testfact2_base").iterator().next().getCause(), MISSING_PARTITIONS);
assertEquals(pruneCause.getDetails().get("c4_testfact2_base").iterator().next().getMissingPartitions().size(), 1);
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public void testDimensionQueryWithTableAliasColumnAlias() throws Exception {
@Test
public void testSingleColExpression() throws Exception {
Configuration tconf = new Configuration(conf);
tconf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C2");
tconf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C2"); // time_range_in not translating
CubeQueryContext rewrittenQuery =
rewriteCtx("select singlecolmsr2expr from testCube where " + TWO_DAYS_RANGE, tconf);
String expected =
Expand Down Expand Up @@ -547,7 +547,7 @@ public void testSingleChainRefColExpressionWithAlias() throws Exception {
@Test
public void testSingleColExpressionWithAlias() throws Exception {
Configuration tconf = new Configuration(conf);
tconf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C2");
tconf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C2"); // time_range_in not getting translated
CubeQueryContext rewrittenQuery =
rewriteCtx("select singlecolmsr2expr as msr2 from testCube where " + TWO_DAYS_RANGE, tconf);
String expected =
Expand All @@ -559,7 +559,7 @@ public void testSingleColExpressionWithAlias() throws Exception {
@Test
public void testSingleColQualifiedExpression() throws Exception {
Configuration tconf = new Configuration(conf);
tconf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C2");
tconf.set(CubeQueryConfUtil.DRIVER_SUPPORTED_STORAGES, "C2"); // time_range_in not getting converted
CubeQueryContext rewrittenQuery =
rewriteCtx("select singlecolmsr2qualifiedexpr from testCube where " + TWO_DAYS_RANGE, tconf);
String expected =
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- java and javax -->
<java.source.version>1.7</java.source.version>
<java.target.version>1.7</java.target.version>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<servlet3.version>3.0.1</servlet3.version>
<servlet.api.version>2.5</servlet.api.version>
<ws.rs.version>2.0.1</ws.rs.version>
Expand Down