addColumn(path, simpleValueType(s), parent, isArray);
return;
}
if (seen.containsKey(s)) // catch recursion
throw new TrevniRuntimeException("Cannot shred recursive schemas: "+s);
seen.put(s, s);
switch (s.getType()) {
case MAP:
path = path == null ? ">" : path+">";
int start = columns.size();
ColumnMetaData p = addColumn(path, ValueType.NULL, parent, true);
addColumn(p(path,"key", ""), ValueType.STRING, p, false);
columnize(p(path,"value", ""), s.getValueType(), p, false);
arrayWidths.set(start, columns.size()-start); // fixup with actual width
break;
case RECORD:
for (Field field : s.getFields()) // flatten fields to columns
columnize(p(path, field.name(), "#"), field.schema(), parent, isArray);
break;
case ARRAY:
path = path == null ? "[]" : path+"[]";
addArrayColumn(path, s.getElementType(), parent);
break;
case UNION:
for (Schema branch : s.getTypes()) // array per non-null branch
if (branch.getType() != Schema.Type.NULL)
addArrayColumn(p(path, branch, "/"), branch, parent);
break;
default:
throw new TrevniRuntimeException("Unknown schema: "+s);
}
}