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
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,20 @@ public function create(RequestInterface $request): Entries
}

if (!empty($requestBodyContent)) {
switch ($requestType) {
case 'json':
if (class_exists(JsonEntry::class)) {
$decodedJson = type_array()->assert(json_decode(
$requestBodyEntry = match ($requestType) {
'json' => class_exists(JsonEntry::class)
? new JsonEntry(
'request_body',
Json::fromArray(type_array()->assert(json_decode(
$requestBodyContent,
true,
512,
JSON_THROW_ON_ERROR,
));

$requestBodyEntry = new JsonEntry('request_body', Json::fromArray($decodedJson));
} else {
$requestBodyEntry = string_entry('request_body', $requestBodyContent);
}

break;

default:
$requestBodyEntry = string_entry('request_body', $requestBodyContent);

break;
}
))),
)
: string_entry('request_body', $requestBodyContent),
default => string_entry('request_body', $requestBodyContent),
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,95 +95,58 @@ public function toParquet(Schema $schema): ParquetSchema
*/
private function flowToParquet(string $name, Type $type, bool $nullable): Column
{
switch ($type::class) {
case FloatType::class:
return FlatColumn::float(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case IntegerType::class:
return FlatColumn::int64(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case HTMLType::class:
case HTMLElementType::class:
case XMLElementType::class:
case XMLType::class:
case StringType::class:
return FlatColumn::string(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case BooleanType::class:
return FlatColumn::boolean(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case TimeType::class:
return FlatColumn::time(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case DateType::class:
return FlatColumn::date(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case DateTimeType::class:
return FlatColumn::datetime(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case UuidType::class:
return FlatColumn::uuid(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case JsonType::class:
return FlatColumn::json(
$name,
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case ListType::class:
$elementType = $type->element();
$elementOptional = $elementType instanceof OptionalType;
$elementType = $elementType instanceof OptionalType ? $elementType->base() : $elementType;

return NestedColumn::list(
$name,
new ListElement($this->flowToParquet('element', $elementType, $elementOptional)),
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case MapType::class:
$valueType = $type->value();
$valueOptional = $valueType instanceof OptionalType;
$valueType = $valueType instanceof OptionalType ? $valueType->base() : $valueType;

return NestedColumn::map(
$name,
new ParquetSchema\MapKey($this->flowToParquet('key', $type->key(), false)),
new ParquetSchema\MapValue($this->flowToParquet('value', $valueType, $valueOptional)),
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
case StructureType::class:
return NestedColumn::struct(
$name,
array_map(
function (int|string $elementName, Type $elementType) {
$elementOptional = $elementType instanceof OptionalType;
$elementType = $elementType instanceof OptionalType ? $elementType->base() : $elementType;

return $this->flowToParquet((string) $elementName, $elementType, $elementOptional);
},
array_keys($type->elements()),
$type->elements(),
),
$nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED,
);
}

throw new RuntimeException($type::class . ' is not supported.');
$repetition = $nullable ? ParquetSchema\Repetition::OPTIONAL : ParquetSchema\Repetition::REQUIRED;

return match ($type::class) {
FloatType::class => FlatColumn::float($name, $repetition),
IntegerType::class => FlatColumn::int64($name, $repetition),
HTMLType::class,
HTMLElementType::class,
XMLElementType::class,
XMLType::class,
StringType::class,
=> FlatColumn::string($name, $repetition),
BooleanType::class => FlatColumn::boolean($name, $repetition),
TimeType::class => FlatColumn::time($name, $repetition),
DateType::class => FlatColumn::date($name, $repetition),
DateTimeType::class => FlatColumn::datetime($name, $repetition),
UuidType::class => FlatColumn::uuid($name, $repetition),
JsonType::class => FlatColumn::json($name, $repetition),
ListType::class => NestedColumn::list(
$name,
new ListElement($this->flowToParquet(
'element',
$this->unwrapOptional($type->element()),
$type->element() instanceof OptionalType,
)),
$repetition,
),
MapType::class => NestedColumn::map(
$name,
new ParquetSchema\MapKey($this->flowToParquet('key', $type->key(), false)),
new ParquetSchema\MapValue($this->flowToParquet(
'value',
$this->unwrapOptional($type->value()),
$type->value() instanceof OptionalType,
)),
$repetition,
),
StructureType::class => NestedColumn::struct(
$name,
array_map(
function (int|string $elementName, Type $elementType) {
$elementOptional = $elementType instanceof OptionalType;
$elementType = $elementType instanceof OptionalType ? $elementType->base() : $elementType;

return $this->flowToParquet((string) $elementName, $elementType, $elementOptional);
},
array_keys($type->elements()),
$type->elements(),
),
$repetition,
),
default => throw new RuntimeException($type::class . ' is not supported.'),
};
}

/**
Expand Down Expand Up @@ -333,4 +296,14 @@ private function parquetToFlowType(Column $column): Type

return $nullable ? type_optional(type_structure($elements)) : type_structure($elements);
}

/**
* @param Type<mixed> $type
*
* @return Type<mixed>
*/
private function unwrapOptional(Type $type): Type
{
return $type instanceof OptionalType ? $type->base() : $type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,73 +102,60 @@ private function flag(Metadata $metadata, SealMetadata $key, bool $default): boo
*/
private function flowToSealField(string $name, Type $type, bool $multiple, Metadata $metadata): AbstractField
{
switch ($type::class) {
case EnumType::class:
case HTMLElementType::class:
case HTMLType::class:
case StringType::class:
case UuidType::class:
case XMLElementType::class:
case XMLType::class:
return new Field\TextField(
$name,
multiple: $multiple,
searchable: $this->flag($metadata, SealMetadata::SEARCHABLE, true),
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, false),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, false),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
);
case IntegerType::class:
return new Field\IntegerField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, true),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
);
case FloatType::class:
return new Field\FloatField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, true),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
);
case BooleanType::class:
return new Field\BooleanField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, false),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
);
case DateTimeType::class:
case DateType::class:
return new Field\DateTimeField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, true),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
);
case JsonType::class:
case MapType::class:
return new Field\JsonObjectField($name);
case ListType::class:
$element = $type->element();
$element = $element instanceof OptionalType ? $element->base() : $element;

return $this->flowToSealField($name, $element, true, $metadata);
case StructureType::class:
return new Field\ObjectField($name, $this->structureFields($type), multiple: $multiple);
}

throw new RuntimeException($type::class . ' is not supported.');
return match ($type::class) {
EnumType::class,
HTMLElementType::class,
HTMLType::class,
StringType::class,
UuidType::class,
XMLElementType::class,
XMLType::class,
=> new Field\TextField(
$name,
multiple: $multiple,
searchable: $this->flag($metadata, SealMetadata::SEARCHABLE, true),
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, false),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, false),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
),
IntegerType::class => new Field\IntegerField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, true),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
),
FloatType::class => new Field\FloatField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, true),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
),
BooleanType::class => new Field\BooleanField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, false),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
),
DateTimeType::class, DateType::class => new Field\DateTimeField(
$name,
multiple: $multiple,
filterable: $this->flag($metadata, SealMetadata::FILTERABLE, true),
sortable: $this->flag($metadata, SealMetadata::SORTABLE, true),
distinct: $this->flag($metadata, SealMetadata::DISTINCT, false),
facet: $this->flag($metadata, SealMetadata::FACET, false),
),
JsonType::class, MapType::class => new Field\JsonObjectField($name),
ListType::class => $this->flowToSealField($name, $this->unwrapOptional($type->element()), true, $metadata),
StructureType::class => new Field\ObjectField($name, $this->structureFields($type), multiple: $multiple),
default => throw new RuntimeException($type::class . ' is not supported.'),
};
}

/**
Expand Down Expand Up @@ -226,4 +213,14 @@ private function structureFields(StructureType $type): array

return $fields;
}

/**
* @param Type<mixed> $type
*
* @return Type<mixed>
*/
private function unwrapOptional(Type $type): Type
{
return $type instanceof OptionalType ? $type->base() : $type;
}
}
28 changes: 10 additions & 18 deletions src/core/etl/src/Flow/ETL/Dataset/Memory/Unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,16 @@ public static function fromString(string $memoryString): self

$unit = substr($limit, -1);

switch (strtoupper($unit)) {
case 'K':
case 'B':
return self::fromKb((int) substr($limit, 0, -1));
case 'M':
case 'MB':
return self::fromMb((int) substr($limit, 0, -1));
case 'G':
case 'GB':
return self::fromGb((int) substr($limit, 0, -1));

default:
if (ctype_digit($limit)) {
return self::fromBytes((int) $limit);
}

throw new InvalidArgumentException("Can't extract memory limit in bytes from php ini value: {$limit}");
}
return match (strtoupper($unit)) {
'K', 'B' => self::fromKb((int) substr($limit, 0, -1)),
'M', 'MB' => self::fromMb((int) substr($limit, 0, -1)),
'G', 'GB' => self::fromGb((int) substr($limit, 0, -1)),
default => ctype_digit($limit)
? self::fromBytes((int) $limit)
: throw new InvalidArgumentException(
"Can't extract memory limit in bytes from php ini value: {$limit}",
),
};
}

public function absolute(): self
Expand Down
Loading
Loading