From 5f17e0cec952da70c39b219db6ea6e2fd0812420 Mon Sep 17 00:00:00 2001 From: Gavin Halliday Date: Mon, 4 Nov 2024 18:03:27 +0000 Subject: [PATCH] HPCC-32940 Allow keyed joins to conditional keys in roxie Signed-off-by: Gavin Halliday --- ecl/hqlcpp/hqlckey.cpp | 17 +++++++++++++++-- roxie/ccd/ccdactivities.cpp | 8 ++++++-- roxie/ccd/ccdfile.cpp | 1 + testing/regress/ecl/keyed_join6.ecl | 13 ++++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/ecl/hqlcpp/hqlckey.cpp b/ecl/hqlcpp/hqlckey.cpp index f04c2cad29b..8f310120e0d 100644 --- a/ecl/hqlcpp/hqlckey.cpp +++ b/ecl/hqlcpp/hqlckey.cpp @@ -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())); @@ -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) diff --git a/roxie/ccd/ccdactivities.cpp b/roxie/ccd/ccdactivities.cpp index 01a3fa91d90..25404c2dffd 100644 --- a/roxie/ccd/ccdactivities.cpp +++ b/roxie/ccd/ccdactivities.cpp @@ -362,8 +362,12 @@ class CRoxieAgentActivity : implements CInterfaceOf, 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(); + } } } diff --git a/roxie/ccd/ccdfile.cpp b/roxie/ccd/ccdfile.cpp index 4afccfd77f6..9f627e91bee 100644 --- a/roxie/ccd/ccdfile.cpp +++ b/roxie/ccd/ccdfile.cpp @@ -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; diff --git a/testing/regress/ecl/keyed_join6.ecl b/testing/regress/ecl/keyed_join6.ecl index e14d8e4d6ed..7b8b2f8e9a9 100644 --- a/testing/regress/ecl/keyed_join6.ecl +++ b/testing/regress/ecl/keyed_join6.ecl @@ -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 --- @@ -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)));