forked from pingcap/tiflash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLASH-386] DeltaMerge DDL support (pingcap#190)
* cast DataType while reading from PageStorage * add isLossyCast function * alter for StroageDeltaMerge, WIP * add Alter for StorageDeltaMerge * add Alter for StorageDeltaMerge * add TableInfo in StroageDeltaMerge * rename table for StorageDeltaMerge * fix bug: the TableInfo from TiDB * add comments for DeltaMerge flush && cache * more faster(?) way to cast mismatch datatype * support cast for numeric type null/not null * support for other data type just change null / not null * isLossyCast -> isSupportedDataTypeCast * isSupportedDataTypeCast add decimal detect * rename function * fix compile errors in gtests * small fix * fix broken tests * support new column with non-zero default value * remove unused code * fix compile error in CI * fix bug in table rename * small fix * minor fix * refine cast function in chunk * update DeltaMergeStore's segments within lock * [WIP]Add test cases for default value ddl. Still has bugs * fix bugs after rebasing to latest master * add some TODO marks * fix compile error in gtests && remove unused comments * fix broken gtests * flush cached chunks in delta instead of doing DeltaMerge when ddl-changes apply * use TypeIndex instead of typeid_cast * clean up data after tests * address comment
- Loading branch information
1 parent
271d3b3
commit e6a12be
Showing
50 changed files
with
2,610 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#include <DataTypes/isSupportedDataTypeCast.h> | ||
#include <Common/typeid_cast.h> | ||
#include <DataTypes/DataTypeNothing.h> | ||
#include <DataTypes/DataTypeArray.h> | ||
#include <DataTypes/DataTypeTuple.h> | ||
#include <DataTypes/DataTypeDate.h> | ||
#include <DataTypes/DataTypeDateTime.h> | ||
#include <DataTypes/DataTypeNullable.h> | ||
#include <DataTypes/DataTypeString.h> | ||
#include <DataTypes/DataTypeFixedString.h> | ||
#include <DataTypes/DataTypeDateTime.h> | ||
#include <DataTypes/DataTypesNumber.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
bool isSupportedDataTypeCast(const DataTypePtr &from, const DataTypePtr &to) | ||
{ | ||
assert(from != nullptr && to != nullptr); | ||
/// `to` is equal to `from` | ||
if (to->equals(*from)) | ||
{ | ||
return true; | ||
} | ||
|
||
/// For Nullable, unwrap DataTypeNullable | ||
{ | ||
bool has_nullable = false; | ||
DataTypePtr from_not_null; | ||
if (const DataTypeNullable * type_nullable = typeid_cast<const DataTypeNullable *>(from.get())) | ||
{ | ||
has_nullable = true; | ||
from_not_null = type_nullable->getNestedType(); | ||
} | ||
else | ||
{ | ||
from_not_null = from; | ||
} | ||
|
||
DataTypePtr to_not_null; | ||
if (const DataTypeNullable * type_nullable = typeid_cast<const DataTypeNullable *>(to.get())) | ||
{ | ||
has_nullable = true; | ||
to_not_null = type_nullable->getNestedType(); | ||
} | ||
else | ||
{ | ||
to_not_null = to; | ||
} | ||
|
||
if (has_nullable) | ||
return isSupportedDataTypeCast(from_not_null, to_not_null); | ||
} | ||
|
||
/// For numeric types (integer, floats) | ||
if (from->isNumber() && to->isNumber()) | ||
{ | ||
/// int <-> float, or float32 <-> float64, is not supported | ||
if (!from->isInteger() || !to->isInteger()) | ||
{ | ||
return false; | ||
} | ||
/// Change from signed to unsigned, or vice versa, is not supported | ||
// use xor(^) | ||
if ((from->isUnsignedInteger()) ^ (to->isUnsignedInteger())) | ||
{ | ||
return false; | ||
} | ||
|
||
/// Both signed or unsigned, compare the sizeof(Type) | ||
size_t from_sz = from->getSizeOfValueInMemory(); | ||
size_t to_sz = to->getSizeOfValueInMemory(); | ||
return from_sz <= to_sz; | ||
} | ||
|
||
/// For String / FixedString | ||
if (from->isStringOrFixedString() && to->isStringOrFixedString()) | ||
{ | ||
size_t from_sz = std::numeric_limits<size_t>::max(); | ||
if (const DataTypeFixedString * type_fixed_str = typeid_cast<const DataTypeFixedString *>(from.get())) | ||
from_sz = type_fixed_str->getN(); | ||
size_t to_sz = std::numeric_limits<size_t>::max(); | ||
if (const DataTypeFixedString * type_fixed_str = typeid_cast<const DataTypeFixedString *>(to.get())) | ||
to_sz = type_fixed_str->getN(); | ||
return from_sz <= to_sz; | ||
} | ||
|
||
/// For Date and DateTime, not supported | ||
if (from->isDateOrDateTime() || to->isDateOrDateTime()) | ||
{ | ||
return false; | ||
} | ||
|
||
{ | ||
bool from_is_decimal = IsDecimalDataType(from); | ||
bool to_is_decimal = IsDecimalDataType(to); | ||
if (from_is_decimal || to_is_decimal) | ||
{ | ||
if (from_is_decimal && to_is_decimal) | ||
{ | ||
// not support change Decimal to other type, neither other type to Decimal | ||
return false; | ||
} | ||
|
||
return from->equals(*to); | ||
} | ||
} | ||
|
||
// TODO enums, set? | ||
|
||
/// some DataTypes that support in ClickHouse but not in TiDB | ||
|
||
// Cast to Nothing / from Nothing is lossy | ||
if (typeid_cast<const DataTypeNothing *>(from.get()) || typeid_cast<const DataTypeNothing *>(to.get())) | ||
{ | ||
return true; | ||
} | ||
|
||
// Cast to Array / from Array is not supported | ||
if (typeid_cast<const DataTypeArray *>(from.get()) || typeid_cast<const DataTypeArray *>(to.get())) | ||
{ | ||
return false; | ||
} | ||
|
||
// Cast to Tuple / from Tuple is not supported | ||
if (typeid_cast<const DataTypeTuple *>(from.get()) || typeid_cast<const DataTypeTuple *>(to.get())) | ||
{ | ||
return false; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <DataTypes/IDataType.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
/// Is TiDB / TiFlash support casting DataType `from` to `to` in DDL | ||
bool isSupportedDataTypeCast(const DataTypePtr &from, const DataTypePtr &to); | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.