-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DataFrame::schema method to just read schema from dataset (#925)
- Loading branch information
1 parent
e5d4aeb
commit 2253b91
Showing
7 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/SchemaTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\DataFrame; | ||
|
||
use function Flow\ETL\DSL\array_to_rows; | ||
use function Flow\ETL\DSL\bool_schema; | ||
use function Flow\ETL\DSL\df; | ||
use function Flow\ETL\DSL\from_rows; | ||
use function Flow\ETL\DSL\int_schema; | ||
use function Flow\ETL\DSL\schema; | ||
use function Flow\ETL\DSL\str_schema; | ||
use function Flow\ETL\DSL\union_schema; | ||
use Flow\ETL\Row\Entry\IntegerEntry; | ||
use Flow\ETL\Row\Entry\StringEntry; | ||
use Flow\ETL\Tests\Integration\IntegrationTestCase; | ||
|
||
final class SchemaTest extends IntegrationTestCase | ||
{ | ||
public function test_getting_schema() : void | ||
{ | ||
$rows = array_to_rows(\array_map( | ||
function ($i) { | ||
return [ | ||
'id' => $i, | ||
'name' => 'name_' . $i, | ||
'active' => $i % 2 === 0, | ||
]; | ||
}, | ||
\range(1, 100) | ||
)); | ||
|
||
$this->assertEquals( | ||
schema( | ||
int_schema('id'), | ||
str_schema('name'), | ||
bool_schema('active') | ||
), | ||
df() | ||
->read(from_rows($rows)) | ||
->autoCast() | ||
->schema() | ||
); | ||
} | ||
|
||
public function test_getting_schema_from_limited_rows() : void | ||
{ | ||
$rows = array_to_rows(\array_map( | ||
function ($i) { | ||
return [ | ||
'id' => $i, | ||
'name' => 'name_' . $i, | ||
'active' => $i % 2 === 0, | ||
'union' => $i > 50 ? 'string' : 1, | ||
]; | ||
}, | ||
\range(1, 100) | ||
)); | ||
|
||
$this->assertEquals( | ||
schema( | ||
int_schema('id'), | ||
str_schema('name'), | ||
bool_schema('active'), | ||
int_schema('union') | ||
), | ||
df() | ||
->read(from_rows($rows)) | ||
->autoCast() | ||
->limit(50) | ||
->schema() | ||
); | ||
} | ||
|
||
public function test_getting_schema_with_union_type() : void | ||
{ | ||
$rows = array_to_rows(\array_map( | ||
function ($i) { | ||
return [ | ||
'id' => $i, | ||
'name' => 'name_' . $i, | ||
'active' => $i % 2 === 0, | ||
'union' => $i > 50 ? 'string' : 1, | ||
]; | ||
}, | ||
\range(1, 100) | ||
)); | ||
|
||
$this->assertEquals( | ||
schema( | ||
int_schema('id'), | ||
str_schema('name'), | ||
bool_schema('active'), | ||
union_schema('union', [IntegerEntry::class, StringEntry::class]) | ||
), | ||
df() | ||
->read(from_rows($rows)) | ||
->autoCast() | ||
->schema() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters