NewData ordered by default
This commit is contained in:
parent
e848be94c1
commit
6338cb6364
@ -63,7 +63,7 @@ pub const HELP_MESSAGE = struct {
|
|||||||
pub const no_schema: []const u8 =
|
pub const no_schema: []const u8 =
|
||||||
\\A database was found here `{s}` but no schema find inside.
|
\\A database was found here `{s}` but no schema find inside.
|
||||||
\\To start a database, you need to attach it a schema using a schema file.
|
\\To start a database, you need to attach it a schema using a schema file.
|
||||||
\\By using 'schema init path/to/schema'. For more informations on how to create a schema: TODO add link
|
\\By using 'schema use path/to/schema'. For more informations on how to create a schema: TODO add link
|
||||||
\\
|
\\
|
||||||
\\You can also set the environment variable ZIPPONDB_SCHEMA to the path to a schema file.
|
\\You can also set the environment variable ZIPPONDB_SCHEMA to the path to a schema file.
|
||||||
\\
|
\\
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pub const BUFFER_SIZE = 1024 * 10; // Used a bit everywhere. The size for the schema for example. 10kB
|
pub const BUFFER_SIZE = 1024 * 1024; // Used a bit everywhere. The size for the schema for example. 10kB
|
||||||
pub const MAX_FILE_SIZE = 1024 * 1024; // 1MB
|
pub const MAX_FILE_SIZE = 1024 * 1024; // 1MB
|
||||||
pub const CPU_CORE = 16;
|
pub const CPU_CORE = 16;
|
||||||
|
|
||||||
|
1
schema/simple
Normal file
1
schema/simple
Normal file
@ -0,0 +1 @@
|
|||||||
|
User (name:str,)
|
@ -165,8 +165,16 @@ pub fn parse(self: *Self, null_term_line_str: [:0]const u8) !bool {
|
|||||||
|
|
||||||
.expect_schema_command => switch (token.tag) {
|
.expect_schema_command => switch (token.tag) {
|
||||||
.keyword_describe => {
|
.keyword_describe => {
|
||||||
if (self.state == .MissingFileEngine) send("Error: No database selected. Please use 'db new' or 'db use'.", .{});
|
if (self.state == .MissingFileEngine) {
|
||||||
if (self.state == .MissingSchemaEngine) send("Error: No schema in database. Please use 'schema init'.", .{});
|
send("{s}", .{config.HELP_MESSAGE.no_engine});
|
||||||
|
state = .end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (self.state == .MissingSchemaEngine) {
|
||||||
|
send(config.HELP_MESSAGE.no_schema, .{self.file_engine.path_to_ZipponDB_dir});
|
||||||
|
state = .end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
send("Schema:\n {s}", .{self.schema_engine.null_terminated});
|
send("Schema:\n {s}", .{self.schema_engine.null_terminated});
|
||||||
state = .end;
|
state = .end;
|
||||||
},
|
},
|
||||||
|
@ -3,7 +3,6 @@ const config = @import("config");
|
|||||||
const utils = @import("../utils.zig");
|
const utils = @import("../utils.zig");
|
||||||
const zid = @import("ZipponData");
|
const zid = @import("ZipponData");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const Self = @import("core.zig").Self;
|
|
||||||
const ZipponError = @import("error").ZipponError;
|
const ZipponError = @import("error").ZipponError;
|
||||||
|
|
||||||
const SchemaStruct = @import("../schema/struct.zig");
|
const SchemaStruct = @import("../schema/struct.zig");
|
||||||
@ -22,6 +21,8 @@ const DateTime = dtype.DateTime;
|
|||||||
const DataType = dtype.DataType;
|
const DataType = dtype.DataType;
|
||||||
const log = std.log.scoped(.fileEngine);
|
const log = std.log.scoped(.fileEngine);
|
||||||
|
|
||||||
|
const Self = @import("core.zig").Self;
|
||||||
|
|
||||||
var path_buffer: [1024]u8 = undefined;
|
var path_buffer: [1024]u8 = undefined;
|
||||||
|
|
||||||
/// Use a struct name to populate a list with all UUID of this struct
|
/// Use a struct name to populate a list with all UUID of this struct
|
||||||
|
@ -235,9 +235,14 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
|||||||
token.loc.end,
|
token.loc.end,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const sstruct = try self.schema_engine.structName2SchemaStruct(struct_name);
|
||||||
|
var members = std.ArrayList([]const u8).init(allocator);
|
||||||
|
defer members.deinit();
|
||||||
|
members.appendSlice(sstruct.members[1..]) catch return ZipponError.MemoryError;
|
||||||
|
|
||||||
var data_map = std.StringHashMap(ConditionValue).init(allocator);
|
var data_map = std.StringHashMap(ConditionValue).init(allocator);
|
||||||
defer data_map.deinit();
|
defer data_map.deinit();
|
||||||
try self.parseNewData(allocator, &data_map, struct_name, null, null);
|
try self.parseNewData(allocator, &data_map, struct_name, &members);
|
||||||
|
|
||||||
var buff = std.ArrayList(u8).init(allocator);
|
var buff = std.ArrayList(u8).init(allocator);
|
||||||
defer buff.deinit();
|
defer buff.deinit();
|
||||||
@ -256,9 +261,14 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
|||||||
token.loc.end,
|
token.loc.end,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const sstruct = try self.schema_engine.structName2SchemaStruct(struct_name);
|
||||||
|
var members = std.ArrayList([]const u8).init(allocator);
|
||||||
|
defer members.deinit();
|
||||||
|
members.appendSlice(sstruct.members[1..]) catch return ZipponError.MemoryError;
|
||||||
|
|
||||||
var data_map = std.StringHashMap(ConditionValue).init(allocator);
|
var data_map = std.StringHashMap(ConditionValue).init(allocator);
|
||||||
defer data_map.deinit();
|
defer data_map.deinit();
|
||||||
try self.parseNewData(allocator, &data_map, struct_name, null, null);
|
try self.parseNewData(allocator, &data_map, struct_name, &members);
|
||||||
|
|
||||||
var buff = std.ArrayList(u8).init(allocator);
|
var buff = std.ArrayList(u8).init(allocator);
|
||||||
defer buff.deinit();
|
defer buff.deinit();
|
||||||
@ -320,9 +330,10 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.parse_new_data_and_add_data => {
|
.parse_new_data_and_add_data => {
|
||||||
|
const sstruct = try self.schema_engine.structName2SchemaStruct(struct_name);
|
||||||
var order = std.ArrayList([]const u8).init(allocator);
|
var order = std.ArrayList([]const u8).init(allocator);
|
||||||
defer order.deinit();
|
defer order.deinit();
|
||||||
var ordered = false;
|
order.appendSlice(sstruct.members[1..]) catch return ZipponError.MemoryError;
|
||||||
|
|
||||||
var buff = std.ArrayList(u8).init(allocator);
|
var buff = std.ArrayList(u8).init(allocator);
|
||||||
defer buff.deinit();
|
defer buff.deinit();
|
||||||
@ -340,8 +351,7 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
|||||||
|
|
||||||
while (true) { // I could multithread that as it do take a long time for big benchmark
|
while (true) { // I could multithread that as it do take a long time for big benchmark
|
||||||
data_map.clearRetainingCapacity();
|
data_map.clearRetainingCapacity();
|
||||||
try self.parseNewData(local_allocator, &data_map, struct_name, &order, ordered);
|
try self.parseNewData(local_allocator, &data_map, struct_name, &order);
|
||||||
ordered = true;
|
|
||||||
|
|
||||||
var error_message_buffer = std.ArrayList(u8).init(local_allocator);
|
var error_message_buffer = std.ArrayList(u8).init(local_allocator);
|
||||||
defer error_message_buffer.deinit();
|
defer error_message_buffer.deinit();
|
||||||
|
@ -16,11 +16,11 @@ pub fn parseNewData(
|
|||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
map: *std.StringHashMap(ConditionValue),
|
map: *std.StringHashMap(ConditionValue),
|
||||||
struct_name: []const u8,
|
struct_name: []const u8,
|
||||||
order: ?*std.ArrayList([]const u8),
|
order: *std.ArrayList([]const u8),
|
||||||
order_full: ?bool,
|
|
||||||
) !void {
|
) !void {
|
||||||
var token = self.toker.next();
|
var token = self.toker.next();
|
||||||
var keep_next = false;
|
var keep_next = false;
|
||||||
|
var reordering: bool = false;
|
||||||
var member_name: []const u8 = undefined;
|
var member_name: []const u8 = undefined;
|
||||||
var state: Self.State = .expect_member_OR_value;
|
var state: Self.State = .expect_member_OR_value;
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
@ -32,6 +32,10 @@ pub fn parseNewData(
|
|||||||
}) switch (state) {
|
}) switch (state) {
|
||||||
.expect_member_OR_value => switch (token.tag) {
|
.expect_member_OR_value => switch (token.tag) {
|
||||||
.identifier => {
|
.identifier => {
|
||||||
|
if (!reordering) {
|
||||||
|
order.*.clearRetainingCapacity();
|
||||||
|
reordering = true;
|
||||||
|
}
|
||||||
member_name = self.toker.getTokenSlice(token);
|
member_name = self.toker.getTokenSlice(token);
|
||||||
if (!(self.schema_engine.isMemberNameInStruct(struct_name, member_name) catch {
|
if (!(self.schema_engine.isMemberNameInStruct(struct_name, member_name) catch {
|
||||||
return ZipponError.StructNotFound;
|
return ZipponError.StructNotFound;
|
||||||
@ -42,7 +46,7 @@ pub fn parseNewData(
|
|||||||
token.loc.start,
|
token.loc.start,
|
||||||
token.loc.end,
|
token.loc.end,
|
||||||
);
|
);
|
||||||
if (order_full) |o| if (!o) order.?.*.append(allocator.dupe(u8, member_name) catch return ZipponError.MemoryError) catch return ZipponError.MemoryError;
|
order.*.append(allocator.dupe(u8, member_name) catch return ZipponError.MemoryError) catch return ZipponError.MemoryError;
|
||||||
state = .expect_equal;
|
state = .expect_equal;
|
||||||
},
|
},
|
||||||
.string_literal,
|
.string_literal,
|
||||||
@ -58,27 +62,11 @@ pub fn parseNewData(
|
|||||||
.l_brace,
|
.l_brace,
|
||||||
.keyword_none,
|
.keyword_none,
|
||||||
.keyword_now,
|
.keyword_now,
|
||||||
=> if (order_full) |o| {
|
=> {
|
||||||
if (!o) return printError(
|
member_name = order.items[i];
|
||||||
"Expected member name.",
|
|
||||||
ZipponError.MemberMissing,
|
|
||||||
self.toker.buffer,
|
|
||||||
token.loc.start,
|
|
||||||
token.loc.end,
|
|
||||||
);
|
|
||||||
|
|
||||||
member_name = order.?.items[i];
|
|
||||||
i += 1;
|
i += 1;
|
||||||
keep_next = true;
|
keep_next = true;
|
||||||
state = .expect_new_value;
|
state = .expect_new_value;
|
||||||
} else {
|
|
||||||
return printError(
|
|
||||||
"Expected member name.",
|
|
||||||
ZipponError.MemberMissing,
|
|
||||||
self.toker.buffer,
|
|
||||||
token.loc.start,
|
|
||||||
token.loc.end,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
else => return printError(
|
else => return printError(
|
||||||
"Error: Expected member name.",
|
"Error: Expected member name.",
|
||||||
|
@ -12,6 +12,10 @@ const JsonString = RelationMap.JsonString;
|
|||||||
|
|
||||||
const ZipponError = @import("error").ZipponError;
|
const ZipponError = @import("error").ZipponError;
|
||||||
|
|
||||||
|
// I need to redo how SchemaStruct work because it is a mess
|
||||||
|
// I mean I use wayyyyyyyyyyyyyyyyyyyyyyy too much structName2SchemaStruct or stuff like that
|
||||||
|
// I mean that not good to always for loop and compare when a map would work
|
||||||
|
|
||||||
pub fn memberName2DataType(self: *Self, struct_name: []const u8, member_name: []const u8) ZipponError!DataType {
|
pub fn memberName2DataType(self: *Self, struct_name: []const u8, member_name: []const u8) ZipponError!DataType {
|
||||||
for (try self.structName2structMembers(struct_name), 0..) |mn, i| {
|
for (try self.structName2structMembers(struct_name), 0..) |mn, i| {
|
||||||
const dtypes = try self.structName2DataType(struct_name);
|
const dtypes = try self.structName2DataType(struct_name);
|
||||||
@ -42,6 +46,7 @@ pub fn structName2structMembers(self: Self, struct_name: []const u8) ZipponError
|
|||||||
return self.struct_array[i].members;
|
return self.struct_array[i].members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This is the first one I want to change to use a map
|
||||||
pub fn structName2SchemaStruct(self: Self, struct_name: []const u8) ZipponError!SchemaStruct {
|
pub fn structName2SchemaStruct(self: Self, struct_name: []const u8) ZipponError!SchemaStruct {
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user