// requires: caseForOuterJoins corresponds the slot "slotNum" // effects: Adds a WhenThen corresponding to child to caseForOuterJoins. private void AddCaseForOuterJoins(CaseStatement caseForOuterJoins, CqlBlock child, int slotNum, CqlIdentifiers identifiers) { // Determine the cells that the slot comes from // and make an OR expression, e.g., WHEN _from0 or _from2 or ... THEN child[slotNum] ProjectedSlot childSlot = child.SlotValue(slotNum); ConstantProjectedSlot constantSlot = childSlot as ConstantProjectedSlot; if (constantSlot != null && constantSlot.CellConstant.IsNull()) { // NULL being generated by a child - don't need to project return; } BoolExpression originBool = BoolExpression.False; for (int i = 0; i < NumBoolSlots; i++) { int boolSlotNum = BoolIndexToSlot(i); if (child.IsProjected(boolSlotNum)) { // OR it to the expression QualifiedCellIdBoolean boolExpr = new QualifiedCellIdBoolean(child, identifiers, i); originBool = BoolExpression.CreateOr(originBool, BoolExpression.CreateLiteral(boolExpr, RightDomainMap)); } } // Qualify the slotNum with the child.CqlAlias for the THEN QualifiedSlot slot = child.QualifySlotWithBlockAlias(slotNum); caseForOuterJoins.AddWhenThen(originBool, slot); }
// requires: children to be a list of nodes that are children of an // Inner Join node. slotNum does not correspond to the key slot // effects: Determines the child number from which the slot should be // picked up. private static int GetInnerJoinChildForSlot(List <CqlBlock> children, int slotNum) { // Picks the child with the non-constant slot first. If none, picks a non-null constant slot. // If not een that, picks any one int result = -1; for (int i = 0; i < children.Count; i++) { CqlBlock child = children[i]; if (false == child.IsProjected(slotNum)) { continue; } ProjectedSlot slot = child.SlotValue(slotNum); ConstantProjectedSlot constantSlot = slot as ConstantProjectedSlot; MemberProjectedSlot joinSlot = slot as MemberProjectedSlot; if (joinSlot != null) { // Pick the non-constant slot result = i; } else if (constantSlot != null && constantSlot.CellConstant.IsNull()) { if (result == -1) { // In case, all are null result = i; } } else { // Just pick anything result = i; } } return(result); }
private SlotInfo[] CreateSlotInfosForCaseStatement( bool[] parentRequiredSlots, int foundSlot, CqlBlock childBlock, CaseStatement thisCaseStatement, IEnumerable <WithRelationship> withRelationships) { int num = childBlock.Slots.Count - this.TotalSlots; SlotInfo[] slotInfoArray = new SlotInfo[this.TotalSlots + num]; for (int slotNum = 0; slotNum < this.TotalSlots; ++slotNum) { bool isProjected = childBlock.IsProjected(slotNum); bool parentRequiredSlot = parentRequiredSlots[slotNum]; ProjectedSlot slotValue = childBlock.SlotValue(slotNum); MemberPath outputMemberPath = this.GetOutputMemberPath(slotNum); if (slotNum == foundSlot) { slotValue = (ProjectedSlot) new CaseStatementProjectedSlot(thisCaseStatement.DeepQualify(childBlock), withRelationships); isProjected = true; } else if (isProjected && parentRequiredSlot) { slotValue = (ProjectedSlot)childBlock.QualifySlotWithBlockAlias(slotNum); } SlotInfo slotInfo = new SlotInfo(parentRequiredSlot && isProjected, isProjected, slotValue, outputMemberPath); slotInfoArray[slotNum] = slotInfo; } for (int totalSlots = this.TotalSlots; totalSlots < this.TotalSlots + num; ++totalSlots) { QualifiedSlot qualifiedSlot = childBlock.QualifySlotWithBlockAlias(totalSlots); slotInfoArray[totalSlots] = new SlotInfo(true, true, (ProjectedSlot)qualifiedSlot, childBlock.MemberPath(totalSlots)); } return(slotInfoArray); }
private void AddCaseForOuterJoins( CaseStatement caseForOuterJoins, CqlBlock child, int slotNum, CqlIdentifiers identifiers) { ConstantProjectedSlot constantProjectedSlot = child.SlotValue(slotNum) as ConstantProjectedSlot; if (constantProjectedSlot != null && constantProjectedSlot.CellConstant.IsNull()) { return; } BoolExpression or = BoolExpression.False; for (int index = 0; index < this.NumBoolSlots; ++index) { int slot = this.BoolIndexToSlot(index); if (child.IsProjected(slot)) { QualifiedCellIdBoolean qualifiedCellIdBoolean = new QualifiedCellIdBoolean(child, identifiers, index); or = BoolExpression.CreateOr(or, BoolExpression.CreateLiteral((BoolLiteral)qualifiedCellIdBoolean, this.RightDomainMap)); } } QualifiedSlot qualifiedSlot = child.QualifySlotWithBlockAlias(slotNum); caseForOuterJoins.AddWhenThen(or, (ProjectedSlot)qualifiedSlot); }
private static int GetInnerJoinChildForSlot(List <CqlBlock> children, int slotNum) { int num = -1; for (int index = 0; index < children.Count; ++index) { CqlBlock child = children[index]; if (child.IsProjected(slotNum)) { ProjectedSlot projectedSlot = child.SlotValue(slotNum); ConstantProjectedSlot constantProjectedSlot = projectedSlot as ConstantProjectedSlot; if (projectedSlot is MemberProjectedSlot) { num = index; } else if (constantProjectedSlot != null && constantProjectedSlot.CellConstant.IsNull()) { if (num == -1) { num = index; } } else { num = index; } } } return(num); }
// <summary> // Given the slot (<paramref name="foundSlot" />) and its corresponding case statement ( // <paramref // name="thisCaseStatement" /> // ), // generates the slotinfos for the cql block producing the case statement. // </summary> private SlotInfo[] CreateSlotInfosForCaseStatement( bool[] parentRequiredSlots, int foundSlot, CqlBlock childBlock, CaseStatement thisCaseStatement, IEnumerable <WithRelationship> withRelationships) { var numSlotsAddedByChildBlock = childBlock.Slots.Count - TotalSlots; var slotInfos = new SlotInfo[TotalSlots + numSlotsAddedByChildBlock]; for (var slotNum = 0; slotNum < TotalSlots; slotNum++) { var isProjected = childBlock.IsProjected(slotNum); var isRequiredByParent = parentRequiredSlots[slotNum]; var slot = childBlock.SlotValue(slotNum); var outputMember = GetOutputMemberPath(slotNum); if (slotNum == foundSlot) { // We need a case statement instead for this slot that we // are handling right now Debug.Assert(isRequiredByParent, "Case result not needed by parent"); // Get a case statement with all slots replaced by aliases slots var newCaseStatement = thisCaseStatement.DeepQualify(childBlock); slot = new CaseStatementProjectedSlot(newCaseStatement, withRelationships); isProjected = true; // We are projecting this slot now } else if (isProjected && isRequiredByParent) { // We only alias something that is needed and is being projected by the child. // It is a qualified slot into the child block. slot = childBlock.QualifySlotWithBlockAlias(slotNum); } // For slots, if it is not required by the parent, we want to // set the isRequiredByParent for this slot to be // false. Furthermore, we do not want to introduce any "NULL // AS something" at this stage for slots not being // projected. So if the child does not project that slot, we // declare it as not being required by the parent (if such a // NULL was needed, it would have been pushed all the way // down to a non-case block. // Essentially, from a Case statement's parent perspective, // it is saying "If you can produce a slot either by yourself // or your children, please do. Otherwise, do not concoct anything" var slotInfo = new SlotInfo(isRequiredByParent && isProjected, isProjected, slot, outputMember); slotInfos[slotNum] = slotInfo; } for (var i = TotalSlots; i < TotalSlots + numSlotsAddedByChildBlock; i++) { var childAddedSlot = childBlock.QualifySlotWithBlockAlias(i); slotInfos[i] = new SlotInfo(true, true, childAddedSlot, childBlock.MemberPath(i)); } return(slotInfos); }