Skip to content

Commit c8d095b

Browse files
Change in config default values, correction in README, solve bug with version validation, add version validation test. (#27)
1 parent 895b05d commit c8d095b

8 files changed

Lines changed: 40 additions & 18 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ bulk insert DBNAME/TABLENAME from PATH with (CONFIG)
6060
KEYS: Number of binary keys in the CSV file.
6161
MZ: MZ file indicator.
6262
WFP: WFP file indicator.
63-
OVERWRITE: Overwrite the destination table.
64-
SORT: Sort the tuples during the import process.
63+
OVERWRITE: Overwrite the destination table. (Default: 0).
64+
SORT: Sort the tuples during the import process. (Default: 1).
6565
FIELDS: Number of CSV fields.
66-
VALIDATE_FIELDS: Check field quantity during importation.
67-
VALIDATE_VERSION: Validate version.json.
68-
VERBOSE: Enable verbose mode.
66+
VALIDATE_FIELDS: Check field quantity during importation. (Default: 1).
67+
VALIDATE_VERSION: Validate version.json.(Default: 1).
68+
VERBOSE: Enable verbose mode. (Default: 0).
6969
COLLATE: Perform collation after import, removing data larger than MAX_RECORD bytes.
70-
MAX_RECORD: Maximum record size in bytes (default: 1024).
70+
MAX_RECORD: Maximum record size in bytes (Default: 2048).
7171
MAX_RAM_PERCENT: limit the system RAM usage during collate process. Default value: 50.
7272
TMP_PATH: Path to the folder used for temporary files (default: /tmp).
7373

src/import.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ bool version_import(ldb_importation_config_t *job)
10361036
test_len -= (strlen(daily_date_i) + strlen("\"daily\":"));
10371037
if (monthly_date_i)
10381038
test_len -= (strlen(monthly_date_i) + strlen("\"monthly\":"));
1039-
//exit if cannot find daily or monthly or there are am excess of characteres in the json
1039+
//exit if cannot find daily or monthly or there are an excess of characteres in the json
10401040
if ((!daily_date_i && !monthly_date_i) || test_len > 10)
10411041
{
10421042
logger_basic("Failed to process version file: %s\n", vf_import);
@@ -1072,7 +1072,7 @@ bool version_import(ldb_importation_config_t *job)
10721072
return false;
10731073
}
10741074

1075-
fprintf(f, JSON_CONTENT, monthly_date_i == NULL ? "N/A" : monthly_date_i ,daily_date_i == NULL ? "N/A" : daily_date_i);
1075+
fprintf(f, JSON_CONTENT, monthly_date_i == NULL ? "N/A" : monthly_date_i, daily_date_i == NULL ? "N/A" : daily_date_i);
10761076
fclose(f);
10771077
free(daily_date_i);
10781078
free(daily_date_o);
@@ -1176,7 +1176,7 @@ bool ldb_importation_config_parse(ldb_importation_config_t * config, char * line
11761176

11771177
bool ldb_create_db_config_default(char * dbname)
11781178
{
1179-
char config[] = "GLOBAL: (VALIDATE_FIELDS=1, VALIDATE_VERSION=0, SORT=1, FILE_DEL=0, OVERWRITE=0, WFP=0, MZ=0, VERBOSE=0, COLLATE=0, MAX_RECORD=2048, MAX_RAM_PERCENT=50, TMP_PATH=/tmp)\n"
1179+
char config[] = "GLOBAL: (VALIDATE_FIELDS=1, VALIDATE_VERSION=1, SORT=1, FILE_DEL=0, OVERWRITE=0, WFP=0, MZ=0, VERBOSE=0, COLLATE=0, MAX_RECORD=2048, MAX_RAM_PERCENT=50, TMP_PATH=/tmp)\n"
11801180
"sources: (MZ=1, KEYS=1)\n"
11811181
"notices: (MZ=1, KEYS=1)\n"
11821182
"attribution: (KEYS=1, FIELDS=2)\n"
@@ -1413,13 +1413,6 @@ int ldb_import(ldb_importation_config_t * job)
14131413
int result = -1;
14141414
ldb_importation_config_t config = *job;
14151415

1416-
logger_set_level(config.opt.params.verbose);
1417-
if (config.opt.params.version_validation && !version_import(&config))
1418-
{
1419-
logger_basic("Failed to validate version.json, check if it is present in %s and it has the correct format\n", config.path);
1420-
exit(EXIT_FAILURE);
1421-
}
1422-
14231416
if (strstr(config.csv_path, ".mz"))
14241417
config.opt.params.is_mz_table = true;
14251418
else
@@ -1807,7 +1800,7 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
18071800

18081801
if (!ldb_database_exists(job.dbname))
18091802
ldb_create_database(job.dbname);
1810-
1803+
18111804
struct ldb_importation_jobs_s jobs = {.job = NULL, .number = 0, .common_opt = job.opt};
18121805
strcpy(jobs.dbname, job.dbname);
18131806
jobs.unsorted_index = 0;
@@ -1828,6 +1821,15 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
18281821
if (!table && ldb_dir_exists(path))
18291822
{
18301823
strcpy(job.path, path);
1824+
//check if the version file is present and update the kb version.
1825+
bool version_present = version_import(&job);
1826+
//abort the job if VERSION_VALIDATION is active and the json file is not present
1827+
if (job.opt.params.version_validation && !version_present)
1828+
{
1829+
logger_basic("Failed to validate version.json, check if it is present in %s and it has the correct format\n", job.path);
1830+
exit(EXIT_FAILURE);
1831+
}
1832+
18311833
recurse_directory(&jobs, path, NULL);
18321834
print_jobs(&jobs);
18331835
/* Process jobs*/
@@ -1882,6 +1884,13 @@ bool ldb_import_command(char * dbtable, char * path, char * config)
18821884
{
18831885
strcpy(job.path,path);
18841886
}
1887+
bool version_present = version_import(&job);
1888+
//abort the job if VERSION_VALIDATION is active and the json file is not present
1889+
if (job.opt.params.version_validation && !version_present)
1890+
{
1891+
logger_basic("Failed to validate version.json, check if it is present in %s and it has the correct format\n", job.path);
1892+
exit(EXIT_FAILURE);
1893+
}
18851894
load_import_config(&job);
18861895
process_sectors(&job, threads_list);
18871896
}

src/ldb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "./ldb/types.h"
2828
#include "./ldb/mz.h"
2929

30-
#define LDB_VERSION "4.0.3"
30+
#define LDB_VERSION "4.0.4"
3131

3232
#define LDB_TABLE_DEFINITION_UNDEFINED -1
3333
#define LDB_TABLE_DEFINITION_STANDARD 0

test/source/mined2/quality.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b377b77401a8bfbef9ea316787ebda99,0,4

test/source/mined2/version.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"daily":"24.10.23"}

test/source/mined3/quality.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b377b77401a8bfbef9ea316787ebda99,0,4

test/source/mined3/version.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"daily":"25.10.23"}

test/test_kb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ test_8_unicode_chars() {
5656
assert_equals "b337487d67c0307bb9d009e2b5e248c8,e7bc2c903379c1eda3ec7a12e88b933d,系列1-MyBatis源码解析/第10节课/mybatis-3-master/src/test/java/org/apache/ibatis/submitted/language/VelocitySqlSourceBuilder.java" $result
5757
}
5858

59+
test_9_version_validation() {
60+
../ldb -q -u source/mined2 -n test_kb -q
61+
result=$(cat /var/lib/ldb/test_kb/version.json)
62+
assert_equals "{\"monthly\":\"23.10\", \"daily\":\"24.10.23\"}" "$result"
63+
echo " bulk insert test_kb from source/mined3 with (FILE_DEL=0,VALIDATE_VERSION=0)" | ../ldb
64+
result=$(cat /var/lib/ldb/test_kb/version.json)
65+
assert_equals "{\"monthly\":\"23.10\", \"daily\":\"25.10.23\"}" "$result"
66+
}
67+
5968
setup_suite () {
6069
../ldb -u source/mined -n test_kb
6170
}

0 commit comments

Comments
 (0)