Condition with index instead of member_name

Condition now store the index of the value in the file instead of the
member_name. So when I parse, I can just use the list array []Data and
the index to compare both value
This commit is contained in:
Adrien Bouvais 2024-10-27 22:34:17 +01:00
parent 304ec89167
commit 294d4f7a2c
4 changed files with 21 additions and 8 deletions

View File

@ -1069,7 +1069,7 @@ pub const FileEngine = struct {
/// Get the type of the member
pub fn memberName2DataType(self: *FileEngine, struct_name: []const u8, member_name: []const u8) FileEngineError!DataType {
var i: u16 = 0;
var i: usize = 0;
for (try self.structName2structMembers(struct_name)) |mn| {
const dtypes = try self.structName2DataType(struct_name);
@ -1080,9 +1080,20 @@ pub const FileEngine = struct {
return FileEngineError.MemberNotFound;
}
pub fn memberName2DataIndex(self: *FileEngine, struct_name: []const u8, member_name: []const u8) FileEngineError!usize {
var i: usize = 0;
for (try self.structName2structMembers(struct_name)) |mn| {
if (std.mem.eql(u8, mn, member_name)) return i;
i += 1;
}
return FileEngineError.MemberNotFound;
}
/// Get the list of all member name for a struct name
pub fn structName2structMembers(self: *FileEngine, struct_name: []const u8) FileEngineError![][]const u8 {
var i: u16 = 0;
var i: usize = 0;
while (i < self.struct_array.items.len) : (i += 1) if (std.mem.eql(u8, self.struct_array.items[i].name, struct_name)) break;

View File

@ -38,7 +38,7 @@ pub const Parser = struct {
name: []const u8,
members: std.ArrayList([]const u8),
types: std.ArrayList(DataType),
links: std.StringHashMap([]const u8),
links: std.StringHashMap([]const u8), // Map key as member_name and value as struct_name, like a dtype
pub fn init(allocator: Allocator, name: []const u8) SchemaStruct {
return SchemaStruct{

View File

@ -47,11 +47,10 @@ const LogicalOperator = enum {
};
pub const Condition = struct {
member_name: []const u8 = undefined,
value: []const u8 = undefined,
operation: ComparisonOperator = undefined,
data_type: DataType = undefined,
// data_index: usize TODO: add this member, this is the position in the row of the value, to use in the evaluate method
data_index: usize = undefined, // Index in the file
};
const FilterNode = union(enum) {
@ -196,8 +195,8 @@ pub const Filter = struct {
self.printNode(logical.right.*);
std.debug.print(" ) ", .{});
},
.condition => |condition| std.debug.print("{s} {s} {s} |{any}|", .{
condition.member_name,
.condition => |condition| std.debug.print("{d} {s} {s} |{any}|", .{
condition.data_index,
condition.operation.str(),
condition.value,
condition.data_type,

View File

@ -542,7 +542,10 @@ pub const Parser = struct {
struct_name,
self.toker.getTokenSlice(token),
) catch return ZiQlParserError.MemberNotFound;
condition.member_name = self.toker.getTokenSlice(token);
condition.data_index = self.file_engine.memberName2DataIndex(
struct_name,
self.toker.getTokenSlice(token),
) catch return ZiQlParserError.MemberNotFound;
state = State.expect_operation;
},
else => return printError(