Schema implements Countable
Interfaces
- Countable
Methods
- __construct() : mixed
- add() : Schema
- addAfter() : Schema
- Inserts definitions immediately after an existing column.
- addBefore() : Schema
- Inserts definitions immediately before an existing column.
- addMetadata() : Schema
- Adds metadata to a given definition.
- count() : int
- definitions() : array<string, Definition<string|int, mixed>>
- findDefinition() : null|Definition<string|int, mixed>
- fromArray() : self
- fromPipeline() : self
- Detecting schema from the pipeline has several disadvantages.
- get() : Definition<string|int, mixed>
- gracefulRemove() : self
- Gracefully remove entries from schema without throwing an exception if entry does not exist.
- insertAt() : Schema
- Inserts definitions at an explicit position. Index 0 prepends, an index equal to the number of definitions appends.
- isSame() : bool
- keep() : Schema
- makeNullable() : self
- Makes all schema definitions nullable.
- merge() : self
- moveAfter() : Schema
- Moves an existing column to immediately after another column, preserving its definition.
- moveBefore() : Schema
- Moves an existing column to immediately before another column, preserving its definition.
- moveTo() : Schema
- Moves an existing column to an explicit position, preserving its definition.
- normalize() : array<string|int, array<string|int, mixed>>
- prepend() : Schema
- Inserts definitions at the beginning of the schema.
- references() : References
- remove() : Schema
- rename() : Schema
- reorder() : Schema
- Reorders columns by name. Any columns not listed keep their relative order and are appended.
- replace() : Schema
- setMetadata() : Schema
- Overwrites metadata for a given definition.
- sort() : Schema
Methods
__construct()
public
__construct(Definition<string|int, mixed> ...$definitions) : mixed
Parameters
- $definitions : Definition<string|int, mixed>
add()
public
add(Definition<string|int, mixed> ...$definitions) : Schema
Parameters
- $definitions : Definition<string|int, mixed>
Return values
SchemaaddAfter()
Inserts definitions immediately after an existing column.
public
addAfter(string|Reference $reference, Definition<string|int, mixed> ...$definitions) : Schema
Parameters
- $reference : string|Reference
- $definitions : Definition<string|int, mixed>
Tags
Return values
SchemaaddBefore()
Inserts definitions immediately before an existing column.
public
addBefore(string|Reference $reference, Definition<string|int, mixed> ...$definitions) : Schema
Parameters
- $reference : string|Reference
- $definitions : Definition<string|int, mixed>
Tags
Return values
SchemaaddMetadata()
Adds metadata to a given definition.
public
addMetadata(string $definition, string $name, array<string|int, mixed>|bool|float|int|string $value) : Schema
Parameters
- $definition : string
- $name : string
- $value : array<string|int, mixed>|bool|float|int|string
Tags
Return values
Schemacount()
public
count() : int
Return values
intdefinitions()
public
definitions() : array<string, Definition<string|int, mixed>>
Return values
array<string, Definition<string|int, mixed>>findDefinition()
public
findDefinition(string|Reference $ref) : null|Definition<string|int, mixed>
Parameters
- $ref : string|Reference
Return values
null|Definition<string|int, mixed>fromArray()
public
static fromArray(array<string|int, mixed> $definitions) : self
Parameters
- $definitions : array<string|int, mixed>
Return values
selffromPipeline()
Detecting schema from the pipeline has several disadvantages.
public
static fromPipeline(Pipeline $pipeline, FlowContext $context[, int $maxRows = 1000 ]) : self
First of all, it's expensive, it needs to iterate through the pipeline until it detects types of all columns. In some cases, when a given column is null in the first 1k rows it will anyway return incorrect schema since row 1001 might have an actual value. When dealing with schemaless file formats like CSV or JSON even when first 1k rows will carry value of one type, there is zero guarantee that following rows will do the same.
Whenever it's possible, it's recommended to define schema upfront and pass it to the extractor. This way, whatever process would need to use this method, will do just one iteration.
Parameters
- $pipeline : Pipeline
- $context : FlowContext
- $maxRows : int = 1000
Return values
selfget()
public
get(string|Reference $ref) : Definition<string|int, mixed>
Parameters
- $ref : string|Reference
Tags
Return values
Definition<string|int, mixed>gracefulRemove()
Gracefully remove entries from schema without throwing an exception if entry does not exist.
public
gracefulRemove(string|Reference ...$entries) : self
Parameters
- $entries : string|Reference
Return values
selfinsertAt()
Inserts definitions at an explicit position. Index 0 prepends, an index equal to the number of definitions appends.
public
insertAt(int $index, Definition<string|int, mixed> ...$definitions) : Schema
Parameters
- $index : int
- $definitions : Definition<string|int, mixed>
Tags
Return values
SchemaisSame()
public
isSame(self $schema) : bool
Parameters
- $schema : self
Return values
boolkeep()
public
keep(string|Reference ...$entries) : Schema
Parameters
- $entries : string|Reference
Return values
SchemamakeNullable()
Makes all schema definitions nullable.
public
makeNullable() : self
Return values
selfmerge()
public
merge(self $schema) : self
Parameters
- $schema : self
Return values
selfmoveAfter()
Moves an existing column to immediately after another column, preserving its definition.
public
moveAfter(string|Reference $name, string|Reference $reference) : Schema
Parameters
Tags
Return values
SchemamoveBefore()
Moves an existing column to immediately before another column, preserving its definition.
public
moveBefore(string|Reference $name, string|Reference $reference) : Schema
Parameters
Tags
Return values
SchemamoveTo()
Moves an existing column to an explicit position, preserving its definition.
public
moveTo(string|Reference $name, int $index) : Schema
The index is the final position of the column in the resulting schema.
Parameters
- $name : string|Reference
- $index : int
Tags
Return values
Schemanormalize()
public
normalize() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>prepend()
Inserts definitions at the beginning of the schema.
public
prepend(Definition<string|int, mixed> ...$definitions) : Schema
Parameters
- $definitions : Definition<string|int, mixed>
Return values
Schemareferences()
public
references() : References
Return values
Referencesremove()
public
remove(string|Reference ...$entries) : Schema
Parameters
- $entries : string|Reference
Return values
Schemarename()
public
rename(string|Reference $entry, string $newName) : Schema
Parameters
- $entry : string|Reference
- $newName : string
Return values
Schemareorder()
Reorders columns by name. Any columns not listed keep their relative order and are appended.
public
reorder(string|Reference ...$names) : Schema
Parameters
- $names : string|Reference
Tags
Return values
Schemareplace()
public
replace(string|Reference $entry, Definition<string|int, mixed> $definition) : Schema
Parameters
- $entry : string|Reference
- $definition : Definition<string|int, mixed>
Return values
SchemasetMetadata()
Overwrites metadata for a given definition.
public
setMetadata(string $definition, Metadata $metadata) : Schema
Parameters
- $definition : string
- $metadata : Metadata
Tags
Return values
Schemasort()
public
sort([SortingStrategy $strategy = new AlphabeticalStrategy() ]) : Schema
Parameters
- $strategy : SortingStrategy = new AlphabeticalStrategy()