Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed groupUniqArray for Date and DateTime types. #263

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions dbms/src/AggregateFunctions/AggregateFunctionGroupUniqArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ namespace DB
namespace
{

/// Substitute return type for Date and DateTime
class AggregateFunctionGroupUniqArrayDate : public AggregateFunctionGroupUniqArray<DataTypeDate::FieldType>
{
DataTypePtr getReturnType() const override { return std::make_shared<DataTypeArray>(std::make_shared<DataTypeDate>()); }
};

class AggregateFunctionGroupUniqArrayDateTime : public AggregateFunctionGroupUniqArray<DataTypeDateTime::FieldType>
{
DataTypePtr getReturnType() const override { return std::make_shared<DataTypeArray>(std::make_shared<DataTypeDateTime>()); }
};


static IAggregateFunction * createWithExtraTypes(const IDataType & argument_type)
{
if (typeid_cast<const DataTypeDateTime *>(&argument_type)) return new AggregateFunctionGroupUniqArray<DataTypeDateTime::FieldType>;
else if (typeid_cast<const DataTypeDate *>(&argument_type)) return new AggregateFunctionGroupUniqArray<DataTypeDate::FieldType>;
if (typeid_cast<const DataTypeDate *>(&argument_type)) return new AggregateFunctionGroupUniqArrayDate;
else if (typeid_cast<const DataTypeDateTime *>(&argument_type)) return new AggregateFunctionGroupUniqArrayDateTime;
else
{
/// Check that we can use plain version of AggreagteFunctionGroupUniqArrayGeneric
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
['2016-12-16'] ['2016-12-16 12:00:00']
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TABLE IF EXISTS test.grop_uniq_array_date;
CREATE TABLE test.grop_uniq_array_date (d Date, dt DateTime) ENGINE = Memory;
INSERT INTO test.grop_uniq_array_date VALUES (toDate('2016-12-16'), toDateTime('2016-12-16 12:00:00')) (toDate('2016-12-16'), toDateTime('2016-12-16 12:00:00'));
SELECT groupUniqArray(d), groupUniqArray(dt) FROM test.grop_uniq_array_date;
DROP TABLE IF EXISTS test.grop_uniq_array_date;