Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklan committed May 2, 2024
1 parent 00f6309 commit 86534d7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ffi/examples/read-table/schema.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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("│ ");
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 86534d7

Please sign in to comment.