// Copyright 2021 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source // License, and you may not use this file except in compliance with the Business Source License. // // As of the Change Date specified in that file, in accordance with // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. #include #include #include #include #include #include #include #include #include "helpers.hpp" #include "storage/v2/storage.hpp" #include "utils/exceptions.hpp" #include "utils/logging.hpp" #include "utils/message.hpp" #include "utils/string.hpp" #include "utils/timer.hpp" #include "version.hpp" bool ValidateControlCharacter(const char *flagname, const std::string &value) { if (value.empty()) { printf("The argument '%s' cannot be empty\n", flagname); return false; } if (value.find('\n') != std::string::npos) { printf("The argument '%s' cannot contain a newline character\n", flagname); return false; } return true; } bool ValidateIdTypeOptions(const char *flagname, const std::string &value) { std::string upper = utils::ToUpperCase(utils::Trim(value)); if (upper != "STRING" && upper != "INTEGER") { printf("Valid options for '%s' are: STRING/INTEGER\n", flagname); return false; } return true; } // Memgraph flags. // NOTE: These flags must be identical as the flags in the main Memgraph binary. // They are used to automatically load the same configuration as the main // Memgraph binary so that the flags don't need to be specified when importing a // CSV file on a correctly set-up Memgraph installation. DEFINE_string(data_directory, "mg_data", "Path to directory in which to save all permanent data."); DEFINE_bool(storage_properties_on_edges, false, "Controls whether relationships have properties."); // CSV import flags. DEFINE_string(array_delimiter, ";", "Delimiter between elements of array values."); DEFINE_validator(array_delimiter, &ValidateControlCharacter); DEFINE_string(delimiter, ",", "Delimiter between each field in the CSV."); DEFINE_validator(delimiter, &ValidateControlCharacter); DEFINE_string(quote, "\"", "Quotation character for data in the CSV. Cannot contain '\n'"); DEFINE_validator(quote, &ValidateControlCharacter); DEFINE_bool(skip_duplicate_nodes, false, "Set to true to skip duplicate nodes instead of raising an error."); DEFINE_bool(skip_bad_relationships, false, "Set to true to skip relationships that connect nodes that don't " "exist instead of raising an error."); DEFINE_bool(ignore_empty_strings, false, "Set to true to treat empty strings as null values."); DEFINE_bool(ignore_extra_columns, false, "Set to true to ignore columns that aren't specified in the header."); DEFINE_bool(trim_strings, false, "Set to true to trim leading/trailing whitespace from all fields " "that are loaded from the CSV file."); DEFINE_string(id_type, "STRING", "Which data type should be used to store the supplied node IDs. " "Possible options are: STRING/INTEGER"); DEFINE_validator(id_type, &ValidateIdTypeOptions); // Arguments `--nodes` and `--relationships` can be input multiple times and are // handled with custom parsing. DEFINE_string(nodes, "", "Files that should be parsed for nodes. The CSV header will be loaded from " "the first supplied file, all other files supplied in a single flag will " "be treated as data files. Additional labels can be specified for the node " "files. The flag can be specified multiple times (useful for differently " "formatted node files). The format of this argument is: " "[