2011-10-24 12:10:59 +00:00
|
|
|
#include <DB/DataStreams/NativeBlockInputStream.h>
|
|
|
|
#include <DB/DataStreams/NativeBlockOutputStream.h>
|
|
|
|
#include <DB/DataStreams/TabSeparatedRowInputStream.h>
|
|
|
|
#include <DB/DataStreams/TabSeparatedRowOutputStream.h>
|
2012-08-17 19:53:11 +00:00
|
|
|
#include <DB/DataStreams/TabSeparatedRawRowOutputStream.h>
|
2012-11-10 04:43:53 +00:00
|
|
|
#include <DB/DataStreams/BinaryRowInputStream.h>
|
|
|
|
#include <DB/DataStreams/BinaryRowOutputStream.h>
|
2011-10-30 05:19:41 +00:00
|
|
|
#include <DB/DataStreams/ValuesRowInputStream.h>
|
|
|
|
#include <DB/DataStreams/ValuesRowOutputStream.h>
|
2011-11-06 06:22:52 +00:00
|
|
|
#include <DB/DataStreams/TabSeparatedBlockOutputStream.h>
|
2011-11-07 01:15:37 +00:00
|
|
|
#include <DB/DataStreams/PrettyBlockOutputStream.h>
|
2011-11-28 04:05:53 +00:00
|
|
|
#include <DB/DataStreams/PrettyCompactBlockOutputStream.h>
|
|
|
|
#include <DB/DataStreams/PrettySpaceBlockOutputStream.h>
|
|
|
|
#include <DB/DataStreams/VerticalRowOutputStream.h>
|
2012-05-08 11:19:00 +00:00
|
|
|
#include <DB/DataStreams/NullBlockOutputStream.h>
|
2011-10-24 12:10:59 +00:00
|
|
|
#include <DB/DataStreams/BlockInputStreamFromRowInputStream.h>
|
|
|
|
#include <DB/DataStreams/BlockOutputStreamFromRowOutputStream.h>
|
2013-05-15 11:51:54 +00:00
|
|
|
#include <DB/DataStreams/JSONRowOutputStream.h>
|
|
|
|
#include <DB/DataStreams/JSONCompactRowOutputStream.h>
|
2015-07-18 04:27:38 +00:00
|
|
|
#include <DB/DataStreams/TSKVRowOutputStream.h>
|
2013-06-17 12:40:44 +00:00
|
|
|
#include <DB/DataStreams/PrettyCompactMonoBlockOutputStream.h>
|
2016-01-13 02:20:12 +00:00
|
|
|
#include <DB/DataStreams/ODBCDriverBlockOutputStream.h>
|
2016-02-07 08:42:21 +00:00
|
|
|
#include <DB/DataStreams/CSVRowInputStream.h>
|
|
|
|
#include <DB/DataStreams/CSVRowOutputStream.h>
|
2011-10-24 12:10:59 +00:00
|
|
|
#include <DB/DataStreams/FormatFactory.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int FORMAT_IS_NOT_SUITABLE_FOR_INPUT;
|
|
|
|
extern const int UNKNOWN_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-24 12:10:59 +00:00
|
|
|
BlockInputStreamPtr FormatFactory::getInput(const String & name, ReadBuffer & buf,
|
2016-02-13 06:37:19 +00:00
|
|
|
const Block & sample, const Context & context, size_t max_block_size) const
|
2011-10-24 12:10:59 +00:00
|
|
|
{
|
|
|
|
if (name == "Native")
|
2015-05-28 03:49:28 +00:00
|
|
|
return new NativeBlockInputStream(buf);
|
2012-11-10 04:43:53 +00:00
|
|
|
else if (name == "RowBinary")
|
|
|
|
return new BlockInputStreamFromRowInputStream(new BinaryRowInputStream(buf, sample), sample, max_block_size);
|
2016-02-07 08:42:21 +00:00
|
|
|
else if (name == "TabSeparated")
|
|
|
|
return new BlockInputStreamFromRowInputStream(new TabSeparatedRowInputStream(buf, sample), sample, max_block_size);
|
2011-11-06 06:22:52 +00:00
|
|
|
else if (name == "TabSeparatedWithNames")
|
|
|
|
return new BlockInputStreamFromRowInputStream(new TabSeparatedRowInputStream(buf, sample, true), sample, max_block_size);
|
|
|
|
else if (name == "TabSeparatedWithNamesAndTypes")
|
|
|
|
return new BlockInputStreamFromRowInputStream(new TabSeparatedRowInputStream(buf, sample, true, true), sample, max_block_size);
|
2011-10-30 05:19:41 +00:00
|
|
|
else if (name == "Values")
|
2016-02-13 06:37:19 +00:00
|
|
|
return new BlockInputStreamFromRowInputStream(new ValuesRowInputStream(buf, sample, context), sample, max_block_size);
|
2016-02-07 08:42:21 +00:00
|
|
|
else if (name == "CSV")
|
|
|
|
return new BlockInputStreamFromRowInputStream(new CSVRowInputStream(buf, sample, ','), sample, max_block_size);
|
|
|
|
else if (name == "CSVWithNames")
|
|
|
|
return new BlockInputStreamFromRowInputStream(new CSVRowInputStream(buf, sample, ',', true), sample, max_block_size);
|
2015-09-20 04:04:52 +00:00
|
|
|
else if (name == "TabSeparatedRaw"
|
|
|
|
|| name == "BlockTabSeparated"
|
|
|
|
|| name == "Pretty"
|
|
|
|
|| name == "PrettyCompact"
|
|
|
|
|| name == "PrettyCompactMonoBlock"
|
|
|
|
|| name == "PrettySpace"
|
|
|
|
|| name == "PrettyNoEscapes"
|
|
|
|
|| name == "PrettyCompactNoEscapes"
|
|
|
|
|| name == "PrettySpaceNoEscapes"
|
|
|
|
|| name == "Vertical"
|
|
|
|
|| name == "VerticalRaw"
|
|
|
|
|| name == "Null"
|
|
|
|
|| name == "JSON"
|
|
|
|
|| name == "JSONCompact"
|
2015-10-31 07:14:03 +00:00
|
|
|
|| name == "TSKV"
|
2016-01-13 02:20:12 +00:00
|
|
|
|| name == "ODBCDriver")
|
2015-09-20 04:04:52 +00:00
|
|
|
throw Exception("Format " + name + " is not suitable for input", ErrorCodes::FORMAT_IS_NOT_SUITABLE_FOR_INPUT);
|
2011-10-24 12:10:59 +00:00
|
|
|
else
|
|
|
|
throw Exception("Unknown format " + name, ErrorCodes::UNKNOWN_FORMAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockOutputStreamPtr FormatFactory::getOutput(const String & name, WriteBuffer & buf,
|
2016-02-13 06:37:19 +00:00
|
|
|
const Block & sample, const Context & context) const
|
2011-10-24 12:10:59 +00:00
|
|
|
{
|
|
|
|
if (name == "Native")
|
|
|
|
return new NativeBlockOutputStream(buf);
|
2012-11-10 04:43:53 +00:00
|
|
|
else if (name == "RowBinary")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new BinaryRowOutputStream(buf, sample));
|
2016-02-07 08:42:21 +00:00
|
|
|
else if (name == "TabSeparated")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new TabSeparatedRowOutputStream(buf, sample));
|
2011-11-06 06:22:52 +00:00
|
|
|
else if (name == "TabSeparatedWithNames")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new TabSeparatedRowOutputStream(buf, sample, true));
|
|
|
|
else if (name == "TabSeparatedWithNamesAndTypes")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new TabSeparatedRowOutputStream(buf, sample, true, true));
|
2012-08-17 19:53:11 +00:00
|
|
|
else if (name == "TabSeparatedRaw")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new TabSeparatedRawRowOutputStream(buf, sample));
|
2011-11-06 06:22:52 +00:00
|
|
|
else if (name == "BlockTabSeparated")
|
|
|
|
return new TabSeparatedBlockOutputStream(buf);
|
2016-02-07 08:42:21 +00:00
|
|
|
else if (name == "CSV")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new CSVRowOutputStream(buf, sample));
|
|
|
|
else if (name == "CSVWithNames")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new CSVRowOutputStream(buf, sample, true));
|
2011-11-07 01:15:37 +00:00
|
|
|
else if (name == "Pretty")
|
|
|
|
return new PrettyBlockOutputStream(buf);
|
2011-11-28 04:05:53 +00:00
|
|
|
else if (name == "PrettyCompact")
|
|
|
|
return new PrettyCompactBlockOutputStream(buf);
|
2015-09-20 04:04:52 +00:00
|
|
|
else if (name == "PrettyCompactMonoBlock")
|
|
|
|
return new PrettyCompactMonoBlockOutputStream(buf);
|
2011-11-28 04:05:53 +00:00
|
|
|
else if (name == "PrettySpace")
|
|
|
|
return new PrettySpaceBlockOutputStream(buf);
|
2012-06-25 05:07:34 +00:00
|
|
|
else if (name == "PrettyNoEscapes")
|
|
|
|
return new PrettyBlockOutputStream(buf, true);
|
|
|
|
else if (name == "PrettyCompactNoEscapes")
|
|
|
|
return new PrettyCompactBlockOutputStream(buf, true);
|
|
|
|
else if (name == "PrettySpaceNoEscapes")
|
|
|
|
return new PrettySpaceBlockOutputStream(buf, true);
|
2011-11-28 04:05:53 +00:00
|
|
|
else if (name == "Vertical")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new VerticalRowOutputStream(buf, sample));
|
2015-09-20 04:04:52 +00:00
|
|
|
else if (name == "VerticalRaw")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new VerticalRawRowOutputStream(buf, sample));
|
2011-10-30 05:19:41 +00:00
|
|
|
else if (name == "Values")
|
2011-11-06 05:01:42 +00:00
|
|
|
return new BlockOutputStreamFromRowOutputStream(new ValuesRowOutputStream(buf, sample));
|
2013-05-15 11:51:54 +00:00
|
|
|
else if (name == "JSON")
|
2013-05-22 14:57:43 +00:00
|
|
|
return new BlockOutputStreamFromRowOutputStream(new JSONRowOutputStream(buf, sample));
|
2013-05-15 11:51:54 +00:00
|
|
|
else if (name == "JSONCompact")
|
2013-05-22 14:57:43 +00:00
|
|
|
return new BlockOutputStreamFromRowOutputStream(new JSONCompactRowOutputStream(buf, sample));
|
2015-07-18 04:27:38 +00:00
|
|
|
else if (name == "TSKV")
|
|
|
|
return new BlockOutputStreamFromRowOutputStream(new TSKVRowOutputStream(buf, sample));
|
2016-01-13 02:20:12 +00:00
|
|
|
else if (name == "ODBCDriver")
|
|
|
|
return new ODBCDriverBlockOutputStream(buf);
|
2012-05-08 11:19:00 +00:00
|
|
|
else if (name == "Null")
|
|
|
|
return new NullBlockOutputStream;
|
2011-10-24 12:10:59 +00:00
|
|
|
else
|
|
|
|
throw Exception("Unknown format " + name, ErrorCodes::UNKNOWN_FORMAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|