Merge pull request #23992 from MaxWk/enable-datatime64-version-column

enable DateTime64 to be version column
This commit is contained in:
Ilya Yatsishin 2021-05-17 14:34:15 +03:00 committed by GitHub
commit 8ede5c736a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 2 deletions

View File

@ -35,6 +35,8 @@ public:
bool canBePromoted() const override { return false; }
bool canBeUsedAsVersion() const override { return true; }
protected:
SerializationPtr doGetDefaultSerialization() const override;
};

View File

@ -177,7 +177,7 @@ public:
*/
virtual bool canBeComparedWithCollation() const { return false; }
/** If the type is totally comparable (Ints, Date, DateTime, not nullable, not floats)
/** If the type is totally comparable (Ints, Date, DateTime, DateTime64, not nullable, not floats)
* and "simple" enough (not String, FixedString) to be used as version number
* (to select rows with maximum version).
*/

View File

@ -648,7 +648,7 @@ void MergeTreeData::MergingParams::check(const StorageInMemoryMetadata & metadat
throw Exception("The column " + version_column +
" cannot be used as a version column for storage " + storage +
" because it is of type " + column.type->getName() +
" (must be of an integer type or of type Date or DateTime)", ErrorCodes::BAD_TYPE_OF_FIELD);
" (must be of an integer type or of type Date/DateTime/DateTime64)", ErrorCodes::BAD_TYPE_OF_FIELD);
miss_column = false;
break;
}

View File

@ -0,0 +1,3 @@
1 1970-01-01 08:25:46.300800003 a1
2 1970-01-01 08:25:46.300800005 a1
3 1970-01-01 08:25:46.300800005 c1

View File

@ -0,0 +1,16 @@
drop table if exists replacing;
create table replacing( `A` Int64, `D` DateTime64(9), `S` String) ENGINE = ReplacingMergeTree(D) ORDER BY A;
insert into replacing values (1,'1970-01-01 08:25:46.300800000','a');
insert into replacing values (2,'1970-01-01 08:25:46.300800002','b');
insert into replacing values (1,'1970-01-01 08:25:46.300800003','a1');
insert into replacing values (1,'1970-01-01 08:25:46.300800002','a2');
insert into replacing values (2,'1970-01-01 08:25:46.300800004','b1');
insert into replacing values (3,'1970-01-01 08:25:46.300800005','c1');
insert into replacing values (2,'1970-01-01 08:25:46.300800005','a1');
OPTIMIZE TABLE replacing FINAL;
select * from replacing;
drop table replacing;