You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
my ($databases, $rps) = parse_statements($statements_in_file);
396
+
397
+
# loop all the databases and add them to the hash
398
+
formy$db (@$databases) {
399
+
# make sure every database is only created once
400
+
if (exists$db_schemas{$db}) {
401
+
die"duplicate database $db in file $db_file detected\n";
402
+
}
403
+
$db_schemas{$db} = {};
404
+
}
405
+
# loop all the retention policies and assign them to the correct database
406
+
formy$rp (@$rps) {
407
+
my$db = $rp->{database};
408
+
if (exists$db_schemas{$db}) {
409
+
# make sure every retention policy is only created once
410
+
if (exists$db_schemas{$db}->{$rp->{rp_name}}) {
411
+
die"duplicate rp $rp on db $db in file $db_file detected\n";
412
+
}
413
+
$db_schemas{$db}->{$rp->{rp_name}} = $rp;
414
+
}
415
+
else {
416
+
die"database $db specified in rp $rp from file $db_file does not exist\n";
417
+
}
418
+
}
402
419
}
403
-
return \%parsed_statements;
420
+
return \%db_schemas;
404
421
}
405
422
406
-
407
423
#
408
424
# Iterates over the lines of a config file, parses the valid statements and adds them to the given hash.
409
425
# Valid statements are:
@@ -412,19 +428,20 @@ sub load_db_schemas_in_config {
412
428
#
413
429
# Arguments:
414
430
# $string_to_parse string: the contents of the config file (loaded as string)
415
-
# $parsed_statements reference: a reference to a hash. The function will populate it with the parsed statements.
416
431
#
417
432
# Returns:
418
-
# a reference to a hash holding the parsed statements from the file.
433
+
# $databases: reference to a list which contains all the database names
434
+
# $rps: reference to a list which contains hashes of all the retention policies
419
435
#
420
436
subparse_statements {
421
437
my ($string_to_parse) = @_;
422
438
# we want to iterate line-by-line
423
439
my@splitted_lines = split"\n", $string_to_parse;
424
-
my%parsed_statements;
440
+
my@databases;
441
+
my@rps;
425
442
426
443
# captures a 'create database' statement with an optional retention policy definition
427
-
my$db_regex = qr/^\s*(create \s+ database \s+ (\w+)) # a create db statement, optionally starting with a space. Any valid word as db name. Captured group.
444
+
my$db_regex = qr/^\s*(create \s+ database \s+ "?([\w.]+)"?) # a create db statement, optionally starting with a space. Any valid word as db name. Captured group.
428
445
(
429
446
\s+ with \s+ duration # optional statement to define a retention policy in the db creation statement
430
447
\s+ ((?:\d+[smhdw])|(?:inf)) # captured policy duration as one or more numbers followed by a letter, or 'inf'
CREATE CONTINUOUS QUERY "cq.test" ON "db.test" RESAMPLE EVERY 5m FOR 10m BEGIN SELECT LAST(a) AS b, c INTO "rp.test"."m.test" FROM "rp.test"."m.test" GROUP BY time(5m) END;
0 commit comments