diff --git a/ffi/examples/read-table/schema.h b/ffi/examples/read-table/schema.h index 6c074f55..29fac4b8 100644 --- a/ffi/examples/read-table/schema.h +++ b/ffi/examples/read-table/schema.h @@ -1,15 +1,16 @@ #include "delta_kernel_ffi.h" /** - * This module defines a very simple model of a schema, just used to be able to print the schema of + * This module defines a very simple model of a schema, used only to be able to print the schema of * a table. It consists of a "SchemaBuilder" which is our user data that gets passed into each visit_x * call. This simply keeps track of all the lists we are asked to allocate. * - * Each list is a "SchemaItemList", which just tracks its length an an array of "SchemaItem"s. + * Each list is a "SchemaItemList", which tracks its length an an array of "SchemaItem"s. * - * Each "SchemaItem" just has a name and a type, which are just strings. It can also have a list - * which is its children. This is initially always NULL, but when visiting a struct, map, or array, - * we point this at the list specified in the callback, which allows us to traverse the schema. + * Each "SchemaItem" has a name and a type, which are just strings. It can also have a list which is + * its children. This is initially always NULL, but when visiting a struct, map, or array, we point + * this at the list specified in the callback, which allows us to traverse the schema when printing + * it. Note that this points to one of the lists in the builder's set of lists and is not a copy. */ // If you want the visitor to print out what it's being asked to do at each step, uncomment the @@ -51,18 +52,19 @@ SchemaItem* add_to_list(SchemaItemList *list, char* name, char* type) { } // print out all items in a list, recursing into any children they may have -void print_list(SchemaItemList *list, int indent, bool last) { +void print_list(SchemaItemList *list, int indent, bool parent_on_last) { for (int i = 0; i < list->len; i++) { + bool is_last = i == list->len - 1; for (int j = 0; j <= indent; j++) { if (j == indent) { - if (i == list->len - 1) { + if (is_last) { printf("└"); } else { printf("├"); } } else { - if (last && j == indent - 1) { - // don't print a dangling | for my last item + if (parent_on_last && j == indent - 1) { + // don't print a dangling | on my parent's last item printf(" "); } else { printf("│ "); @@ -71,8 +73,7 @@ void print_list(SchemaItemList *list, int indent, bool last) { } printf("─ %s: %s\n", list->list[i].name, list->list[i].type); if (list->list[i].children) { - bool last = i == list->len - 1; - print_list(list->list[i].children, indent+1, last); + print_list(list->list[i].children, indent+1, is_last); } } }