提交 0787bd66 编写于 作者: P proller 提交者: alexey-milovidov

Merge: fail if cant convert columns (#753)

* Merge: fail if cant convert columns

* Merge: convert all different types, more tests

* clean

* clean

* clean
上级 bb257eec
......@@ -9,6 +9,7 @@
namespace DB
{
CastTypeBlockInputStream::CastTypeBlockInputStream(
const Context & context_,
BlockInputStreamPtr input_,
......@@ -109,14 +110,8 @@ void CastTypeBlockInputStream::collectDifferent(const Block & in_sample, const B
const auto & in_elem = in_sample.getByPosition(i);
const auto & out_elem = out_sample.getByPosition(i);
/// Force conversion if source type is not Enum.
if (dynamic_cast<IDataTypeEnum*>(out_elem.type.get())
&& !dynamic_cast<IDataTypeEnum*>(in_elem.type.get()))
{
cast_types[i] = NameAndTypePair(out_elem.name, out_elem.type);
}
/// Force conversion if both types is numeric but not equal.
else if (in_elem.type->behavesAsNumber() && out_elem.type->behavesAsNumber() && !out_elem.type->equals(*in_elem.type))
/// Force conversion if source and destination types is different.
if (!out_elem.type->equals(*in_elem.type))
{
cast_types[i] = NameAndTypePair(out_elem.name, out_elem.type);
}
......
......@@ -181,7 +181,10 @@ BlockInputStreams StorageMerge::read(
/// Subordinary tables could have different but convertible types, like numeric types of different width.
/// We must return streams with structure equals to structure of Merge table.
for (auto & stream : source_streams)
{
/// will throw if some columns not convertible
stream = std::make_shared<CastTypeBlockInputStream>(context, stream, table->getSampleBlock(), getSampleBlock());
}
}
else
{
......@@ -207,7 +210,10 @@ BlockInputStreams StorageMerge::read(
auto stream = streams.empty() ? std::make_shared<NullBlockInputStream>() : streams.front();
if (!streams.empty())
{
/// will throw if some columns not convertible
stream = std::make_shared<CastTypeBlockInputStream>(context, stream, table->getSampleBlock(), getSampleBlock());
}
return stream;
}));
}
......
UInt32 | UInt64
= 1:
1
1
......@@ -9,7 +10,24 @@
4294967290
4294967299:
4294967299
Int64 | UInt64
1:
1
1
-1:
Int32 | UInt64
1
1
2147483650
String | FixedString(16)
1
1
DateTime | UInt64
1
1
Array(UInt32) | Array(UInt64)
[1]
[1]
[4294967290]
[4294967290]
[4294967299]
SELECT ' UInt32 | UInt64 ';
DROP TABLE IF EXISTS test.u32;
DROP TABLE IF EXISTS test.u64;
DROP TABLE IF EXISTS test.merge_32_64;
......@@ -31,6 +34,7 @@ DROP TABLE test.u64;
DROP TABLE test.merge_32_64;
SELECT ' Int64 | UInt64 ';
DROP TABLE IF EXISTS test.s64;
DROP TABLE IF EXISTS test.u64;
......@@ -52,3 +56,82 @@ SELECT x FROM test.merge_s64_u64 WHERE x IN (-1);
DROP TABLE test.s64;
DROP TABLE test.u64;
DROP TABLE test.merge_s64_u64;
SELECT ' Int32 | UInt64 ';
DROP TABLE IF EXISTS test.one;
DROP TABLE IF EXISTS test.two;
DROP TABLE IF EXISTS test.merge_one_two;
CREATE TABLE test.one (x Int32) ENGINE = Memory;
CREATE TABLE test.two (x UInt64) ENGINE = Memory;
CREATE TABLE test.merge_one_two (x UInt64) ENGINE = Merge(test, 'one|two');
INSERT INTO test.one VALUES (1);
INSERT INTO test.two VALUES (1);
INSERT INTO test.one VALUES (2147483650);
INSERT INTO test.two VALUES (2147483650);
SELECT * FROM test.merge_one_two WHERE x IN (1);
SELECT x FROM test.merge_one_two WHERE x IN (2147483650);
SELECT x FROM test.merge_one_two WHERE x IN (-1);
SELECT ' String | FixedString(16) ';
DROP TABLE IF EXISTS test.one;
DROP TABLE IF EXISTS test.two;
DROP TABLE IF EXISTS test.merge_one_two;
CREATE TABLE test.one (x String) ENGINE = Memory;
CREATE TABLE test.two (x FixedString(16)) ENGINE = Memory;
CREATE TABLE test.merge_one_two (x String) ENGINE = Merge(test, 'one|two');
INSERT INTO test.one VALUES ('1');
INSERT INTO test.two VALUES ('1');
SELECT * FROM test.merge_one_two WHERE x IN ('1');
SELECT ' DateTime | UInt64 ';
DROP TABLE IF EXISTS test.one;
DROP TABLE IF EXISTS test.two;
DROP TABLE IF EXISTS test.merge_one_two;
CREATE TABLE test.one (x DateTime) ENGINE = Memory;
CREATE TABLE test.two (x UInt64) ENGINE = Memory;
CREATE TABLE test.merge_one_two (x UInt64) ENGINE = Merge(test, 'one|two');
INSERT INTO test.one VALUES (1);
INSERT INTO test.two VALUES (1);
SELECT * FROM test.merge_one_two WHERE x IN (1);
SELECT ' Array(UInt32) | Array(UInt64) ';
DROP TABLE IF EXISTS test.one;
DROP TABLE IF EXISTS test.two;
DROP TABLE IF EXISTS test.merge_one_two;
CREATE TABLE test.one (x Array(UInt32)) ENGINE = Memory;
CREATE TABLE test.two (x Array(UInt64)) ENGINE = Memory;
CREATE TABLE test.merge_one_two (x Array(UInt64)) ENGINE = Merge(test, 'one|two');
INSERT INTO test.one VALUES ([1]);
INSERT INTO test.two VALUES ([1]);
INSERT INTO test.one VALUES ([4294967290]);
INSERT INTO test.two VALUES ([4294967290]);
INSERT INTO test.one VALUES ([4294967299]);
INSERT INTO test.two VALUES ([4294967299]);
SELECT x FROM test.merge_one_two WHERE x IN (1);
SELECT x FROM test.merge_one_two WHERE x IN (4294967290);
SELECT x FROM test.merge_one_two WHERE x IN (4294967299);
DROP TABLE IF EXISTS test.one;
DROP TABLE IF EXISTS test.two;
DROP TABLE IF EXISTS test.merge_one_two;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册