src/sydra/query/value.zig
Purpose
Defines a runtime value representation used during query execution and expression evaluation.
See also
- Expression evaluation
- Operator pipeline
- pgwire server (formats
Valueinto text rows)
Definition index (public)
pub const ConvertError = error { ... }
TypeMismatch
pub const Value = union(enum)
Variants:
nullboolean: boolinteger: i64float: f64string: []const u8
Helpers:
isNull()asBool(),asFloat(),asInt(),asString()(type-checked conversions)equals(a, b)– equality across compatible numeric typescompareNumeric(a, b)– ordering comparison using float conversioncopySlice(allocator, values)– shallow copy a[]Valueslice
Conversion rules (as implemented)
asBoolaccepts only.boolean.asIntaccepts only.integer.asStringaccepts only.string.asFloataccepts:.floatas-is.integerby converting tof64
Equality rules (as implemented)
.integerand.floatcompare equal if theirf64values are equal.- Other mixed-type comparisons return
false.
Code excerpt
src/sydra/query/value.zig (Value + conversions excerpt)
pub const Value = union(enum) {
null,
boolean: bool,
integer: i64,
float: f64,
string: []const u8,
pub fn asFloat(self: Value) ConvertError!f64 {
return switch (self) {
.float => |f| f,
.integer => |i| @as(f64, @floatFromInt(i)),
else => ConvertError.TypeMismatch,
};
}
pub fn equals(a: Value, b: Value) bool {
return switch (a) {
.integer => |ai| switch (b) {
.integer => |bi| ai == bi,
.float => |bf| @as(f64, @floatFromInt(ai)) == bf,
else => false,
},
.float => |af| switch (b) {
.float => |bf| af == bf,
.integer => |bi| af == @as(f64, @floatFromInt(bi)),
else => false,
},
else => a == b,
};
}
};