Skip to content

Commit 3a19726

Browse files
committed
Dont truncate ascii table output schema
1 parent 919ee1c commit 3a19726

2 files changed

Lines changed: 81 additions & 4 deletions

File tree

src/core/etl/src/Flow/ETL/Row/Formatter/ASCIISchemaFormatter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,27 @@
1313

1414
final readonly class ASCIISchemaFormatter implements SchemaFormatter
1515
{
16-
public function __construct(private bool $asTable = false)
16+
public function __construct(private bool $asTable = false, private bool $withMetadata = true)
1717
{
1818
}
1919

2020
public function format(Schema $schema) : string
2121
{
2222
if ($this->asTable) {
2323
ob_start();
24-
df()
24+
$df = df()
2525
->read(from_array($schema->normalize()))
2626
->withEntry('type', ref('type')->unpack())
2727
->renameEach(rename_replace('type.', ''))
2828
->rename('ref', 'name')
2929
->collect()
30-
->select('name', 'type', 'nullable', 'metadata')
31-
->write(to_output())
30+
->select('name', 'type', 'nullable', 'metadata');
31+
32+
if (!$this->withMetadata) {
33+
$df->drop('metadata');
34+
}
35+
36+
$df->write(to_output(false))
3237
->run();
3338

3439
$content = ob_get_clean();

src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Formatter/ASCIISchemaFormatterTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,78 @@ public function test_format_nested_schema() : void
4949
);
5050
}
5151

52+
public function test_format_nested_schema_as_table() : void
53+
{
54+
$schema = schema(integer_schema('integer', true), integer_schema('float'), structure_schema('user', type_structure([
55+
'name' => type_string(true),
56+
'age' => type_int(),
57+
'address' => type_structure([
58+
'street' => type_string(true),
59+
'city' => type_string(true),
60+
'country' => type_string(true),
61+
]),
62+
])), string_schema('name', nullable: true), list_schema('tags', type_list(type_string())), bool_schema('active'), xml_schema('xml'), xml_element_schema('xml_element'), json_schema('json'), uuid_schema('uuid'), datetime_schema('datetime'));
63+
64+
self::assertSame(
65+
<<<'SCHEMA'
66+
+-------------+-------------+----------+----------+
67+
| name | type | nullable | metadata |
68+
+-------------+-------------+----------+----------+
69+
| integer | integer | true | [] |
70+
| float | integer | false | [] |
71+
| user | structure | false | [] |
72+
| name | string | true | [] |
73+
| tags | list | false | [] |
74+
| active | boolean | false | [] |
75+
| xml | xml | false | [] |
76+
| xml_element | xml_element | false | [] |
77+
| json | json | false | [] |
78+
| uuid | uuid | false | [] |
79+
| datetime | datetime | false | [] |
80+
+-------------+-------------+----------+----------+
81+
11 rows
82+
83+
SCHEMA,
84+
(new ASCIISchemaFormatter(true, true))->format($schema)
85+
);
86+
}
87+
88+
public function test_format_nested_schema_as_table_without_metadata() : void
89+
{
90+
$schema = schema(integer_schema('integer', true), integer_schema('float'), structure_schema('user', type_structure([
91+
'name' => type_string(true),
92+
'age' => type_int(),
93+
'address' => type_structure([
94+
'street' => type_string(true),
95+
'city' => type_string(true),
96+
'country' => type_string(true),
97+
]),
98+
])), string_schema('name', nullable: true), list_schema('tags', type_list(type_string())), bool_schema('active'), xml_schema('xml'), xml_element_schema('xml_element'), json_schema('json'), uuid_schema('uuid'), datetime_schema('datetime'));
99+
100+
self::assertSame(
101+
<<<'SCHEMA'
102+
+-------------+-------------+----------+
103+
| name | type | nullable |
104+
+-------------+-------------+----------+
105+
| integer | integer | true |
106+
| float | integer | false |
107+
| user | structure | false |
108+
| name | string | true |
109+
| tags | list | false |
110+
| active | boolean | false |
111+
| xml | xml | false |
112+
| xml_element | xml_element | false |
113+
| json | json | false |
114+
| uuid | uuid | false |
115+
| datetime | datetime | false |
116+
+-------------+-------------+----------+
117+
11 rows
118+
119+
SCHEMA,
120+
(new ASCIISchemaFormatter(true))->format($schema)
121+
);
122+
}
123+
52124
public function test_format_schema() : void
53125
{
54126
$schema = schema(string_schema('name', nullable: true), list_schema('tags', type_list(type_string())), bool_schema('active'), xml_schema('xml'), map_schema('map', type_map(type_string(), type_string())), list_schema('list', type_list(type_map(type_string(), type_integer()))));

0 commit comments

Comments
 (0)