Relix.input(String, Input) to name as a relation.
Two kinds, which differ in what a second read of the relation does:
- Re-readable,
of(InputFormat, Supplier): the supplier is called for each scan, asRelix.source(java.lang.String, com.darkcollective.relix.symbol.Schema, java.util.function.Supplier<java.util.stream.Stream<com.darkcollective.relix.processor.Row>>)calls its own, so a query that reads the relation twice opens it twice. For a file. - Single-pass,
of(InputFormat, InputStream): the stream is read once. Its rows are kept as they are read, so a later scan — a second query, or a query reading the relation twice — replays them; reading a large stream more than once therefore holds it in memory. For standard input or a pipe.
With no declared heading the heading is inferred from the
first records: a delimited format's names come from its header row,
and JSON's from the keys the sample uses. A record after the sample whose value does
not fit the inferred type is an error naming it; declare the heading, or sample more.
An input is immutable; each method returns a new one.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHow many records a heading is inferred from unlesssample(int)says otherwise. -
Method Summary
Modifier and TypeMethodDescriptionformat()Returns how the text is written.booleanReturns whether each scan opens the text afresh, rather than reading one stream once.booleanReturns whether the input never ends.names()Returns the column names a headerless input was given, or empty when its first line is its header row.This input, read as text with no header row whose columns arecolumns, in order — their types inferred as for any heading, unless one isdeclared.static Inputof(InputFormat format, InputStream stream) A single-pass input:streamis read once, and closed by the session when it is finished with.static Inputof(InputFormat format, Supplier<InputStream> open) A re-readable input:openis called for each scan, and the engine closes what it returns.intsample()Returns how many records a heading is inferred from.sample(int records) This input, its heading inferred from the firstrecordsrecords.schema()Returns the declared heading, if one was.This input, read asheadingrather than an inferred one.This input, marked as never ending: a log followed as it is written, a feed.
-
Field Details
-
DEFAULT_SAMPLE
public static final int DEFAULT_SAMPLEHow many records a heading is inferred from unlesssample(int)says otherwise.- See Also:
-
-
Method Details
-
of
A re-readable input:openis called for each scan, and the engine closes what it returns.- Parameters:
format- how the text is written; must not be nullopen- opens the text afresh; must not be null- Returns:
- the input
- Since:
- 1.0
-
of
A single-pass input:streamis read once, and closed by the session when it is finished with.- Parameters:
format- how the text is written; must not be nullstream- the text; must not be null- Returns:
- the input
- Since:
- 1.0
-
schema
This input, read asheadingrather than an inferred one. A delimited format matches its header to the heading's names; JSON reads each name's key.- Parameters:
heading- the heading; must not be null- Returns:
- the input
- Since:
- 1.0
-
names
This input, read as text with no header row whose columns arecolumns, in order — their types inferred as for any heading, unless one isdeclared.Without names, a delimited input's first line is its header row, and one that has none cannot be read with an inferred heading: nothing else would name its columns.
- Parameters:
first- the first column's namemore- the rest, in order; each column is named once- Returns:
- the input
- Throws:
IllegalArgumentException- for a JSON format, whose columns are its keys, or for a name given twice- Since:
- 1.0
-
names
Returns the column names a headerless input was given, or empty when its first line is its header row.- Returns:
- the column names a headerless input was given, or empty when its first line is its header row
- Since:
- 1.0
-
sample
This input, its heading inferred from the firstrecordsrecords.- Parameters:
records- how many; at least 1- Returns:
- the input
- Since:
- 1.0
-
unbounded
This input, marked as never ending: a log followed as it is written, a feed.The engine then treats the relation as it treats any endless one: a query streams it, a row at a time, and one that would have to read all of it first — a sort, a grouping, a collecting terminal — is refused before it starts. A single-pass input marked so keeps nothing, and can be read by one scan only. A JSON array is one document and cannot be; read the stream as
InputFormat.NDJSON.- Returns:
- the input
- Throws:
IllegalArgumentException- for a JSON array- Since:
- 1.0
-
format
Returns how the text is written.- Returns:
- how the text is written
- Since:
- 1.0
-
schema
Returns the declared heading, if one was.- Returns:
- the declared heading, if one was
- Since:
- 1.0
-
sample
public int sample()Returns how many records a heading is inferred from.- Returns:
- how many records a heading is inferred from
- Since:
- 1.0
-
isUnbounded
public boolean isUnbounded()Returns whether the input never ends.- Returns:
- whether the input never ends
- Since:
- 1.0
-
isReReadable
public boolean isReReadable()Returns whether each scan opens the text afresh, rather than reading one stream once.- Returns:
- whether each scan opens the text afresh, rather than reading one stream once
- Since:
- 1.0
-