mirror of https://gitee.com/bigwinds/arangodb
added input type jsonl
This commit is contained in:
parent
d55e60cb2e
commit
aab138a4e6
|
@ -115,7 +115,7 @@ void ImportFeature::collectOptions(
|
|||
new DiscreteValuesParameter<StringParameter>(&_createCollectionType,
|
||||
types));
|
||||
|
||||
std::unordered_set<std::string> imports = {"csv", "tsv", "json", "auto"};
|
||||
std::unordered_set<std::string> imports = {"csv", "tsv", "json", "jsonl", "auto"};
|
||||
|
||||
options->addOption(
|
||||
"--type", "type of import file",
|
||||
|
@ -230,12 +230,8 @@ void ImportFeature::start() {
|
|||
}
|
||||
|
||||
std::string extension = match[1].str();
|
||||
if (extension == "json") {
|
||||
_typeImport = "json";
|
||||
} else if (extension == "csv") {
|
||||
_typeImport = "csv";
|
||||
} else if (extension == "tsv") {
|
||||
_typeImport = "tsv";
|
||||
if (extension == "json" || extension == "jsonl" || extension == "csv" || extension == "tsv") {
|
||||
_typeImport = extension;
|
||||
} else {
|
||||
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "Unsupported file extension '" << extension << "'";
|
||||
FATAL_ERROR_EXIT();
|
||||
|
@ -386,9 +382,9 @@ void ImportFeature::start() {
|
|||
arangodb::import::ImportHelper::TSV);
|
||||
}
|
||||
|
||||
else if (_typeImport == "json") {
|
||||
else if (_typeImport == "json" || _typeImport == "jsonl") {
|
||||
std::cout << "Starting JSON import..." << std::endl;
|
||||
ok = ih.importJson(_collectionName, _filename);
|
||||
ok = ih.importJson(_collectionName, _filename, (_typeImport == "jsonl"));
|
||||
}
|
||||
|
||||
else {
|
||||
|
|
|
@ -280,7 +280,8 @@ bool ImportHelper::importDelimited(std::string const& collectionName,
|
|||
}
|
||||
|
||||
bool ImportHelper::importJson(std::string const& collectionName,
|
||||
std::string const& fileName) {
|
||||
std::string const& fileName,
|
||||
bool assumeLinewise) {
|
||||
_collectionName = collectionName;
|
||||
_firstLine = "";
|
||||
_outputBuffer.clear();
|
||||
|
@ -309,6 +310,11 @@ bool ImportHelper::importJson(std::string const& collectionName,
|
|||
bool isObject = false;
|
||||
bool checkedFront = false;
|
||||
|
||||
if (assumeLinewise) {
|
||||
checkedFront = true;
|
||||
isObject = false;
|
||||
}
|
||||
|
||||
// progress display control variables
|
||||
int64_t totalRead = 0;
|
||||
double nextProgress = ProgressStep;
|
||||
|
@ -345,8 +351,7 @@ bool ImportHelper::importJson(std::string const& collectionName,
|
|||
|
||||
if (!checkedFront) {
|
||||
// detect the import file format (single lines with individual JSON
|
||||
// objects
|
||||
// or a JSON array with all documents)
|
||||
// objects or a JSON array with all documents)
|
||||
char const* p = _outputBuffer.begin();
|
||||
char const* e = _outputBuffer.end();
|
||||
|
||||
|
|
|
@ -79,7 +79,8 @@ class ImportHelper {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool importJson(std::string const& collectionName,
|
||||
std::string const& fileName);
|
||||
std::string const& fileName,
|
||||
bool assumeLinewise);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets the action to carry out on duplicate _key
|
||||
|
|
|
@ -1024,7 +1024,7 @@ static void ClientConnection_importJson(
|
|||
std::string fileName = TRI_ObjectToString(isolate, args[0]);
|
||||
std::string collectionName = TRI_ObjectToString(isolate, args[1]);
|
||||
|
||||
if (ih.importJson(collectionName, fileName)) {
|
||||
if (ih.importJson(collectionName, fileName, false)) {
|
||||
v8::Handle<v8::Object> result = v8::Object::New(isolate);
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("lines"),
|
||||
|
|
Loading…
Reference in New Issue