|
40 | 40 | import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySort; |
41 | 41 | import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySortBy; |
42 | 42 | import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySplit; |
| 43 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.Cardinality; |
43 | 44 | import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementAt; |
44 | 45 | import org.apache.doris.nereids.trees.expressions.functions.scalar.Lambda; |
| 46 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.Length; |
45 | 47 | import org.apache.doris.nereids.trees.expressions.functions.scalar.MapContainsEntry; |
46 | 48 | import org.apache.doris.nereids.trees.expressions.functions.scalar.MapContainsKey; |
47 | 49 | import org.apache.doris.nereids.trees.expressions.functions.scalar.MapContainsValue; |
48 | 50 | import org.apache.doris.nereids.trees.expressions.functions.scalar.MapKeys; |
| 51 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.MapSize; |
49 | 52 | import org.apache.doris.nereids.trees.expressions.functions.scalar.MapValues; |
50 | 53 | import org.apache.doris.nereids.trees.expressions.functions.scalar.StructElement; |
51 | 54 | import org.apache.doris.nereids.trees.expressions.literal.Literal; |
@@ -127,9 +130,75 @@ public Void visitSlotReference(SlotReference slotReference, CollectorContext con |
127 | 130 | int slotId = slotReference.getExprId().asInt(); |
128 | 131 | slotToAccessPaths.put(slotId, new CollectAccessPathResult(path, context.bottomFilter, context.type)); |
129 | 132 | } |
| 133 | + if (dataType.isStringLikeType()) { |
| 134 | + int slotId = slotReference.getExprId().asInt(); |
| 135 | + if (!context.accessPathBuilder.isEmpty()) { |
| 136 | + // Accessed via an offset-only function (e.g. length()). |
| 137 | + // Builder already has "offset" at the tail; add the column name as prefix. |
| 138 | + context.accessPathBuilder.addPrefix(slotReference.getName()); |
| 139 | + ImmutableList<String> path = ImmutableList.copyOf(context.accessPathBuilder.accessPath); |
| 140 | + slotToAccessPaths.put(slotId, |
| 141 | + new CollectAccessPathResult(path, context.bottomFilter, TAccessPathType.DATA)); |
| 142 | + } else { |
| 143 | + // Direct access to the string column → record a DATA path so that any |
| 144 | + // concurrent offset-only path for the same slot is suppressed. |
| 145 | + List<String> path = ImmutableList.of(slotReference.getName()); |
| 146 | + slotToAccessPaths.put(slotId, |
| 147 | + new CollectAccessPathResult(path, context.bottomFilter, TAccessPathType.DATA)); |
| 148 | + } |
| 149 | + } |
130 | 150 | return null; |
131 | 151 | } |
132 | 152 |
|
| 153 | + @Override |
| 154 | + public Void visitLength(Length length, CollectorContext context) { |
| 155 | + Expression arg = length.child(0); |
| 156 | + // length() only needs the offset array, not the chars data. |
| 157 | + // Add ACCESS_STRING_OFFSET as a suffix so the path builder accumulates |
| 158 | + // e.g. ["str_col", "OFFSET"] or ["c_struct", "f3", "OFFSET"]. |
| 159 | + if (arg.getDataType().isStringLikeType() && context.accessPathBuilder.isEmpty()) { |
| 160 | + CollectorContext offsetContext = |
| 161 | + new CollectorContext(context.statementContext, context.bottomFilter); |
| 162 | + offsetContext.accessPathBuilder.addSuffix(AccessPathInfo.ACCESS_STRING_OFFSET); |
| 163 | + return arg.accept(this, offsetContext); |
| 164 | + } |
| 165 | + // fall through to default (recurse into children with fresh contexts) |
| 166 | + return visit(length, context); |
| 167 | + } |
| 168 | + |
| 169 | + @Override |
| 170 | + public Void visitMapSize(MapSize mapSize, CollectorContext context) { |
| 171 | + Expression arg = mapSize.child(); |
| 172 | + DataType argType = arg.getDataType(); |
| 173 | + if (argType.isMapType() && context.accessPathBuilder.isEmpty()) { |
| 174 | + CollectorContext offsetContext = |
| 175 | + new CollectorContext(context.statementContext, context.bottomFilter); |
| 176 | + offsetContext.accessPathBuilder.addSuffix(AccessPathInfo.ACCESS_STRING_OFFSET); |
| 177 | + return arg.accept(this, offsetContext); |
| 178 | + } |
| 179 | + return visit(mapSize, context); |
| 180 | + } |
| 181 | + |
| 182 | + @Override |
| 183 | + public Void visitCardinality(Cardinality cardinality, CollectorContext context) { |
| 184 | + Expression arg = cardinality.child(0); |
| 185 | + // cardinality(arr) / cardinality(map) only needs the offset array, not element data. |
| 186 | + // Arrays and maps share the same offset-array + data storage layout as strings on the BE. |
| 187 | + DataType argType = arg.getDataType(); |
| 188 | + if ((argType.isArrayType() || argType.isMapType()) && context.accessPathBuilder.isEmpty()) { |
| 189 | + CollectorContext offsetContext = |
| 190 | + new CollectorContext(context.statementContext, context.bottomFilter); |
| 191 | + offsetContext.accessPathBuilder.addSuffix(AccessPathInfo.ACCESS_STRING_OFFSET); |
| 192 | + // cardinality(map_keys(m)) == cardinality(m) == cardinality(map_values(m)): |
| 193 | + // all three count map entries, so emit the same [map_col, OFFSET] path. |
| 194 | + Expression effectiveArg = (arg instanceof MapKeys || arg instanceof MapValues) |
| 195 | + ? arg.child(0) : arg; |
| 196 | + return effectiveArg.accept(this, offsetContext); |
| 197 | + } |
| 198 | + // fall through to default |
| 199 | + return visit(cardinality, context); |
| 200 | + } |
| 201 | + |
133 | 202 | @Override |
134 | 203 | public Void visitArrayItemSlot(ArrayItemSlot arrayItemSlot, CollectorContext context) { |
135 | 204 | if (nameToLambdaArguments.isEmpty()) { |
|
0 commit comments