MCPcopy Create free account
hub / github.com/apache/impala / PrintStruct

Function PrintStruct

be/src/util/debug-util.cc:189–225  ·  view source on GitHub ↗

Print a struct with field names, recursing to children. This is not intended to work with impala_udf::StructVal. Instead, it works with the representation of structs that is directly inside another tuple. Example: {a:1,b:2}

Source from the content-addressed store, hash-verified

187// that is directly inside another tuple.
188// Example: {a:1,b:2}
189static void PrintStruct(const Tuple* t, const SlotDescriptor& slot_d, stringstream* out) {
190 DCHECK(t != nullptr);
191 DCHECK(slot_d.type().IsStructType());
192 const TupleDescriptor* child_tuple_d = slot_d.children_tuple_descriptor();
193 DCHECK(child_tuple_d != nullptr);
194 const ColumnType& struct_type = slot_d.type();
195 const std::vector<SlotDescriptor*>& child_slots = child_tuple_d->slots();
196 // The struct may have fields that are not being materialized, so the child_slots may
197 // be a subset of the actual struct type.
198 DCHECK_LE(child_slots.size(), struct_type.children.size());
199 *out << "{";
200 for (int i = 0; i < child_slots.size(); ++i) {
201 if (i != 0) {
202 *out << ",";
203 }
204 const SlotDescriptor& child_slot_desc = *child_slots[i];
205 // To find the struct field name, we need the index into the ColumnType's
206 // field_names. Structs can be partially materialized, so the slot's index
207 // is not correct. The struct_field_idx contains the appropriate index into
208 // the field_names.
209 if (child_slot_desc.struct_field_idx().has_value()) {
210 int struct_field_idx = child_slot_desc.struct_field_idx().value();
211 if (struct_field_idx < struct_type.field_names.size()) {
212 *out << struct_type.field_names[struct_field_idx] << ":";
213 } else {
214 // This is invalid. Assert on debug builds, but otherwise handle it for
215 // release builds.
216 DCHECK_LT(struct_field_idx, struct_type.field_names.size());
217 *out << "invalid" << i << ":";
218 }
219 } else {
220 *out << "unnamed" << i << ":";
221 }
222 PrintSlot(t, child_slot_desc, out);
223 }
224 *out << "}";
225}
226
227void PrintTuple(const Tuple* t, const TupleDescriptor& tuple_d, stringstream* out) {
228 // The whole tuple is null

Callers 1

PrintSlotFunction · 0.85

Calls 8

PrintSlotFunction · 0.85
IsStructTypeMethod · 0.80
has_valueMethod · 0.80
struct_field_idxMethod · 0.80
typeMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected