Skip to content

Commit

Permalink
[KYLIN-4794] Make it possible to force hit a cube set for sqls with c…
Browse files Browse the repository at this point in the history
…ube join
  • Loading branch information
Ted-Jiang authored and hit-lacus committed Apr 6, 2021
1 parent 22322a0 commit e44aee2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import org.apache.calcite.linq4j.Enumerator;
import org.apache.kylin.common.debug.BackdoorToggles;
import org.apache.kylin.common.util.StringUtil;
import org.apache.kylin.cube.CubeInstance;
import org.apache.kylin.cube.CubeManager;
import org.apache.kylin.cube.model.DimensionDesc;
Expand Down Expand Up @@ -60,8 +65,22 @@ public LookupTableEnumerator(OLAPContext olapContext) {
List<RealizationEntry> realizationEntries = project.getRealizationEntries();
String lookupTableName = olapContext.firstTableScan.getTableName();
CubeManager cubeMgr = CubeManager.getInstance(cube.getConfig());
cube = cubeMgr.findLatestSnapshot(realizationEntries, lookupTableName, cube);
olapContext.realization = cube;

// Make force hit cube in lookup table
String forceHitCubeName = BackdoorToggles.getForceHitCube();
if (!StringUtil.isEmpty(forceHitCubeName)) {
String forceHitCubeNameLower = forceHitCubeName.toLowerCase(Locale.ROOT);
String[] forceHitCubeNames = forceHitCubeNameLower.split(",");
final Set<String> forceHitCubeNameSet = new HashSet<String>(Arrays.asList(forceHitCubeNames));
cube = cubeMgr.findLatestSnapshot(
(List<RealizationEntry>) realizationEntries.stream()
.filter(x -> forceHitCubeNameSet.contains(x.getRealization().toLowerCase(Locale.ROOT))),
lookupTableName, cube);
olapContext.realization = cube;
} else {
cube = cubeMgr.findLatestSnapshot(realizationEntries, lookupTableName, cube);
olapContext.realization = cube;
}
} else if (olapContext.realization instanceof HybridInstance) {
final HybridInstance hybridInstance = (HybridInstance) olapContext.realization;
final IRealization latestRealization = hybridInstance.getLatestRealization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@

package org.apache.kylin.query.routing;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.kylin.common.debug.BackdoorToggles;
import org.apache.kylin.common.util.StringUtil;
import org.apache.kylin.metadata.model.FunctionDesc;
import org.apache.kylin.metadata.realization.CapabilityResult;
import org.apache.kylin.metadata.realization.CapabilityResult.CapabilityInfluence;
Expand Down Expand Up @@ -50,15 +54,30 @@ public static IRealization selectRealization(OLAPContext olapContext, Set<IReali
String projectName = olapContext.olapSchema.getProjectName();
SQLDigest sqlDigest = olapContext.getSQLDigest();

List<Candidate> candidates = Lists.newArrayListWithCapacity(realizations.size());
String forceHitCubeName = BackdoorToggles.getForceHitCube();
Set<String> forceHitCubeNameSet = new HashSet<String>();
if (!StringUtil.isEmpty(forceHitCubeName)) {
String forceHitCubeNameLower = forceHitCubeName.toLowerCase(Locale.ROOT);
String[] forceHitCubeNames = forceHitCubeNameLower.split(",");
forceHitCubeNameSet = new HashSet<String>(Arrays.asList(forceHitCubeNames));
}

List<Candidate> candidates = Lists.newArrayList();
for (IRealization real : realizations) {
if (real.isReady())
candidates.add(new Candidate(real, sqlDigest));
if (BackdoorToggles.getForceHitCube() != null && BackdoorToggles.getForceHitCube().equalsIgnoreCase(real.getName())) {
logger.info("Force choose {} as selected cube for specific purpose.", real.getName());
candidates = Lists.newArrayListWithCapacity(1);
if (!forceHitCubeNameSet.isEmpty()) {
if (!forceHitCubeNameSet.contains(real.getName().toLowerCase(Locale.ROOT))) {
continue;
}
if (!real.isReady()) {
throw new RuntimeException(
"Realization " + real.getName() + " is not ready and should not be force hit");
}
candidates.add(new Candidate(real, sqlDigest));
break;
} else {
if (real.isReady()) {
candidates.add(new Candidate(real, sqlDigest));
}
}
}

Expand Down

0 comments on commit e44aee2

Please sign in to comment.