Skip to content

Commit fb6a2cf

Browse files
committed
Add virtual table & struct values
1 parent 671f0cb commit fb6a2cf

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

src/substrait/utils/display.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,29 @@ def _stream_read_rel(self, read: stalg.ReadRel, stream, depth: int):
183183
stream.write(
184184
f"{indent}{self._color('read:', Colors.GREEN)} {self._color(table_names[0] if len(table_names) == 1 else table_names, Colors.YELLOW)}\n"
185185
)
186+
elif read.HasField("virtual_table"):
187+
stream.write(
188+
f"{indent}{self._color('read:', Colors.GREEN)} {self._color('virtual_table', Colors.YELLOW)}\n"
189+
)
190+
if read.virtual_table.values:
191+
stream.write(
192+
f"{self._get_indent_with_arrow(depth + 1)}{self._color('values:', Colors.BLUE)} {self._color(len(read.virtual_table.values), Colors.YELLOW)}\n"
193+
)
194+
# Show the actual values, not just count
195+
for i, value in enumerate(read.virtual_table.values):
196+
# Handle struct values properly
197+
if hasattr(value, "fields"):
198+
stream.write(
199+
f"{self._get_indent_with_arrow(depth + 2)}value[{i}]: "
200+
)
201+
self._stream_struct_literal(
202+
value, stream, depth + 2, inline=True
203+
)
204+
else:
205+
stream.write(
206+
f"{self._get_indent_with_arrow(depth + 2)}value[{i}]: "
207+
)
208+
self._stream_literal_value(value, stream, depth + 2)
186209

187210
if read.HasField("base_schema"):
188211
# Capture schema names for field resolution
@@ -730,6 +753,53 @@ def _stream_literal_value(
730753
f"{indent}{self._color('<unknown_literal_type>', Colors.RED)}\n"
731754
)
732755

756+
def _stream_struct_literal(
757+
self, struct_literal, stream, depth: int, inline: bool = False
758+
):
759+
"""Print a struct literal value with proper indentation"""
760+
if inline:
761+
# When inline, don't add extra indentation since we're already on the same line
762+
indent = ""
763+
else:
764+
indent = " " * (depth * self.indent_size)
765+
766+
if hasattr(struct_literal, "fields") and struct_literal.fields:
767+
stream.write(f"{indent}{self._color('struct', Colors.BLUE)}\n")
768+
for i, field in enumerate(struct_literal.fields):
769+
# Show field index
770+
stream.write(f"{self._get_indent_with_arrow(depth + 1)}field[{i}]:\n")
771+
# Show the actual field value with proper indentation
772+
if hasattr(field, "i64"):
773+
stream.write(
774+
f"{self._get_indent_with_arrow(depth + 2)}{self._color('i64', Colors.BLUE)}: {self._color(field.i64, Colors.GREEN)}\n"
775+
)
776+
elif hasattr(field, "fp64"):
777+
stream.write(
778+
f"{self._get_indent_with_arrow(depth + 2)}{self._color('fp64', Colors.BLUE)}: {self._color(field.fp64, Colors.GREEN)}\n"
779+
)
780+
elif hasattr(field, "fp32"):
781+
stream.write(
782+
f"{self._get_indent_with_arrow(depth + 2)}{self._color('fp32', Colors.BLUE)}: {self._color(field.fp32, Colors.GREEN)}\n"
783+
)
784+
elif hasattr(field, "i32"):
785+
stream.write(
786+
f"{self._get_indent_with_arrow(depth + 2)}{self._color('i32', Colors.BLUE)}: {self._color(field.i32, Colors.GREEN)}\n"
787+
)
788+
elif hasattr(field, "string"):
789+
stream.write(
790+
f"{self._get_indent_with_arrow(depth + 2)}{self._color('string', Colors.BLUE)}: {self._color(f'"{field.string}"', Colors.GREEN)}\n"
791+
)
792+
elif hasattr(field, "boolean"):
793+
stream.write(
794+
f"{self._get_indent_with_arrow(depth + 2)}{self._color('boolean', Colors.BLUE)}: {self._color(field.boolean, Colors.GREEN)}\n"
795+
)
796+
else:
797+
stream.write(
798+
f"{self._get_indent_with_arrow(depth + 2)}{self._color('<unknown_field_type>', Colors.RED)}\n"
799+
)
800+
else:
801+
stream.write(f"{indent}{self._color('empty_struct', Colors.YELLOW)}\n")
802+
733803
def _type_to_string(self, type_info: stt.Type) -> str:
734804
"""Convert a type to a concise string representation"""
735805
if type_info.HasField("bool"):

0 commit comments

Comments
 (0)