Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed converting list of structures to parquet schema #900

Merged
merged 1 commit into from
Jan 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function flowListToParquetList(ListType $type) : ListElement
$this->flowMapValueToParquetMapValue($element->value())
);
case StructureType::class:
return ListElement::structure(...$this->flowStructureToParquetStructureElements($element));
return ListElement::structure($this->flowStructureToParquetStructureElements($element));
}

throw new RuntimeException($element::class . ' is not supported.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Flow\ETL\Adapter\Parquet\Tests\Unit;

use function Flow\ETL\DSL\type_boolean;
use function Flow\ETL\DSL\type_int;
use function Flow\ETL\DSL\type_object;
use function Flow\ETL\DSL\type_string;
use Flow\ETL\Adapter\Parquet\SchemaConverter;
Expand Down Expand Up @@ -44,6 +46,12 @@ public function test_convert_etl_entries_to_parquet_fields() : void
FlatColumn::dateTime('datetime'),
FlatColumn::string('json'),
NestedColumn::list('list', ParquetSchema\ListElement::string()),
NestedColumn::list('list_of_structs', ParquetSchema\ListElement::structure(
[
FlatColumn::int64('integer'),
FlatColumn::boolean('boolean'),
]
)),
NestedColumn::struct('structure', [FlatColumn::string('a')]),
NestedColumn::map('map', ParquetSchema\MapKey::string(), ParquetSchema\MapValue::int64()),
FlatColumn::time('time')
Expand All @@ -56,6 +64,12 @@ public function test_convert_etl_entries_to_parquet_fields() : void
Schema\Definition::dateTime('datetime'),
Schema\Definition::json('json'),
Schema\Definition::list('list', new ListType(ListElement::string())),
Schema\Definition::list('list_of_structs', new ListType(ListElement::structure(
new StructureType(
new StructureElement('integer', type_int()),
new StructureElement('boolean', type_boolean())
),
))),
Schema\Definition::structure('structure', new StructureType(new StructureElement('a', type_string()))),
Schema\Definition::map('map', new MapType(MapKey::string(), MapValue::integer())),
Schema\Definition::object('time', type_object(\DateInterval::class, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use function Flow\ETL\DSL\type_string;
use Flow\ETL\PHP\Type\Logical\ListType;
use Flow\ETL\PHP\Type\Logical\MapType;
use Flow\ETL\PHP\Type\Logical\StructureType;
use Flow\ETL\PHP\Type\Type;

final class ListElement
Expand Down Expand Up @@ -60,6 +61,11 @@ public static function string() : self
return new self(type_string(false));
}

public static function structure(StructureType $structure) : self
{
return new self($structure);
}

public function isEqual(mixed $value) : bool
{
return $this->value->isEqual($value);
Expand Down