IODA Bundle
SQLOutputConfig.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include "eckit/sql/SQLSimpleOutput.h"
12 
13 #include "odc/DispatchingWriter.h"
14 #include "odc/sql/ODAOutput.h"
16 #include "odc/TemplateParameters.h"
17 #include "odc/Writer.h"
18 
19 namespace odc {
20 namespace sql {
21 
22 //----------------------------------------------------------------------------------------------------------------------
23 
24 
26  bool noNULL,
27  const std::string& delimiter,
28  const std::string& format,
29  bool bitfieldsBinary,
30  bool noColumnAlignment,
31  bool fullPrecision) :
32  eckit::sql::SQLOutputConfig(noColumnNames, noNULL, delimiter, format,
33  bitfieldsBinary, noColumnAlignment, fullPrecision),
34  outStream_(std::cout) {}
35 
36 SQLOutputConfig::SQLOutputConfig(const std::string& odbFilename) :
37  SQLOutputConfig() {
38  outputFormat_ = "odb";
39  outputFile_ = odbFilename;
40 }
41 
43 
44 eckit::sql::SQLOutput* SQLOutputConfig::buildOutput(const eckit::PathName& path) const {
45 
46  // TODO: maxOpenFiles configuration for output. Was disabled in Feb 2016
47  const size_t maxOpenFiles = 100;
48 
49  std::string format (path.asString().empty() ? outputFormat_ : "odb");
50 
51  if (format == "default" || format == "wide") {
52  return new eckit::sql::SQLSimpleOutput(*this, outStream_.get());
53  } else if (format == "odb") {
54  ASSERT(path.asString().size());
55  TemplateParameters templateParameters;
56  TemplateParameters::parse(path, templateParameters);
57  if (templateParameters.size()) {
58  return new odc::sql::ODAOutput<DispatchingWriter>(new DispatchingWriter(path, maxOpenFiles));
59  } else {
60  return new odc::sql::ODAOutput<Writer<>>(new Writer<>(path));
61  // TODO: toODAColumns
62  }
63 
64  }
65  NOTIMP;
66 }
67 
68 void SQLOutputConfig::setOutputStream(std::ostream& s) {
69  outStream_ = s;
70 }
71 
72 
73 //----------------------------------------------------------------------------------------------------------------------
74 
75 } // namespace sql
76 } // namespace odc
static TemplateParameters & parse(const std::string &fileNameTemplate, TemplateParameters &, const core::MetaData &=nullMD)
eckit::sql::SQLOutput * buildOutput(const eckit::PathName &path) const override
void setOutputStream(std::ostream &s)
SQLOutputConfig(bool noColumnNames=false, bool noNULL=false, const std::string &delimiter=defaultDelimiter, const std::string &format=defaultOutputFormat, bool bitfieldsBinary=false, bool noColumnAlignment=false, bool fullPrecision=false)
std::reference_wrapper< std::ostream > outStream_
Definition: ColumnInfo.h:23
Definition: encode.cc:30