Skip to content

Commit

Permalink
HPCC-32940 Allow keyed joins to conditional keys in roxie
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday committed Nov 5, 2024
1 parent bf3653d commit 5f17e0c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
17 changes: 15 additions & 2 deletions ecl/hqlcpp/hqlckey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,22 @@ IHqlExpression * KeyedJoinInfo::querySimplifiedKey(IHqlExpression * expr)
}
}

IHqlExpression * queryBaseIndexForKeyedJoin(IHqlExpression * expr)
{
if (expr->getOperator() == no_if)
{
IHqlExpression * left = queryBaseIndexForKeyedJoin(expr->queryChild(1));
IHqlExpression * right = queryBaseIndexForKeyedJoin(expr->queryChild(2));
if (left && right)
return left;
return nullptr;
}
return queryPhysicalRootTable(expr);
}

IHqlExpression * KeyedJoinInfo::createKeyFromComplexKey(IHqlExpression * expr)
{
IHqlExpression * base = queryPhysicalRootTable(expr);
IHqlExpression * base = queryBaseIndexForKeyedJoin(expr);
if (!base)
{
translator.throwError1(HQLERR_KeyedJoinNoRightIndex_X, getOpString(expr->getOperator()));
Expand Down Expand Up @@ -1232,7 +1245,7 @@ void HqlCppTranslator::buildKeyJoinIndexReadHelper(ActivityInstance & instance,
buildFilenameFunction(instance, instance.startctx, WaIndexname, "getIndexFileName", info->queryKeyFilename(), hasDynamicFilename(info->queryKey()));

//virtual IOutputMetaData * queryIndexRecordSize() = 0;
LinkedHqlExpr indexExpr = info->queryOriginalKey();
LinkedHqlExpr indexExpr = info->queryKey();
OwnedHqlExpr serializedRecord;
unsigned numPayload = numPayloadFields(indexExpr);
if (numPayload)
Expand Down
8 changes: 6 additions & 2 deletions roxie/ccd/ccdactivities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,12 @@ class CRoxieAgentActivity : implements CInterfaceOf<IRoxieAgentActivity>, implem
unsigned checksum;
serializedCreate.read(checksum);
OwnedRoxieString fname(queryDynamicFileName());
varFileInfo.setown(queryAgentDynamicFileCache()->lookupDynamicFile(logctx, fname, cacheDate, checksum, &packet->queryHeader(), isOpt, true));
setVariableFileInfo();
if (fname)
{
//fname may not be set if the index is being provided by another activity
varFileInfo.setown(queryAgentDynamicFileCache()->lookupDynamicFile(logctx, fname, cacheDate, checksum, &packet->queryHeader(), isOpt, true));
setVariableFileInfo();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions roxie/ccd/ccdfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3576,6 +3576,7 @@ class CAgentDynamicFileCache : implements IAgentDynamicFileCache, public CInterf

virtual IResolvedFile *lookupDynamicFile(const IRoxieContextLogger &logctx, const char *lfn, CDateTime &cacheDate, unsigned checksum, RoxiePacketHeader *header, bool isOpt, bool isLocal) override
{
assertex(lfn);
if (doTrace(traceRoxieFiles))
{
StringBuffer s;
Expand Down
13 changes: 12 additions & 1 deletion testing/regress/ecl/keyed_join6.ecl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
//version multiPart=true
//version multiPart=true,useLocal=true
//version multiPart=true,useTranslation=true
//version multiPart=false,conditional=true,nothor,nohthor
//version multiPart=true,conditional=true,nothor,nohthor

import ^ as root;
multiPart := #IFDEFINED(root.multiPart, true);
useLocal := #IFDEFINED(root.useLocal, true);
useTranslation := #IFDEFINED(root.useTranslation, false);
conditional := #IFDEFINED(root.conditional, false);

//--- end of version configuration ---

Expand All @@ -52,4 +55,12 @@ inDs := DATASET([
], inRecord);


output(JOIN(inDs, Files.DG_IntIndex, KEYED(RIGHT.DG_parentId = (integer)LEFT.s.v AND RIGHT.DG_parentId = LEFT.i.v)));
#if (conditional)
trueValue := true : stored('trueValue');
indexAlias := INDEX(Files.DG_IntIndex, 'indexAlias', OPT);
joinIndex := IF(trueValue, Files.DG_IntIndex, indexAlias);
#else
joinIndex := Files.DG_IntIndex;
#end

output(JOIN(inDs, joinIndex, KEYED(RIGHT.DG_parentId = (integer)LEFT.s.v AND RIGHT.DG_parentId = LEFT.i.v)));

0 comments on commit 5f17e0c

Please sign in to comment.