-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A utility for parsing CSV dialect parameters of the ingest requests
- Loading branch information
1 parent
21f2835
commit 24a35fd
Showing
4 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* LSST Data Management System | ||
* | ||
* This product includes software developed by the | ||
* LSST Project (http://www.lsst.org/). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the LSST License Statement and | ||
* the GNU General Public License along with this program. If not, | ||
* see <http://www.lsstcorp.org/LegalNotices/>. | ||
*/ | ||
|
||
// Class header | ||
#include "replica/ingest/IngestUtils.h" | ||
|
||
// Qserv headers | ||
#include "http/RequestBodyJSON.h" | ||
#include "replica/util/Csv.h" | ||
|
||
using namespace std; | ||
|
||
namespace lsst::qserv::replica { | ||
|
||
csv::DialectInput parseDialectInput(http::RequestBodyJSON const& body) { | ||
csv::DialectInput dialectInput; | ||
|
||
// Allow an empty string in the input. Simply replace the one (if present) with | ||
// the corresponding default value of the parameter. | ||
auto const getDialectParam = [&](string const& param, string const& defaultValue) -> string { | ||
string val = body.optional<string>(param, defaultValue); | ||
if (val.empty()) val = defaultValue; | ||
return val; | ||
}; | ||
dialectInput.fieldsTerminatedBy = | ||
getDialectParam("fields_terminated_by", csv::Dialect::defaultFieldsTerminatedBy); | ||
dialectInput.fieldsEnclosedBy = | ||
getDialectParam("fields_enclosed_by", csv::Dialect::defaultFieldsEnclosedBy); | ||
dialectInput.fieldsEscapedBy = getDialectParam("fields_escaped_by", csv::Dialect::defaultFieldsEscapedBy); | ||
dialectInput.linesTerminatedBy = | ||
getDialectParam("lines_terminated_by", csv::Dialect::defaultLinesTerminatedBy); | ||
|
||
return dialectInput; | ||
} | ||
|
||
} // namespace lsst::qserv::replica |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* LSST Data Management System | ||
* | ||
* This product includes software developed by the | ||
* LSST Project (http://www.lsst.org/). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the LSST License Statement and | ||
* the GNU General Public License along with this program. If not, | ||
* see <http://www.lsstcorp.org/LegalNotices/>. | ||
*/ | ||
#ifndef LSST_QSERV_REPLICA_INGESTUTILS_H | ||
#define LSST_QSERV_REPLICA_INGESTUTILS_H | ||
|
||
// System headers | ||
#include <string> | ||
|
||
// Third party headers | ||
#include "nlohmann/json.hpp" | ||
|
||
// Qserv headers | ||
#include "http/RequestBodyJSON.h" | ||
|
||
// Forward declarations | ||
|
||
namespace lsst::qserv::http { | ||
class RequestBodyJSON; | ||
} // namespace lsst::qserv::http | ||
|
||
namespace lsst::qserv::replica::csv { | ||
class DialectInput; | ||
} // namespace lsst::qserv::replica::csv | ||
|
||
// This header declarations | ||
namespace lsst::qserv::replica { | ||
|
||
/** | ||
* Parse the dialect input from the request body. | ||
* @param body The request body. | ||
* @return The parsed dialect input. | ||
*/ | ||
csv::DialectInput parseDialectInput(http::RequestBodyJSON const& body); | ||
|
||
} // namespace lsst::qserv::replica | ||
|
||
#endif // LSST_QSERV_REPLICA_INGESTUTILS_H |