From 294d4f7a2c6dcb98de9b8b38e51155d4f3a3c2f5 Mon Sep 17 00:00:00 2001 From: MrBounty Date: Sun, 27 Oct 2024 22:34:17 +0100 Subject: [PATCH] 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 --- src/fileEngine.zig | 15 +++++++++++++-- src/schemaParser.zig | 2 +- src/stuffs/filter.zig | 7 +++---- src/ziqlParser.zig | 5 ++++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/fileEngine.zig b/src/fileEngine.zig index 1a9d4e3..27b260f 100644 --- a/src/fileEngine.zig +++ b/src/fileEngine.zig @@ -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; diff --git a/src/schemaParser.zig b/src/schemaParser.zig index 86b1b35..2f50d20 100644 --- a/src/schemaParser.zig +++ b/src/schemaParser.zig @@ -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{ diff --git a/src/stuffs/filter.zig b/src/stuffs/filter.zig index 1b876c1..49f18f5 100644 --- a/src/stuffs/filter.zig +++ b/src/stuffs/filter.zig @@ -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, diff --git a/src/ziqlParser.zig b/src/ziqlParser.zig index b04f627..9327815 100644 --- a/src/ziqlParser.zig +++ b/src/ziqlParser.zig @@ -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(