flow php

DSL stands for Domain Specific Language. In the case of Flow, the DSL is used to define simple functions that can be used to transform data. Most of those functions are initializing a new instance of a class under the hood since Flow is fully object-oriented. Please look at the examples below to get a better understanding of how to use the DSL functions.

SCHEMA


/**
 * @param class-string<\UnitEnum> $type
 */
enum_schema(string $name, string $type, bool $nullable, ?Metadata $metadata) : Definition
float_schema(string $name, bool $nullable, int $precision, ?Metadata $metadata) : Definition
/**
 * Alias for `int_schema`.
 */
int_schema(string $name, bool $nullable, ?Metadata $metadata) : Definition
map_schema(string $name, MapType $type, ?Metadata $metadata) : Definition
/**
 * Alias for `string_schema`.
 */
str_schema(string $name, bool $nullable, ?Metadata $metadata) : Definition
xml_schema(string $name, bool $nullable, ?Metadata $metadata) : Definition

TYPE


/**
 * @param class-string<\UnitEnum> $class
 */
type_enum(string $class, bool $nullable) : EnumType
/**
 * @param Type<mixed> $element
 */
type_list(Type $element, bool $nullable) : ListType
/**
 * @param Type<mixed> $value_type
 */
type_map(StringType|IntegerType $key_type, Type $value_type, bool $nullable) : MapType
/**
 * @param class-string $class
 */
type_object(string $class, bool $nullable) : ObjectType
/**
 * @param array<string, Type<mixed>> $elements
 */
type_structure(array $elements, bool $nullable) : StructureType

ENTRY


date_entry(string $name, DateTimeInterface|string|null $value) : DateEntry
/**
 * @throws InvalidArgumentException
 */
json_object_entry(string $name, array|string|null $data) : JsonEntry
/**
 * @param list<mixed> $value
 */
list_entry(string $name, ?array $value, ListType $type) : ListEntry
/**
 * This functions is an alias for creating string entry from null.
 * The main difference between using this function an simply str_entry with second argument null
 * is that this function will also keep a note in the metadata that type might not be final.
 * For example when we need to guess column type from rows because schema was not provided,
 * and given column in the first row is null, it might still change once we get to the second row.
 * That metadata is used to determine if string_entry was created from null or not.
 *
 * By design flow assumes when guessing column type that null would be a string (the most flexible type).
 */
null_entry(string $name) : StringEntry

DATA_FRAME


/**
 * @param array<array<mixed>>|array<mixed|string> $data
 * @param array<Partition>|Partitions $partitions
 */
array_to_row(array $data, EntryFactory $entryFactory, Partitions|array $partitions, ?Schema $schema) : Row
/**
 * @param array<array<mixed>>|array<mixed|string> $data
 * @param array<Partition>|Partitions $partitions
 */
array_to_rows(array $data, EntryFactory $entryFactory, Partitions|array $partitions, ?Schema $schema) : Rows
/**
 * An alias for `ref`.
 */
col(string $entry) : EntryReference
/**
 * @param array<class-string<Entry<mixed, mixed>>, int> $priorities
 */
compare_entries_by_type(array $priorities, Order $order) : Comparator
/**
 * Alias for data_frame() : Flow.
 */
df(Config|ConfigBuilder|null $config) : Flow
/**
 * @param Entry<mixed, mixed> ...$entries
 */
entries(Entry $entries) : Entries
filesystem_cache(Path|string|null $cache_dir, Filesystem $filesystem, Serializer $serializer) : FilesystemCache
/**
 * @param array<string|Type<mixed>> $types
 * @param mixed $value
 */
is_type(array $types, ?mixed $value) : bool
join_on(Comparison|array $comparisons, string $join_prefix) : Expression
print_rows(Rows $rows, int|bool $truncate, ?Formatter $formatter) : string
random_string(ScalarFunction|int $length, RandomValueGenerator $generator) : RandomString
/**
 * @param Entry<mixed, mixed> ...$entry
 */
row(Entry $entry) : Row
/**
 * @param array<mixed> $data
 *
 * @return Entry<mixed, mixed>
 */
to_entry(string $name, ?mixed $data, EntryFactory $entryFactory) : Entry

EXTRACTOR


/**
 * @param int<1, max> $chunk_size
 */
chunks_from(Extractor $extractor, int $chunk_size) : ChunkExtractor
/**
 * @param iterable $array
 * @param null|Schema $schema - @deprecated use withSchema() method instead
 */
from_array(iterable $array, ?Schema $schema) : ArrayExtractor
/**
 * @param string $id - cache id from which data will be extracted
 * @param null|Extractor $fallback_extractor - extractor that will be used when cache is empty - @deprecated use withFallbackExtractor() method instead
 * @param bool $clear - clear cache after extraction - @deprecated use withClearOnFinish() method instead
 */
from_cache(string $id, ?Extractor $fallback_extractor, bool $clear) : CacheExtractor
from_sequence_date_period(string $entry_name, DateTimeInterface $start, DateInterval $interval, DateTimeInterface $end, int $options) : SequenceExtractor
from_sequence_number(string $entry_name, string|int|float $start, string|int|float $end, int|float $step) : SequenceExtractor

AGGREGATING_FUNCTION


string_agg(EntryReference|string $ref, string $separator, ?SortOrder $sort) : StringAggregate

SCALAR_FUNCTION


array_exists(ScalarFunction|array $ref, ScalarFunction|string $path) : ArrayPathExists
/**
 * Expands each value into entry, if there are more than one value, multiple rows will be created.
 * Array keys are ignored, only values are used to create new rows.
 *
 * Before:
 *   +--+-------------------+
 *   |id|              array|
 *   +--+-------------------+
 *   | 1|{"a":1,"b":2,"c":3}|
 *   +--+-------------------+
 *
 * After:
 *   +--+--------+
 *   |id|expanded|
 *   +--+--------+
 *   | 1|       1|
 *   | 1|       2|
 *   | 1|       3|
 *   +--+--------+
 */
array_expand(ScalarFunction $function, ArrayExpand $expand) : ArrayExpand
array_get(ScalarFunction $ref, ScalarFunction|string $path) : ArrayGet
array_key_rename(ScalarFunction $ref, ScalarFunction|string $path, ScalarFunction|string $newName) : ArrayKeyRename
array_merge(ScalarFunction|array $left, ScalarFunction|array $right) : ArrayMerge
array_reverse(ScalarFunction|array $function, ScalarFunction|bool $preserveKeys) : ArrayReverse
array_sort(ScalarFunction $function, ScalarFunction|Sort|null $sort_function, ScalarFunction|int|null $flags, ScalarFunction|bool $recursive) : ArraySort
/**
 * Unpacks each element of an array into a new entry, using the array key as the entry name.
 *
 * Before:
 * +--+-------------------+
 * |id|              array|
 * +--+-------------------+
 * | 1|{"a":1,"b":2,"c":3}|
 * | 2|{"d":4,"e":5,"f":6}|
 * +--+-------------------+
 *
 * After:
 * +--+-----+-----+-----+-----+-----+
 * |id|arr.b|arr.c|arr.d|arr.e|arr.f|
 * +--+-----+-----+-----+-----+-----+
 * | 1|    2|    3|     |     |     |
 * | 2|     |     |    4|    5|    6|
 * +--+-----+-----+-----+-----+-----+
 */
array_unpack(ScalarFunction|array $array, ScalarFunction|array $skip_keys, ScalarFunction|string|null $entry_prefix) : ArrayUnpack
between(?mixed $value, ?mixed $lower_bound, ?mixed $upper_bound, ScalarFunction|Boundary $boundary) : Between
/**
 * @param ScalarFunction|string|Type<mixed> $type
 */
cast(?mixed $value, ScalarFunction|Type|string $type) : Cast
combine(ScalarFunction|array $keys, ScalarFunction|array $values) : Combine
/**
 * Concat all values. If you want to concatenate values with separator use concat_ws function.
 */
concat(ScalarFunction|string $functions) : Concat
/**
 * Concat all values with separator.
 */
concat_ws(ScalarFunction|string $functions) : ConcatWithSeparator
/**
 * An alias for `ref`.
 */
entry(string $entry) : EntryReference
hash(?mixed $value, Algorithm $algorithm) : Hash
now(DateTimeZone|ScalarFunction $time_zone) : Now
number_format(ScalarFunction|int|float $value, ScalarFunction|int $decimals, ScalarFunction|string $decimal_separator, ScalarFunction|string $thousands_separator) : NumberFormat
regex(ScalarFunction|string $pattern, ScalarFunction|string $subject, ScalarFunction|int $flags, ScalarFunction|int $offset) : Regex
regex_all(ScalarFunction|string $pattern, ScalarFunction|string $subject, ScalarFunction|int $flags, ScalarFunction|int $offset) : RegexAll
regex_match(ScalarFunction|string $pattern, ScalarFunction|string $subject, ScalarFunction|int $flags, ScalarFunction|int $offset) : RegexMatch
regex_match_all(ScalarFunction|string $pattern, ScalarFunction|string $subject, ScalarFunction|int $flags, ScalarFunction|int $offset) : RegexMatchAll
regex_replace(ScalarFunction|string $pattern, ScalarFunction|string $replacement, ScalarFunction|string $subject, ScalarFunction|int|null $limit) : RegexReplace
round(ScalarFunction|int|float $value, ScalarFunction|int $precision, ScalarFunction|int $mode) : Round
sanitize(ScalarFunction|string $value, ScalarFunction|string $placeholder, ScalarFunction|int|null $skipCharacters) : Sanitize
split(ScalarFunction|string $value, ScalarFunction|string $separator, ScalarFunction|int $limit) : Split
sprintf(ScalarFunction|string $format, ScalarFunction|string|int|float|null $args) : Sprintf
to_date(?mixed $ref, ScalarFunction|string $format, ScalarFunction|DateTimeZone $timeZone) : ToDate
to_date_time(?mixed $ref, ScalarFunction|string $format, ScalarFunction|DateTimeZone $timeZone) : ToDateTime
to_timezone(ScalarFunction|DateTimeInterface $value, ScalarFunction|DateTimeZone|string $timeZone) : ToTimeZone
uuid_v7(ScalarFunction|DateTimeInterface|null $value) : Uuid
when(?mixed $condition, ?mixed $then, ?mixed $else) : When

WINDOW_FUNCTION


COMPARISON


equal(Reference|string $left, Reference|string $right) : Equal
identical(Reference|string $left, Reference|string $right) : Identical

HELPER


/**
 * Advanced type casting mechanism.
 * Usage:
 *
 * caster()->to(type_float(precision: 2))->value("1.1234") // 1.12
 *
 * Options can be also passed to "to" function to override default options.
 *
 * caster()->to(type_float(precision: 2), caster_options())->value("1.1234") // 1.12
 */
caster(?Options $options) : Caster

LOADER


/**
 * Convert rows to an array and store them in passed array variable.
 *
 * @param-out array<array<mixed>> $array
 */
to_array(array $array) : ArrayLoader
to_output(int|bool $truncate, Output $output, Formatter $formatter, SchemaFormatter $schemaFormatter) : StreamLoader
to_stderr(int|bool $truncate, Output $output, Formatter $formatter, SchemaFormatter $schemaFormatter) : StreamLoader
to_stdout(int|bool $truncate, Output $output, Formatter $formatter, SchemaFormatter $schemaFormatter) : StreamLoader
to_stream(string $uri, int|bool $truncate, Output $output, string $mode, Formatter $formatter, SchemaFormatter $schemaFormatter) : StreamLoader

Contributors

Join us on GitHub external resource
scroll back to top