diff --git a/src/schemaEngine.zig b/src/schemaEngine.zig index 724ce51..dc7a70b 100644 --- a/src/schemaEngine.zig +++ b/src/schemaEngine.zig @@ -46,8 +46,6 @@ pub const SchemaEngine = struct { }; } - log.debug("SchemaEngine init with {d} SchemaStruct after populateFileIndexUUIDMap.", .{struct_array.items.len}); - return SchemaEngine{ .allocator = allocator, .null_terminated_schema_buff = null_terminated_schema_buff, diff --git a/src/stuffs/filter.zig b/src/stuffs/filter.zig index 360f782..069b961 100644 --- a/src/stuffs/filter.zig +++ b/src/stuffs/filter.zig @@ -59,7 +59,6 @@ pub const ConditionValue = union(enum) { bool_: bool, self: UUID, unix: u64, - link: UUID, int_array: std.ArrayList(i32), str_array: std.ArrayList([]const u8), float_array: std.ArrayList(f64), @@ -67,14 +66,17 @@ pub const ConditionValue = union(enum) { unix_array: std.ArrayList(u64), link_array: *std.AutoHashMap(UUID, void), - pub fn deinit(self: ConditionValue) void { + pub fn deinit(self: ConditionValue, allocator: std.mem.Allocator) void { switch (self) { .int_array => self.int_array.deinit(), .str_array => self.str_array.deinit(), .float_array => self.float_array.deinit(), .bool_array => self.bool_array.deinit(), .unix_array => self.unix_array.deinit(), - .link_array => self.link_array.deinit(), + .link_array => { + self.link_array.deinit(); + allocator.destroy(self.link_array); + }, else => {}, } } @@ -111,14 +113,6 @@ pub const ConditionValue = union(enum) { return ConditionValue{ .unix = s2t.parseDatetime(value).toUnix() }; } - pub fn initLink(value: []const u8) ConditionValue { - const uuid = UUID.parse(value) catch { - std.debug.print("Error: {s}", .{value}); - @panic("WFT ?"); - }; - return ConditionValue{ .link = uuid }; - } - // Array pub fn initArrayInt(allocator: std.mem.Allocator, value: []const u8) ConditionValue { return ConditionValue{ .int_array = s2t.parseArrayInt(allocator, value) }; @@ -159,8 +153,8 @@ pub const Condition = struct { data_type: DataType = undefined, data_index: usize = undefined, // Index in the file - pub fn deinit(self: Condition) void { - self.value.deinit(); + pub fn deinit(self: Condition, allocator: std.mem.Allocator) void { + self.value.deinit(allocator); } }; @@ -187,7 +181,7 @@ pub const Filter = struct { pub fn deinit(self: *Filter) void { switch (self.root.*) { .logical => self.freeNode(self.root), - .condition => |condition| condition.deinit(), + .condition => |condition| condition.deinit(self.allocator), else => {}, } self.allocator.destroy(self.root); @@ -201,7 +195,7 @@ pub const Filter = struct { self.allocator.destroy(logical.left); self.allocator.destroy(logical.right); }, - .condition => |condition| condition.deinit(), + .condition => |condition| condition.deinit(self.allocator), .empty => {}, } } diff --git a/src/ziqlParser.zig b/src/ziqlParser.zig index 8d842f6..8ef3883 100644 --- a/src/ziqlParser.zig +++ b/src/ziqlParser.zig @@ -668,23 +668,22 @@ pub const Parser = struct { .time => condition.value = ConditionValue.initTime(self.toker.buffer[start_index..token.loc.end]), .datetime => condition.value = ConditionValue.initDateTime(self.toker.buffer[start_index..token.loc.end]), .bool => condition.value = ConditionValue.initBool(self.toker.buffer[start_index..token.loc.end]), - .link_array => { - var map = std.AutoHashMap(UUID, void).init(self.allocator); - try self.file_engine.populateVoidUUIDMap( - struct_name, - filter, - &map, - &additional_data, - ); - condition.value = ConditionValue.initLinkArray(&map); - }, - .link => switch (token.tag) { - .l_brace, .l_bracket => {}, // Get the first entity using a filter - .uuid_literal => { - condition.value = ConditionValue.initLink(self.toker.buffer[start_index..token.loc.end]); + .link_array, .link => switch (token.tag) { + .l_brace, .l_bracket => { + const map = self.allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError; + map.* = std.AutoHashMap(UUID, void).init(self.allocator); + if (condition.data_type == .link) additional_data.entity_count_to_find = 1; // FIXME: Look like it return 2 of them, not 1 + try self.file_engine.populateVoidUUIDMap( + struct_name, + filter, + map, + &additional_data, + ); + log.debug("Found {d} entity when parsing for populateVoidUUID\n", .{map.count()}); + condition.value = ConditionValue.initLinkArray(map); }, else => return printError( - "Error: Expected filter or UUID", + "Error: Expected filter", ZiQlParserError.SynthaxError, self.toker.buffer, token.loc.start,