* ExecInitJunkFilter * * Initialize the Junk filter. * * The source targetlist is passed in. The output tuple descriptor is * built from the non-junk tlist entries. * An optional resultSlot can be passed as well; otherwise, we create one. * An optional execFilterJunkFunc can be passed as well; otherwise, we use ExecFilterJunk. */
| 61 | * An optional execFilterJunkFunc can be passed as well; otherwise, we use ExecFilterJunk. |
| 62 | */ |
| 63 | JunkFilter * |
| 64 | ExecInitJunkFilter(List *targetList, TupleTableSlot *slot, |
| 65 | ExecFilterJunkFunc execFilterJunkFunc) |
| 66 | { |
| 67 | JunkFilter *junkfilter; |
| 68 | TupleDesc cleanTupType; |
| 69 | int cleanLength; |
| 70 | AttrNumber *cleanMap; |
| 71 | |
| 72 | /* |
| 73 | * Compute the tuple descriptor for the cleaned tuple. |
| 74 | */ |
| 75 | cleanTupType = ExecCleanTypeFromTL(targetList); |
| 76 | |
| 77 | /* |
| 78 | * Use the given slot, or make a new slot if we weren't given one. |
| 79 | */ |
| 80 | if (slot) |
| 81 | ExecSetSlotDescriptor(slot, cleanTupType); |
| 82 | else |
| 83 | slot = MakeSingleTupleTableSlot(cleanTupType, &TTSOpsVirtual); |
| 84 | |
| 85 | /* |
| 86 | * Now calculate the mapping between the original tuple's attributes and |
| 87 | * the "clean" tuple's attributes. |
| 88 | * |
| 89 | * The "map" is an array of "cleanLength" attribute numbers, i.e. one |
| 90 | * entry for every attribute of the "clean" tuple. The value of this entry |
| 91 | * is the attribute number of the corresponding attribute of the |
| 92 | * "original" tuple. (Zero indicates a NULL output attribute, but we do |
| 93 | * not use that feature in this routine.) |
| 94 | */ |
| 95 | cleanLength = cleanTupType->natts; |
| 96 | if (cleanLength > 0) |
| 97 | { |
| 98 | AttrNumber cleanResno; |
| 99 | ListCell *t; |
| 100 | |
| 101 | cleanMap = (AttrNumber *) palloc(cleanLength * sizeof(AttrNumber)); |
| 102 | cleanResno = 0; |
| 103 | foreach(t, targetList) |
| 104 | { |
| 105 | TargetEntry *tle = lfirst(t); |
| 106 | |
| 107 | if (!tle->resjunk) |
| 108 | { |
| 109 | cleanMap[cleanResno] = tle->resno; |
| 110 | cleanResno++; |
| 111 | } |
| 112 | } |
| 113 | Assert(cleanResno == cleanLength); |
| 114 | } |
| 115 | else |
| 116 | cleanMap = NULL; |
| 117 | |
| 118 | /* |
| 119 | * Finally create and initialize the JunkFilter struct. |
| 120 | */ |
no test coverage detected