8000 added input type jsonl · georgekaf/arangodb@aab138a · GitHub
[go: up one dir, main page]

Skip to content

Commit aab138a

Browse files
committed
added input type jsonl
1 parent d55e60c commit aab138a

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

arangosh/Import/ImportFeature.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void ImportFeature::collectOptions(
115115
new DiscreteValuesParameter<StringParameter>(&_createCollectionType,
116116
types));
117117

118-
std::unordered_set<std::string> imports = {"csv", "tsv", "json", "auto"};
118+
std::unordered_set<std::string> imports = {"csv", "tsv", "json", "jsonl", "auto"};
119119

120120
options->addOption(
121121
"--type", "type of import file",
@@ -230,12 +230,8 @@ void ImportFeature::start() {
230230
}
231231

232232
std::string extension = match[1].str();
233-
if (extension == "json") {
234-
_typeImport = "json";
235-
} else if (extension == "csv") {
236-
_typeImport = "csv";
237-
} else if (extension == "tsv") {
238-
_typeImport = "tsv";
233+
if (extension == "json" || extension == "jsonl" || extension == "csv" || extension == "tsv") {
234+
_typeImport = extension;
239235
} else {
240236
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "Unsupported file extension '" << extension << "'";
241237
FATAL_ERROR_EXIT();
@@ -386,9 +382,9 @@ void ImportFeature::start() {
386382
arangodb::import::ImportHelper::TSV);
387383
}
388384

389-
else if (_typeImport == "json") {
385+
else if (_typeImport == "json" || _typeImport == "jsonl") {
390386
std::cout << "Starting JSON import..." << std::endl;
391-
ok = ih.importJson(_collectionName, _filename);
387+
ok = ih.importJson(_collectionName, _filename, (_typeImport == "jsonl"));
392388
}
393389

394390
else {

arangosh/Import/ImportHelper.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ bool ImportHelper::importDelimited(std::string const& collectionName,
280280
}
281281

282282
bool ImportHelper::importJson(std::string const& collectionName,
283-
std::string const& fileName) {
283+
std::string const& fileName,
284+
bool assumeLinewise) {
284285
_collectionName = collectionName;
285286
_firstLine = "";
286287
_outputBuffer.clear();
@@ -309,6 +310,11 @@ bool ImportHelper::importJson(std::string const& collectionName,
309310
bool isObject = false;
310311
bool checkedFront = false;
311312

313+
if (assumeLinewise) {
314+
checkedFront = true;
315+
isObject = false;
316+
}
317+
312318
// progress display control variables
313319
int64_t totalRead = 0;
314320
double nextProgress = ProgressStep;
@@ -345,8 +351,7 @@ bool ImportHelper::importJson(std::string const& collectionName,
345351

346352
if (!checkedFront) {
347353
// detect the import file format (single lines with individual JSON
348-
// objects
349-
// or a JSON array with all documents)
354+
// objects or a JSON array with all documents)
350355
char const* p = _outputBuffer.begin();
351356
char const* e = _outputBuffer.end();
352357

arangosh/Import/ImportHelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class ImportHelper {
7979
//////////////////////////////////////////////////////////////////////////////
8080

8181
bool importJson(std::string const& collectionName,
82-
std::string const& fileName);
82+
std::string const& fileName,
83+
bool assumeLinewise);
8384

8485
//////////////////////////////////////////////////////////////////////////////
8586
/// @brief sets the action to carry out on duplicate _key

arangosh/Shell/V8ClientConnection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ static void ClientConnection_importJson(
10241024
std::string fileName = TRI_ObjectToString(isolate, args[0]);
10251025
std::string collectionName = TRI_ObjectToString(isolate, args[1]);
10261026

1027-
if (ih.importJson(collectionName, fileName)) {
1027+
if (ih.importJson(collectionName, fileName, false)) {
10281028
v8::Handle<v8::Object> result = v8::Object::New(isolate);
10291029

10301030
result->Set(TRI_V8_ASCII_STRING("lines"),

0 commit comments

Comments
 (0)
0