17#ifndef A11_FLOW_VALUES_H_
18#define A11_FLOW_VALUES_H_
32#include <absl/base/nullability.h>
33#include <absl/container/flat_hash_map.h>
34#include <absl/container/inlined_vector.h>
35#include <absl/numeric/int128.h>
36#include <absl/status/status.h>
37#include <absl/status/statusor.h>
38#include <absl/time/time.h>
39#include <absl/types/span.h>
71 [[nodiscard]]
virtual std::string
Tag()
const = 0;
73 [[nodiscard]]
virtual std::string
Text()
const = 0;
75 [[nodiscard]]
virtual bool Truthy()
const = 0;
77 [[nodiscard]]
virtual std::optional<size_t>
Size()
const = 0;
85 [[nodiscard]]
virtual std::optional<Value>
FindField(
86 std::string_view
name)
const;
87 [[nodiscard]]
virtual std::optional<Value>
FindElement(
101 [[nodiscard]] std::string
Tag()
const override;
102 [[nodiscard]] std::string
Text()
const override;
103 [[nodiscard]]
bool Truthy()
const override;
104 [[nodiscard]] std::optional<size_t>
Size()
const override;
107 [[nodiscard]] std::optional<Value>
FindField(
108 std::string_view
name)
const override;
123 [[nodiscard]] std::string
Tag()
const override;
124 [[nodiscard]] std::string
Text()
const override;
125 [[nodiscard]]
bool Truthy()
const override;
126 [[nodiscard]] std::optional<size_t>
Size()
const override;
129 [[nodiscard]] std::optional<Value>
FindField(
130 std::string_view
name)
const override;
184 static Value List(std::vector<Value>
items, std::string_view element_type);
186 static Value Status(absl::Status status, Pairs fields);
194 static Value Host(std::shared_ptr<const HostObject>
object);
217 [[nodiscard]]
bool boolean()
const;
219 [[nodiscard]] std::int64_t
integer()
const;
221 [[nodiscard]]
double number()
const;
223 [[nodiscard]] absl::uint128
magnitude()
const;
225 [[nodiscard]]
bool negative()
const {
return negative_; }
235 [[nodiscard]]
const std::string&
text()
const;
237 [[nodiscard]]
const std::vector<Value>&
items()
const;
245 [[nodiscard]]
const Pairs&
pairs()
const;
247 [[nodiscard]]
const absl::Status* absl_nullable
native_status()
const;
249 [[nodiscard]] absl::Duration
duration()
const;
251 [[nodiscard]] absl::Time
time()
const;
257 [[nodiscard]]
const std::shared_ptr<const HostObject>&
host_object()
const;
260 [[nodiscard]]
const Value* absl_nullable
Get(std::string_view
key)
const;
272 using TextPtr = std::shared_ptr<const std::string>;
273 using ListPtr = std::shared_ptr<const std::vector<Value>>;
274 using PackedListPtr = std::shared_ptr<const PackedList>;
275 using WindowListPtr = std::shared_ptr<const WindowList>;
276 using ObjectPtr = std::shared_ptr<const Pairs>;
277 using StatusPtr = std::shared_ptr<const StatusPayload>;
278 using ChunkPtr = std::shared_ptr<const data::Chunk>;
279 using HostPtr = std::shared_ptr<const HostObject>;
281 std::variant<std::monostate, bool, std::int64_t, double, absl::uint128,
282 absl::Duration, absl::Time, std::string, TextPtr, ListPtr,
283 PackedListPtr, WindowListPtr, ObjectPtr, StatusPtr, ChunkPtr,
287 bool option_ =
false;
288 bool negative_ =
false;
289 bool numeric_signed_ =
true;
290 bool legacy_number_ =
false;
291 std::uint8_t numeric_bits_ = 0;
306 std::deque<Value> small_;
307 std::shared_ptr<Block> previous_;
308 std::shared_ptr<Block> current_;
312 :
public absl::InlinedVector<std::pair<std::string, Value>, 2> {
314 using absl::InlinedVector<std::pair<std::string, Value>, 2>::InlinedVector;
333 virtual absl::StatusOr<Value>
Coerce(std::string_view tag,
345 std::string_view declared_type)
const;
350 absl::Span<const data::Chunk* const> chunks) {
351 std::vector<absl::StatusOr<Value>> values;
352 values.reserve(chunks.size());
364 virtual std::vector<absl::StatusOr<data::Chunk>>
ToChunks(
365 absl::Span<const Value* const> values, std::string_view
mimetype) {
366 std::vector<absl::StatusOr<data::Chunk>> chunks;
367 chunks.reserve(values.size());
407int Order(
const Value& left,
const Value& right);
414absl::StatusOr<Value>
Add(
const Value& left,
const Value& right);
435absl::StatusOr<Value>
MatchPattern(std::string_view pattern,
476std::string
TimeText(absl::Time
value, std::string_view spec = {});
533 absl::flat_hash_map<std::string, pattern::Pattern>
patterns;
534 absl::flat_hash_map<std::string, FormatTemplate>
formats;
535 absl::flat_hash_map<const syntax::Node*, Value>
folded;
540 std::function<absl::StatusOr<std::optional<Value>>(
const syntax::Node&)>
544 const absl::flat_hash_map<const syntax::Node*, Value>* absl_nullable
bound =
563 const EvalContext& context);
572 const syntax::TypeExpression&
type,
573 const CoerceContext& context);
590 const CoerceContext& context);
What the process running a flow knows and the language does not.
Definition values.h:325
virtual std::vector< absl::StatusOr< data::Chunk > > ToChunks(absl::Span< const Value *const > values, std::string_view mimetype)
Chunks holding values, in order, each with its own outcome.
Definition values.h:364
virtual absl::StatusOr< Value > Coerce(std::string_view tag, const Value &value)=0
Make value a value of the type tag names.
virtual ~HostBridge()=default
virtual bool CanPassChunkObject(const data::Chunk &chunk, std::string_view declared_type) const
Whether a typed port can retain this local object without conversion.
Definition values.cc:1408
virtual std::vector< absl::StatusOr< Value > > FromChunks(absl::Span< const data::Chunk *const > chunks)
Reads a batch in order, retaining a separate result for each chunk.
Definition values.h:349
virtual absl::StatusOr< Value > FromChunk(const data::Chunk &chunk)=0
The value chunk holds.
virtual absl::StatusOr< data::Chunk > ToChunk(const Value &value, std::string_view mimetype)=0
A chunk holding value, in mimetype when one is asked for.
virtual absl::StatusOr< Value > Adopt(const DtoPlan &shape, const Program &program, const Value &value)
Adopts a validated value of a declared shape for the host.
Definition values.h:376
A value only the host knows what to do with.
Definition values.h:66
virtual bool Truthy() const =0
Whether the value counts as true.
virtual Value Field(std::string_view name) const =0
value.name, or a null value when there is no such field.
virtual std::optional< Value > FindElement(const Value &key) const
Definition values.cc:1424
virtual std::string Tag() const =0
The tag the host knows this type by, for a message.
virtual ~HostObject()=default
virtual std::optional< size_t > Size() const =0
How many things it holds, where that means anything.
virtual Value Element(const Value &key) const =0
value[key].
virtual std::optional< Value > FindField(std::string_view name) const
A field or element with its presence retained, including a null value.
Definition values.cc:1419
virtual bool Equals(const HostObject &other) const =0
Whether this is the same value as other, by the host's own equality.
virtual std::string Text() const =0
What as_text gives: what the value is on the wire, not its repr.
A typed raw fragment carried through a fragment-view Flow pipeline.
Definition values.h:116
bool Equals(const HostObject &other) const override
Whether this is the same value as other, by the host's own equality.
Definition values.cc:750
std::optional< Value > FindField(std::string_view name) const override
A field or element with its presence retained, including a null value.
Definition values.cc:742
bool Truthy() const override
Whether the value counts as true.
Definition values.cc:709
Value Element(const Value &key) const override
value[key].
Definition values.cc:738
std::string Tag() const override
The tag the host knows this type by, for a message.
Definition values.cc:701
const data::NodeFragment & fragment() const
Definition values.h:121
Value Field(std::string_view name) const override
value.name, or a null value when there is no such field.
Definition values.cc:717
NodeFragmentObject(data::NodeFragment fragment)
Definition values.h:118
std::optional< size_t > Size() const override
How many things it holds, where that means anything.
Definition values.cc:713
std::string Text() const override
What as_text gives: what the value is on the wire, not its repr.
Definition values.cc:705
A typed reference carried through a fragment-view Flow pipeline.
Definition values.h:94
std::string Text() const override
What as_text gives: what the value is on the wire, not its repr.
Definition values.cc:653
bool Equals(const HostObject &other) const override
Whether this is the same value as other, by the host's own equality.
Definition values.cc:696
Value Field(std::string_view name) const override
value.name, or a null value when there is no such field.
Definition values.cc:665
NodeReferenceObject(data::NodeRef reference)
Definition values.h:96
std::string Tag() const override
The tag the host knows this type by, for a message.
Definition values.cc:649
bool Truthy() const override
Whether the value counts as true.
Definition values.cc:657
std::optional< Value > FindField(std::string_view name) const override
A field or element with its presence retained, including a null value.
Definition values.cc:687
Value Element(const Value &key) const override
value[key].
Definition values.cc:683
const data::NodeRef & reference() const
Definition values.h:99
std::optional< size_t > Size() const override
How many things it holds, where that means anything.
Definition values.cc:661
An immutable Flow value with shared containers and long text.
Definition values.h:139
static Value Null()
Definition values.h:172
bool has_packed_element_type(std::string_view name) const
Definition values.cc:1005
bool is_legacy_number() const
Definition values.h:231
static Value Bool(bool value)
Definition values.cc:1082
static Value TypedFloat(double value, int bits)
Definition values.cc:1115
const std::vector< Value > & items() const
Definition values.cc:975
static Value LegacyNumber(Value value)
Definition values.cc:1123
static Value List(std::vector< Value > items)
Definition values.cc:1148
static Value Bytes(data::Bytes value)
Definition values.cc:1144
const std::shared_ptr< const HostObject > & host_object() const
Definition values.cc:1059
bool negative() const
Definition values.h:225
std::int64_t integer() const
Definition values.cc:955
static Value Object(Pairs pairs)
Definition values.cc:1253
const HostObject & host() const
Definition values.cc:1055
Kind kind() const
Definition values.h:198
const absl::Status *absl_nullable native_status() const
Definition values.cc:1035
const Value *absl_nullable Get(std::string_view key) const
The value at key of an object, or nullptr.
Definition values.cc:1332
static Value String(std::string value)
Definition values.cc:1140
static Value Status(absl::Status status, Pairs fields)
Definition values.cc:1074
bool IsTimelike() const
Definition values.h:207
bool IsNumber() const
Definition values.h:202
double number() const
Definition values.cc:959
Value list_at(size_t index) const
Definition values.cc:995
absl::uint128 magnitude() const
Definition values.cc:963
static Value Integer(std::int64_t value)
Definition values.cc:1089
static Value Double(double value)
Definition values.cc:1096
bool boolean() const
Definition values.cc:951
size_t list_size() const
Definition values.cc:985
const std::string & text() const
Definition values.cc:967
static Value Host(std::shared_ptr< const HostObject > object)
Definition values.cc:1288
static Value Of(const syntax::Constant &constant)
The value a Constant – a literal, or a folded literal expression – is.
Definition values.cc:1298
bool numeric_signed() const
Definition values.h:227
static Value Option(std::optional< Value > value)
Definition values.cc:1063
Kind
Definition values.h:141
@ kChunk
An undecoded chunk, kept whole so a pipe that only moves values re-writes the producer's own bytes an...
@ kNull
A value that is not there: an absent key, an empty stream, a missing header.
absl::Duration duration() const
Definition values.cc:1043
bool IsTextlike() const
Whether the value is one the language itself can take apart: a string or a byte string,...
Definition values.h:213
friend bool operator==(const Value &left, const Value &right)
Whether the two values are equal, as == in a flow decides it.
Definition values.cc:1344
bool is_option() const
Definition values.h:189
const data::Chunk & chunk() const
Definition values.cc:1051
bool IsNull() const
Definition values.h:200
const Pairs & pairs() const
Definition values.cc:1027
static Value TypedInteger(absl::uint128 magnitude, bool negative, int bits, bool is_signed)
Definition values.cc:1104
absl::Time time() const
Definition values.cc:1047
static Value Chunk(data::Chunk chunk)
Definition values.cc:1280
int numeric_bits() const
Definition values.h:229
Builds immutable overlapping lists from append-only blocks.
Definition values.h:296
std::optional< Value > Push(Value value)
Definition values.cc:894
std::string value
Definition discover.cc:100
std::string key
Definition discover.cc:764
std::optional< std::string > text
The text, where the value is a string literal or a name bound to one.
Definition discover.cc:596
std::vector< std::string > arguments
argv for the program, [0] = path.
Definition main.cc:136
std::string Bytes
Raw byte payload; an alias of std::string.
Definition types.h:56
Definition catalogue.cc:29
std::vector< FormatPart > FormatTemplate
Definition values.h:526
std::string StrformatCompiled(const FormatTemplate &parts, absl::Span< const Value > arguments)
Definition values.cc:2234
double DurationSeconds(absl::Duration value)
A duration as a number of seconds, for every duration there is.
Definition values.cc:1911
Value StatusRecord(const absl::Status &status)
A status as the record a flow sees when it looks at an outcome.
Definition values.cc:3926
Value MatchCompiled(const pattern::Pattern &compiled, std::string_view subject)
The same, against a pattern already compiled.
Definition values.cc:1699
std::optional< absl::StatusCode > StatusCodeOf(const Value &value)
The canonical code value names, by name or by number, or nullopt.
Definition values.cc:3952
Value FailureRecord(const absl::Status &status, Value item, std::int64_t seq)
A tolerated stage failure, with the original item and zero-based position.
Definition values.cc:3945
absl::StatusOr< Value > Evaluate(const syntax::Node &node, const EvalContext &context)
Evaluate one expression.
Definition values.cc:3666
absl::StatusOr< Value > Add(const Value &left, const Value &right)
left + right, as an expression means it.
Definition values.cc:3659
std::unique_ptr< HostBridge > NativeHostBridge()
A host bridge backed by the C++ serialization registry.
Definition values.cc:1404
Value AsJson(const Value &value)
Text parsed as JSON; anything already decoded is left alone.
Definition values.cc:1868
absl::StatusOr< Value > MatchPattern(std::string_view text, std::string_view subject)
The fields a pattern pulls out of subject, or null where it does not fit.
Definition values.cc:1689
std::optional< std::int64_t > ExactInt64(const Value &value)
Definition values.cc:1645
std::string DurationText(absl::Duration value, std::string_view spec)
A duration as text: 1m30s by default, or one unit when spec names one.
Definition values.cc:1947
double AsDouble(const Value &value)
AsNumber as a double, for the places that only want the magnitude.
Definition values.cc:1657
Value Lookup(const Value &value, const Value &key)
Take key out of value: a mapping key, an index, or a field.
Definition values.cc:1476
std::string JsonText(const Value &value)
Renders JSON with sorted keys, spaced separators, and escaped non-ASCII.
Definition values.cc:1903
absl::StatusOr< Value > CoerceShape(const DtoPlan &shape, const Value &value, const CoerceContext &context)
Make value a value of shape: fill its defaults, check its bounds, and coerce every field to the type ...
Definition values.cc:3028
absl::StatusOr< Value > LookupChecked(const Value &value, const Value &key)
Definition values.cc:1465
int Order(const Value &left, const Value &right)
Where two values sit relative to one another: -1, 0 or 1.
Definition values.cc:3655
Value AsNumber(const Value &value)
value as a number, or zero when there is nothing to read.
Definition values.cc:1578
absl::Duration AsDuration(const Value &value)
A duration from a duration, from written text, or from seconds.
Definition values.cc:1921
FormatTemplate CompileStrformat(std::string_view text)
Definition values.cc:2227
bool Truthy(const Value &value)
Whether value counts as true, as an if and a where decide it.
Definition values.cc:1515
absl::StatusOr< Value > Coerce(const Value &value, const syntax::TypeExpression &type, const CoerceContext &context)
Make value a value of the type type names.
Definition values.cc:3074
std::string Strformat(const Value &format, absl::Span< const Value > arguments)
format with each % conversion replaced by one of arguments.
Definition values.cc:2243
absl::Status StatusOfRecord(const Value &record)
The status a record like the one above describes.
Definition values.cc:3980
std::string AsText(const Value &value)
value as text, the way the text stage and builtin render it.
Definition values.cc:1544
absl::StatusOr< Value > CallBuiltin(std::string_view name, absl::Span< const Value > arguments, HostBridge *absl_nullable bridge, const PreparedExpressions *prepared)
Definition values.cc:2299
std::optional< Value > LookupOptional(const Value &value, const Value &key)
Definition values.cc:1432
absl::Time AsTime(const Value &value)
An instant from an instant, from RFC 3339 text, or from epoch seconds.
Definition values.cc:1934
Value Truncate(const Value &value, std::int64_t size)
The first size of a value: characters, bytes, elements or pairs.
Definition values.cc:1876
std::string TimeText(absl::Time value, std::string_view spec)
An instant as text: RFC 3339 in UTC, a strftime pattern, or epoch.
Definition values.cc:2003
absl::Duration Duration
A11 duration; an alias of absl::Duration (nanosecond-aware).
Definition time.h:40
absl::Time Time
A11 instant; an alias of absl::Time (nanosecond-aware).
Definition time.h:42
std::string subject
What to call it in the message: ‘'Source’, orthe pattern`.
Definition resolve.cc:6292
std::string shape
Declared shape of stream values, retained through compatible stages.
Definition resolve.cc:814
graph::RefId node
Graph ref for this result, or [graph::kNone] without a resolved ref.
Definition resolve.cc:809
std::uint32_t seq
Definition sqlite_chunk_store.cc:186
std::string mimetype
Definition sqlite_chunk_store.cc:191
A unit of data: bytes plus optional descriptive metadata.
Definition types.h:173
One piece of a node's stream: an inline chunk or a node reference.
Definition types.h:366
A reference to a (slice of a) logical node, in lieu of inline data.
Definition types.h:311
What coercion needs besides the value and the type.
Definition values.h:503
const Program *absl_nullable shapes
Definition values.h:505
bool allow_temporal_text
Definition values.h:506
HostBridge *absl_nullable bridge
Definition values.h:504
One compiled struct: a shape a port may be typed with.
Definition plan.h:87
std::function< absl::StatusOr< Value >(const syntax::Builtin &)> reference
Definition values.h:542
std::function< absl::StatusOr< std::optional< Value > >(const syntax::Node &)> lookup
Definition values.h:541
HostBridge *absl_nullable bridge
Definition values.h:549
const absl::flat_hash_map< const syntax::Node *, Value > *absl_nullable bound
Definition values.h:544
const Program *absl_nullable shapes
The shapes the program declared, for a cast written inside an expression.
Definition values.h:551
std::function< bool(const syntax::Node &)> is_option
Definition values.h:543
bool has_it
Definition values.h:548
Value it
The value a where/map/group stage is looking at.
Definition values.h:547
const PreparedExpressions *absl_nullable prepared
Definition values.h:539
CoerceContext Coercion() const
Definition values.h:553
Immutable, bounded literal preparation shared by execution activations.
Definition values.h:532
absl::flat_hash_map< const syntax::Node *, Value > folded
Definition values.h:535
absl::flat_hash_map< std::string, pattern::Pattern > patterns
Definition values.h:533
absl::flat_hash_map< std::string, FormatTemplate > formats
Definition values.h:534
Every flow and shape one source file declares.
Definition plan.h:200
name(arg, ...) – one of the language's fixed functions.
Definition syntax.h:278
A literal or folded literal expression, including nested lists and objects.
Definition syntax.h:62
Base of every syntax node: what it is, and where it started.
Definition syntax.h:179
Output format
Definition main.cc:65
A11's core wire value types: chunks, node fragments and messages.
bool is_signed
Definition values.cc:65
int bits
Definition values.cc:64