Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @norberttech
6 changes: 5 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<!-- Bellow section will be used to automatically generate changelog, please do not modify HTML code structure -->
<!--
Below section will be used to automatically generate changelog, please do not modify HTML code structure
DO NOT REMOVE that HTML STRUCTURE, INSTEAD ADD YOUR CHANGES INSIDE THE LISTS
PULL REQUESTS WITHOUT CHANGELOG CAN'T BE MERGED
-->
<h2>Change Log</h2>
<div id="change-log">
<h4>Added</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function format() : void
foreach ($columnsStatistics->all() as $columnStatistics) {
$normalizedColumnStatistics[] = [
'name' => $columnStatistics->name(),
'type' => $columnStatistics->type()->toString(),
'type' => $schema ? $schema->get($columnStatistics->reference())->type()->toString() : 'N/A',
'nulls_count' => $valueFormatter->format($columnStatistics->nullCount()),
'distinct_count' => $valueFormatter->format($columnStatistics->distinctCount()),
'min' => $valueFormatter->format($columnStatistics->min()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function test_read_rows_csv() : void
│ order_id │ uuid │ 0 │ 5 │ - │ - │ - │ - │ - │ - │
│ created_at │ datetime │ 0 │ 5 │ 2024-02-23T19:18:53+00:00 │ 2024-06-17T19:24:49+00:00 │ - │ - │ - │ - │
│ updated_at │ datetime │ 0 │ 5 │ 2024-02-23T19:18:53+00:00 │ 2024-06-17T19:24:49+00:00 │ - │ - │ - │ - │
│ discount │ float │ 2 │ 3 │ 12.45 │ 47.10 │ - │ - │ - │ - │
│ discount │ ?float │ 2 │ 3 │ 12.45 │ 47.10 │ - │ - │ - │ - │
│ address │ map<string, string> │ 0 │ 5 │ - │ - │ - │ - │ 4 │ 4 │
│ notes │ list<string> │ 0 │ 5 │ - │ - │ - │ - │ 1 │ 5 │
│ items │ list<structure{sku: string, quantity: integer, price: float}> │ 0 │ 5 │ - │ - │ - │ - │ 2 │ 4 │
Expand All @@ -67,4 +67,49 @@ public function test_read_rows_csv() : void

self::assertStringContainsString("Execution Time", $tester->getDisplay());
}

public function test_read_rows_csv_without_schema() : void
{
$application = new Application();
$application->add(new FileAnalyzeCommand());
$tester = new CommandTester($application->get('file:analyze'));

$tester->execute(['input-file' => __DIR__ . '/Fixtures/orders.csv', '--input-file-limit' => 5, '--stats-columns' => true]);

$tester->assertCommandIsSuccessful();

self::assertStringContainsString(
<<<'OUTPUT'
Analyzing File
==============

[INFO] File path: orders.csv
OUTPUT,
$tester->getDisplay()
);

self::assertStringContainsString(
<<<'OUTPUT'
Columns
-------

┌────────────┬──────┬───────┬─────────────────┬───────────────────────────┬───────────────────────────┬────────────┬────────────┬────────────────────┬────────────────────┐
│ Name │ Type │ Nulls │ Distinct Values │ Min │ Max │ Min Length │ Max Length │ Min Elements Count │ Max Elements Count │
├────────────┼──────┼───────┼─────────────────┼───────────────────────────┼───────────────────────────┼────────────┼────────────┼────────────────────┼────────────────────┤
│ order_id │ N/A │ 0 │ 5 │ - │ - │ - │ - │ - │ - │
│ created_at │ N/A │ 0 │ 5 │ 2024-02-23T19:18:53+00:00 │ 2024-06-17T19:24:49+00:00 │ - │ - │ - │ - │
│ updated_at │ N/A │ 0 │ 5 │ 2024-02-23T19:18:53+00:00 │ 2024-06-17T19:24:49+00:00 │ - │ - │ - │ - │
│ discount │ N/A │ 2 │ 3 │ 12.45 │ 47.10 │ - │ - │ - │ - │
│ address │ N/A │ 0 │ 5 │ - │ - │ - │ - │ 4 │ 4 │
│ notes │ N/A │ 0 │ 5 │ - │ - │ - │ - │ 1 │ 5 │
│ items │ N/A │ 0 │ 5 │ - │ - │ - │ - │ 2 │ 4 │
└────────────┴──────┴───────┴─────────────────┴───────────────────────────┴───────────────────────────┴────────────┴────────────┴────────────────────┴────────────────────┘
OUTPUT,
$tester->getDisplay()
);

self::assertStringContainsString("Analyzed Rows", $tester->getDisplay());

self::assertStringContainsString("Execution Time", $tester->getDisplay());
}
}
21 changes: 10 additions & 11 deletions src/core/etl/src/Flow/ETL/Dataset/Statistics/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Flow\ETL\Dataset\Statistics;

use Flow\ETL\PHP\Type\Type;
use Flow\ETL\Row\Entry;
use Flow\ETL\Row\{Entry, Reference};

final class Column
{
Expand All @@ -25,23 +24,26 @@ final class Column

private int $nullsCount = 0;

private readonly Reference $reference;

/**
* @param Entry<mixed, mixed> $entry
*
* @throws \JsonException
*/
public function __construct(public readonly Entry $entry)
public function __construct(Entry $entry)
{
$this->reference = $entry->ref();
$this->distinctCounter = new DistinctCounter();
$this->calculate($this->entry);
$this->calculate($entry);
}

/**
* @param Entry<mixed, mixed> $entry
*/
public function calculate(Entry $entry) : void
{
if (!$entry->is($this->entry->name())) {
if (!$this->reference->is($entry->ref())) {
return;
}

Expand Down Expand Up @@ -134,19 +136,16 @@ public function minLength() : ?int

public function name() : string
{
return $this->entry->name();
return $this->reference->name();
}

public function nullCount() : int
{
return $this->nullsCount;
}

/**
* @return Type<mixed>
*/
public function type() : Type
public function reference() : Reference
{
return $this->entry->type();
return $this->reference;
}
}