Moved benchmark outside of src and making it better
This commit is contained in:
parent
b075f8b89a
commit
900b9e5305
102
benchmark.zig
Normal file
102
benchmark.zig
Normal file
@ -0,0 +1,102 @@
|
||||
const std = @import("std");
|
||||
const dtype = @import("dtype");
|
||||
const DBEngine = @import("src/main.zig").DBEngine;
|
||||
const ziqlTokenizer = @import("src/tokenizers/ziql.zig").Tokenizer;
|
||||
const ziqlToken = @import("src/tokenizers/ziql.zig").Token;
|
||||
const ziqlParser = @import("src/ziqlParser.zig").Parser;
|
||||
const ZipponError = @import("src/stuffs/errors.zig").ZipponError;
|
||||
|
||||
const names = [_][]const u8{ "Alice", "Bob", "Charlie", "Dave", "Eve" };
|
||||
const emails = [_][]const u8{ "alice@email.com", "bob@email.com", "charlie@email.com", "dave@email.com", "eve@email.com" };
|
||||
const scores = [_]i32{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
|
||||
pub const std_options = .{
|
||||
.logFn = myLog,
|
||||
};
|
||||
|
||||
pub fn myLog(
|
||||
comptime message_level: std.log.Level,
|
||||
comptime scope: @Type(.EnumLiteral),
|
||||
comptime format: []const u8,
|
||||
args: anytype,
|
||||
) void {
|
||||
if (true) return;
|
||||
_ = message_level;
|
||||
_ = scope;
|
||||
_ = format;
|
||||
_ = args;
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var line_buffer: [1024 * 1024]u8 = undefined;
|
||||
// Initialize your DBEngine here
|
||||
var db_engine = DBEngine.init("benchmark", "schema/example");
|
||||
defer db_engine.deinit();
|
||||
|
||||
// Reset the database
|
||||
{
|
||||
const null_term_query_str = try std.fmt.bufPrintZ(&line_buffer, "DELETE User {{}}", .{});
|
||||
var toker = ziqlTokenizer.init(null_term_query_str);
|
||||
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
|
||||
try parser.parse();
|
||||
}
|
||||
|
||||
// Populate with random dummy value
|
||||
std.debug.print("\n=====================================\n\n", .{});
|
||||
std.debug.print("Populating with {d} users.\n", .{10_000});
|
||||
|
||||
var gpa = std.rand.DefaultPrng.init(0);
|
||||
const populate_start_time = std.time.nanoTimestamp();
|
||||
for (10_000) |_| {
|
||||
const name = names[gpa.random().uintAtMost(usize, names.len - 1)];
|
||||
const email = emails[gpa.random().uintAtMost(usize, emails.len - 1)];
|
||||
const age = gpa.random().uintAtMost(usize, 100);
|
||||
const score = scores[gpa.random().uintAtMost(usize, scores.len - 1)];
|
||||
const null_term_query_str = try std.fmt.bufPrintZ(
|
||||
&line_buffer,
|
||||
"ADD User (name = '{s}', email='{s}', age={d}, scores=[ {d} ], best_friend=none, friends=none, bday=2000/01/01, a_time=12:04, last_order=2000/01/01-12:45)",
|
||||
.{ name, email, age, score },
|
||||
);
|
||||
var toker = ziqlTokenizer.init(null_term_query_str);
|
||||
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
|
||||
try parser.parse();
|
||||
}
|
||||
const populate_end_time = std.time.nanoTimestamp();
|
||||
const populate_duration = @as(f64, @floatFromInt(populate_end_time - populate_start_time)) / 1e9;
|
||||
|
||||
std.debug.print("Populate duration: {d:.6} seconds\n\n", .{populate_duration});
|
||||
|
||||
var buffer = std.ArrayList(u8).init(std.heap.page_allocator);
|
||||
defer buffer.deinit();
|
||||
try db_engine.file_engine.writeDbMetrics(&buffer);
|
||||
std.debug.print("{s}\n", .{buffer.items});
|
||||
std.debug.print("--------------------------------------\n\n", .{});
|
||||
|
||||
// Define your benchmark queries
|
||||
const queries = [_][]const u8{
|
||||
"GRAB User {}",
|
||||
"GRAB User [1] {}",
|
||||
"GRAB User [name] {}",
|
||||
"GRAB User {name = 'Charlie'}",
|
||||
"GRAB User {age > 30}",
|
||||
"DELETE User {}",
|
||||
};
|
||||
|
||||
// Run benchmarks
|
||||
for (queries) |query| {
|
||||
const start_time = std.time.nanoTimestamp();
|
||||
|
||||
// Execute the query here
|
||||
const null_term_query_str = try std.fmt.bufPrintZ(&line_buffer, "{s}", .{query});
|
||||
var toker = ziqlTokenizer.init(null_term_query_str);
|
||||
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
|
||||
try parser.parse();
|
||||
|
||||
const end_time = std.time.nanoTimestamp();
|
||||
const duration = @as(f64, @floatFromInt(end_time - start_time)) / 1e9;
|
||||
|
||||
std.debug.print("Query: \t\t{s}\nDuration: \t{d:.6} seconds\n\n", .{ query, duration });
|
||||
}
|
||||
|
||||
std.debug.print("=====================================\n\n", .{});
|
||||
}
|
@ -104,7 +104,7 @@ pub fn build(b: *std.Build) void {
|
||||
// -----------------------------------------------
|
||||
const benchmark = b.addExecutable(.{
|
||||
.name = "benchmark",
|
||||
.root_source_file = b.path("src/benchmark.zig"),
|
||||
.root_source_file = b.path("benchmark.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
@ -1,77 +0,0 @@
|
||||
const std = @import("std");
|
||||
const DBEngine = @import("main.zig").DBEngine;
|
||||
const dtype = @import("dtype");
|
||||
const ziqlTokenizer = @import("tokenizers/ziql.zig").Tokenizer;
|
||||
const ziqlToken = @import("tokenizers/ziql.zig").Token;
|
||||
const ziqlParser = @import("ziqlParser.zig").Parser;
|
||||
|
||||
pub const std_options = .{
|
||||
.logFn = myLog,
|
||||
};
|
||||
|
||||
pub fn myLog(
|
||||
comptime message_level: std.log.Level,
|
||||
comptime scope: @Type(.EnumLiteral),
|
||||
comptime format: []const u8,
|
||||
args: anytype,
|
||||
) void {
|
||||
if (true) return;
|
||||
_ = message_level;
|
||||
_ = scope;
|
||||
_ = format;
|
||||
_ = args;
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var line_buffer: [1024 * 1024]u8 = undefined;
|
||||
// Initialize your DBEngine here
|
||||
var db_engine = DBEngine.init("benchmark", "example.zipponschema");
|
||||
defer db_engine.deinit();
|
||||
|
||||
// Define your benchmark queries
|
||||
const populate = [_][]const u8{
|
||||
"ADD User (name = 'Bob', email='bob@email.com', age=55, scores=[ 1 ], best_friend=none, friends=none, bday=2000/01/01, a_time=12:04, last_order=2000/01/01-12:45)",
|
||||
};
|
||||
|
||||
// Run benchmarks
|
||||
const populate_start_time = std.time.nanoTimestamp();
|
||||
for (populate) |query| {
|
||||
const null_term_query_str = try std.fmt.bufPrintZ(&line_buffer, "{s}", .{query});
|
||||
for (0..1) |_| {
|
||||
var toker = ziqlTokenizer.init(null_term_query_str);
|
||||
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
|
||||
try parser.parse();
|
||||
}
|
||||
}
|
||||
|
||||
const populate_end_time = std.time.nanoTimestamp();
|
||||
const populate_duration = @as(f64, @floatFromInt(populate_end_time - populate_start_time)) / 1e9;
|
||||
|
||||
std.debug.print("Populate duration: {d:.6} seconds\n\n", .{populate_duration});
|
||||
|
||||
// Define your benchmark queries
|
||||
const queries = [_][]const u8{
|
||||
"GRAB User {}",
|
||||
"GRAB User [1] {}",
|
||||
"GRAB User [name] {}",
|
||||
"GRAB User {name = 'Adrien'}",
|
||||
"GRAB User {age > 30}",
|
||||
};
|
||||
|
||||
// Run benchmarks
|
||||
std.debug.print("Running benchmarks...\n", .{});
|
||||
for (queries) |query| {
|
||||
const start_time = std.time.nanoTimestamp();
|
||||
|
||||
// Execute the query here
|
||||
const null_term_query_str = try std.fmt.bufPrintZ(&line_buffer, "{s}", .{query});
|
||||
var toker = ziqlTokenizer.init(null_term_query_str);
|
||||
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
|
||||
try parser.parse();
|
||||
|
||||
const end_time = std.time.nanoTimestamp();
|
||||
const duration = @as(f64, @floatFromInt(end_time - start_time)) / 1e9;
|
||||
|
||||
std.debug.print("Query: {s}\nDuration: {d:.6} seconds\n\n", .{ query, duration });
|
||||
}
|
||||
}
|
@ -18,9 +18,7 @@ const AdditionalDataMember = @import("stuffs/additionalData.zig").AdditionalData
|
||||
const send = @import("stuffs/utils.zig").send;
|
||||
const printError = @import("stuffs/utils.zig").printError;
|
||||
|
||||
const ZiQlParserError = @import("stuffs/errors.zig").ZiQlParserError;
|
||||
const ZipponError = @import("stuffs/errors.zig").ZipponError;
|
||||
|
||||
const PRINT_STATE = @import("config").PRINT_STATE;
|
||||
|
||||
const log = std.log.scoped(.ziqlParser);
|
||||
@ -119,7 +117,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected action keyword. Available: GRAB ADD DELETE UPDATE",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -131,14 +129,14 @@ pub const Parser = struct {
|
||||
struct_name = self.toker.getTokenSlice(token);
|
||||
if (token.tag != .identifier) return printError(
|
||||
"Error: Missing struct name.",
|
||||
ZiQlParserError.StructNotFound,
|
||||
ZipponError.StructNotFound,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
);
|
||||
if (!self.schema_engine.isStructNameExists(struct_name)) return printError(
|
||||
"Error: struct name not found in schema.",
|
||||
ZiQlParserError.StructNotFound,
|
||||
ZipponError.StructNotFound,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -161,7 +159,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expect [ for additional data or { for a filter",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -195,7 +193,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected filter.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -212,7 +210,7 @@ pub const Parser = struct {
|
||||
|
||||
if (token.tag != .keyword_to) return printError(
|
||||
"Error: Expected TO",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -221,7 +219,7 @@ pub const Parser = struct {
|
||||
token = self.toker.next();
|
||||
if (token.tag != .l_paren) return printError(
|
||||
"Error: Expected (",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -242,7 +240,7 @@ pub const Parser = struct {
|
||||
token = self.toker.next();
|
||||
if (token.tag != .l_paren) return printError(
|
||||
"Error: Expected (",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -261,7 +259,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected filter or TO.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -290,7 +288,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected filter.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -304,7 +302,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected new data starting with (",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -334,13 +332,13 @@ pub const Parser = struct {
|
||||
error_message_buffer_writer.writeAll("Error missing: ") catch return ZipponError.WriteError;
|
||||
|
||||
if (!(self.schema_engine.checkIfAllMemberInMap(struct_name, &data_map, &error_message_buffer) catch {
|
||||
return ZiQlParserError.StructNotFound;
|
||||
return ZipponError.StructNotFound;
|
||||
})) {
|
||||
_ = error_message_buffer.pop();
|
||||
_ = error_message_buffer.pop();
|
||||
return printError(
|
||||
error_message_buffer.items,
|
||||
ZiQlParserError.MemberMissing,
|
||||
ZipponError.MemberMissing,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -421,7 +419,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected ( or condition.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -465,7 +463,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected AND, OR, or }",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -499,7 +497,7 @@ pub const Parser = struct {
|
||||
if (!(self.schema_engine.isMemberNameInStruct(struct_name, self.toker.getTokenSlice(token)) catch {
|
||||
return printError(
|
||||
"Error: Struct not found.",
|
||||
ZiQlParserError.StructNotFound,
|
||||
ZipponError.StructNotFound,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -507,7 +505,7 @@ pub const Parser = struct {
|
||||
})) {
|
||||
return printError(
|
||||
"Error: Member not part of struct.",
|
||||
ZiQlParserError.MemberNotFound,
|
||||
ZipponError.MemberNotFound,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -516,16 +514,16 @@ pub const Parser = struct {
|
||||
condition.data_type = self.schema_engine.memberName2DataType(
|
||||
struct_name,
|
||||
self.toker.getTokenSlice(token),
|
||||
) catch return ZiQlParserError.MemberNotFound;
|
||||
) catch return ZipponError.MemberNotFound;
|
||||
condition.data_index = self.schema_engine.memberName2DataIndex(
|
||||
struct_name,
|
||||
self.toker.getTokenSlice(token),
|
||||
) catch return ZiQlParserError.MemberNotFound;
|
||||
) catch return ZipponError.MemberNotFound;
|
||||
state = .expect_operation;
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected member name.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -561,7 +559,7 @@ pub const Parser = struct {
|
||||
.int, .float, .str, .bool, .date, .time, .datetime => {},
|
||||
else => return printError(
|
||||
"Error: Only int, float, str, bool, date, time, datetime can be compare with =",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -572,7 +570,7 @@ pub const Parser = struct {
|
||||
.int, .float, .str, .bool, .date, .time, .datetime => {},
|
||||
else => return printError(
|
||||
"Error: Only int, float, str, bool, date, time, datetime can be compare with !=",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -583,7 +581,7 @@ pub const Parser = struct {
|
||||
.int, .float, .date, .time, .datetime => {},
|
||||
else => return printError(
|
||||
"Error: Only int, float, date, time, datetime can be compare with >=",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -594,7 +592,7 @@ pub const Parser = struct {
|
||||
.int, .float, .date, .time, .datetime => {},
|
||||
else => return printError(
|
||||
"Error: Only int, float, date, time, datetime can be compare with >",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -605,7 +603,7 @@ pub const Parser = struct {
|
||||
.int, .float, .date, .time, .datetime => {},
|
||||
else => return printError(
|
||||
"Error: Only int, float, date, time, datetime can be compare with <=",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -616,7 +614,7 @@ pub const Parser = struct {
|
||||
.int, .float, .date, .time, .datetime => {},
|
||||
else => return printError(
|
||||
"Error: Only int, float, date, time, datetime can be compare with <",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -627,7 +625,7 @@ pub const Parser = struct {
|
||||
.link => {},
|
||||
else => return printError(
|
||||
"Error: Only link can be compare with IN.",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -638,7 +636,7 @@ pub const Parser = struct {
|
||||
.link => {},
|
||||
else => return printError(
|
||||
"Error: Only link can be compare with !IN.",
|
||||
ZiQlParserError.ConditionError,
|
||||
ZipponError.ConditionError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -669,7 +667,7 @@ pub const Parser = struct {
|
||||
additional_data.limit = std.fmt.parseInt(usize, self.toker.getTokenSlice(token), 10) catch {
|
||||
return printError(
|
||||
"Error while transforming limit into a integer.",
|
||||
ZiQlParserError.ParsingValueError,
|
||||
ZipponError.ParsingValueError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -688,7 +686,7 @@ pub const Parser = struct {
|
||||
.r_bracket => state = .end,
|
||||
else => return printError(
|
||||
"Error: Expect ';' or ']'.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -700,7 +698,7 @@ pub const Parser = struct {
|
||||
if (!(self.schema_engine.isMemberNameInStruct(struct_name, self.toker.getTokenSlice(token)) catch {
|
||||
return printError(
|
||||
"Struct not found.",
|
||||
ZiQlParserError.StructNotFound,
|
||||
ZipponError.StructNotFound,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -708,7 +706,7 @@ pub const Parser = struct {
|
||||
})) {
|
||||
return printError(
|
||||
"Member not found in struct.",
|
||||
ZiQlParserError.MemberNotFound,
|
||||
ZipponError.MemberNotFound,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -723,7 +721,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected a member name.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -745,7 +743,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected , or ] or [",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -757,7 +755,7 @@ pub const Parser = struct {
|
||||
.r_bracket => state = .end,
|
||||
else => return printError(
|
||||
"Error: Expected , or ]",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -794,10 +792,10 @@ pub const Parser = struct {
|
||||
.identifier => {
|
||||
member_name = self.toker.getTokenSlice(token);
|
||||
if (!(self.schema_engine.isMemberNameInStruct(struct_name, member_name) catch {
|
||||
return ZiQlParserError.StructNotFound;
|
||||
return ZipponError.StructNotFound;
|
||||
})) return printError(
|
||||
"Member not found in struct.",
|
||||
ZiQlParserError.MemberNotFound,
|
||||
ZipponError.MemberNotFound,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -820,7 +818,7 @@ pub const Parser = struct {
|
||||
=> if (order_full) |o| {
|
||||
if (!o) return printError(
|
||||
"Expected member name.",
|
||||
ZiQlParserError.MemberMissing,
|
||||
ZipponError.MemberMissing,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -833,7 +831,7 @@ pub const Parser = struct {
|
||||
} else {
|
||||
return printError(
|
||||
"Expected member name.",
|
||||
ZiQlParserError.MemberMissing,
|
||||
ZipponError.MemberMissing,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -841,7 +839,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected member name.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -853,7 +851,7 @@ pub const Parser = struct {
|
||||
.equal => state = .expect_new_value,
|
||||
else => return printError(
|
||||
"Error: Expected =",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -861,7 +859,7 @@ pub const Parser = struct {
|
||||
},
|
||||
|
||||
.expect_new_value => {
|
||||
const data_type = self.schema_engine.memberName2DataType(struct_name, member_name) catch return ZiQlParserError.StructNotFound;
|
||||
const data_type = self.schema_engine.memberName2DataType(struct_name, member_name) catch return ZipponError.StructNotFound;
|
||||
map.put(member_name, try self.parseConditionValue(allocator, struct_name, data_type, &token)) catch return ZipponError.MemoryError;
|
||||
if (data_type == .link or data_type == .link_array) {
|
||||
token = self.toker.last_token;
|
||||
@ -875,7 +873,7 @@ pub const Parser = struct {
|
||||
.comma => state = .expect_member_OR_value,
|
||||
else => return printError(
|
||||
"Error: Expect , or )",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -898,7 +896,7 @@ pub const Parser = struct {
|
||||
.keyword_not_in => .not_in,
|
||||
else => return printError(
|
||||
"Error: Expected condition. Including < > <= >= = !=",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -934,7 +932,7 @@ pub const Parser = struct {
|
||||
if (token.tag != tag) {
|
||||
return printError(
|
||||
"Error: Wrong type", // TODO: Print the expected type
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -946,7 +944,7 @@ pub const Parser = struct {
|
||||
if (token.tag != .bool_literal_true and token.tag != .bool_literal_false) {
|
||||
return printError(
|
||||
"Error: Expected bool",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -959,7 +957,7 @@ pub const Parser = struct {
|
||||
if (token.tag != .bool_literal_true and token.tag != .bool_literal_false) {
|
||||
return printError(
|
||||
"Error: Expected bool or ]",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -1000,7 +998,7 @@ pub const Parser = struct {
|
||||
const uuid = UUID.parse(self.toker.buffer[start_index..token.loc.end]) catch return ZipponError.InvalidUUID;
|
||||
if (!self.schema_engine.isUUIDExist(struct_name, uuid)) return printError(
|
||||
"Error: UUID do not exist in database.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -1027,7 +1025,7 @@ pub const Parser = struct {
|
||||
|
||||
if (token.tag == .l_brace) filter = try self.parseFilter(allocator, struct_name, false) else return printError(
|
||||
"Error: Expected filter",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -1047,7 +1045,7 @@ pub const Parser = struct {
|
||||
|
||||
else => return printError(
|
||||
"Error: Expected uuid or none",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -1075,7 +1073,7 @@ pub const Parser = struct {
|
||||
|
||||
if (token.tag == .l_brace) filter = try self.parseFilter(allocator, struct_name, false) else return printError(
|
||||
"Error: Expected filter",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -1094,7 +1092,7 @@ pub const Parser = struct {
|
||||
},
|
||||
else => return printError(
|
||||
"Error: Expected uuid or none",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -1112,7 +1110,7 @@ pub const Parser = struct {
|
||||
while (token.tag != .r_bracket) : (token = self.toker.next()) {
|
||||
if (token.tag != tag) return printError(
|
||||
"Error: Wrong type.",
|
||||
ZiQlParserError.SynthaxError,
|
||||
ZipponError.SynthaxError,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
token.loc.end,
|
||||
@ -1123,14 +1121,14 @@ pub const Parser = struct {
|
||||
};
|
||||
|
||||
test "Synthax error" {
|
||||
try expectParsingError("ADD User (name = 'Bob', email='bob@email.com', age=-55, scores=[ 1 ], best_friend=7db1f06d-a5a7-4917-8cc6-4d490191c9c1, bday=2000/01/01, a_time=12:04:54.8741, last_order=2000/01/01-12:45)", ZiQlParserError.SynthaxError);
|
||||
try expectParsingError("GRAB {}", ZiQlParserError.StructNotFound);
|
||||
try expectParsingError("GRAB User {qwe = 'qwe'}", ZiQlParserError.MemberNotFound);
|
||||
try expectParsingError("ADD User (name='Bob')", ZiQlParserError.MemberMissing);
|
||||
try expectParsingError("GRAB User {name='Bob'", ZiQlParserError.SynthaxError);
|
||||
try expectParsingError("GRAB User {age = 50 name='Bob'}", ZiQlParserError.SynthaxError);
|
||||
try expectParsingError("GRAB User {age <14 AND (age>55}", ZiQlParserError.SynthaxError);
|
||||
try expectParsingError("GRAB User {name < 'Hello'}", ZiQlParserError.ConditionError);
|
||||
try expectParsingError("ADD User (name = 'Bob', email='bob@email.com', age=-55, scores=[ 1 ], best_friend=7db1f06d-a5a7-4917-8cc6-4d490191c9c1, bday=2000/01/01, a_time=12:04:54.8741, last_order=2000/01/01-12:45)", ZipponError.SynthaxError);
|
||||
try expectParsingError("GRAB {}", ZipponError.StructNotFound);
|
||||
try expectParsingError("GRAB User {qwe = 'qwe'}", ZipponError.MemberNotFound);
|
||||
try expectParsingError("ADD User (name='Bob')", ZipponError.MemberMissing);
|
||||
try expectParsingError("GRAB User {name='Bob'", ZipponError.SynthaxError);
|
||||
try expectParsingError("GRAB User {age = 50 name='Bob'}", ZipponError.SynthaxError);
|
||||
try expectParsingError("GRAB User {age <14 AND (age>55}", ZipponError.SynthaxError);
|
||||
try expectParsingError("GRAB User {name < 'Hello'}", ZipponError.ConditionError);
|
||||
}
|
||||
|
||||
test "Clear" {
|
||||
@ -1247,7 +1245,7 @@ fn testParsing(source: [:0]const u8) !void {
|
||||
try parser.parse();
|
||||
}
|
||||
|
||||
fn expectParsingError(source: [:0]const u8, err: ZiQlParserError) !void {
|
||||
fn expectParsingError(source: [:0]const u8, err: ZipponError) !void {
|
||||
const TEST_DATA_DIR = @import("config").TEST_DATA_DIR;
|
||||
|
||||
var db_engine = DBEngine.init(TEST_DATA_DIR, null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user