1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-07 03:22:57 +03:00

Adding support for enum continuation

This commit is contained in:
Nedeljko Stefanovic
2025-06-30 08:18:05 +00:00
parent b96e5e6618
commit d7ee669696
12 changed files with 121 additions and 4 deletions

View File

@@ -283,6 +283,12 @@ const string& TypeHandlerBit::name() const
return xname;
}
const string& TypeHandlerEnum::name() const
{
static const string xname = "ENUM";
return xname;
}
TypeHandlerBit mcs_type_handler_bit;
TypeHandlerSInt8 mcs_type_handler_sint8;
@@ -297,6 +303,8 @@ TypeHandlerUInt24 mcs_type_handler_uint24;
TypeHandlerUInt32 mcs_type_handler_uint32;
TypeHandlerUInt64 mcs_type_handler_uint64;
TypeHandlerEnum mcs_type_handler_enum;
TypeHandlerSFloat mcs_type_handler_sfloat;
TypeHandlerSDouble mcs_type_handler_sdouble;
TypeHandlerSLongDouble mcs_type_handler_slongdouble;
@@ -344,6 +352,8 @@ const TypeHandler* TypeHandler::find(SystemCatalog::ColDataType typeCode,
case SystemCatalog::UFLOAT: return &mcs_type_handler_ufloat;
case SystemCatalog::UDOUBLE: return &mcs_type_handler_udouble;
case SystemCatalog::ENUM: return &mcs_type_handler_enum;
case SystemCatalog::DECIMAL:
if (static_cast<uint32_t>(ct.colWidth) < datatypes::MAXDECIMALWIDTH)
return &mcs_type_handler_sdecimal64;
@@ -434,6 +444,8 @@ const TypeHandler* TypeHandler::find_by_ddltype(const ddlpackage::ColumnType& ct
case ddlpackage::DDL_UNSIGNED_INT: return &mcs_type_handler_uint32;
case ddlpackage::DDL_UNSIGNED_BIGINT: return &mcs_type_handler_uint64;
case ddlpackage::DDL_ENUM: return &mcs_type_handler_sint16;
case ddlpackage::DDL_UNSIGNED_DECIMAL:
case ddlpackage::DDL_UNSIGNED_NUMERIC:
@@ -1543,12 +1555,29 @@ boost::any TypeHandlerVarbinary::getNullValueForType(const SystemCatalog::TypeAt
/****************************************************************************/
boost::any TypeHandlerBit::convertFromString(const SystemCatalog::TypeAttributesStd& colType,
const ConvertFromStringParam& prm, const std::string& data,
bool& pushWarning) const
const ConvertFromStringParam& prm, const std::string& data,
bool& pushWarning) const
{
return dataconvert::DataConvert::StringToBit(colType, prm, data, pushWarning);
}
boost::any TypeHandlerEnum::convertFromString(const SystemCatalog::TypeAttributesStd& colType,
const ConvertFromStringParam&, const std::string& data,
bool&) const
{
unsigned short val = 0;
for (; val<colType.enumVals.size(); ++val) {
if (colType.enumVals[val] == data) {
break;
}
}
boost::any value = val;
return value;
}
boost::any TypeHandlerSInt8::convertFromString(const SystemCatalog::TypeAttributesStd& colType,
const ConvertFromStringParam& prm, const std::string& data,
bool& pushWarning) const

View File

@@ -152,6 +152,7 @@ class SystemCatalog
enum ColDataType
{
BIT, /*!< BIT type */
ENUM, /*!< ENUM type */
TINYINT, /*!< TINYINT type */
CHAR, /*!< CHAR type */
SMALLINT, /*!< SMALLINT type */
@@ -195,6 +196,8 @@ class SystemCatalog
int32_t colWidth;
int32_t scale; // number after decimal points
int32_t precision;
std::vector<std::string> enumVals;
TypeAttributesStd() : colWidth(0), scale(0), precision(-1)
{
}
@@ -1143,6 +1146,65 @@ class TypeHandlerBit : public TypeHandler
}
};
// QQ: perhaps not needed yet
class TypeHandlerEnum : public TypeHandler
{
const string& name() const override;
code_t code() const override
{
return SystemCatalog::ENUM;
}
size_t ColWriteBatch(WriteBatchField* /*field*/, const unsigned char* /*buf*/, bool /*nullVal*/,
ColBatchWriter& /*writer*/) const override
{
idbassert(0); // QQ
return 0;
}
int storeValueToField(rowgroup::Row& /*row*/, int /*pos*/, StoreField* /*f*/) const override
{
idbassert(0); // QQ
return 0;
}
std::string format(const SimpleValue& /*v*/, const SystemCatalog::TypeAttributesStd& /*attr*/) const override
{
return "0"; // QQ
}
std::string formatPartitionInfo(const SystemCatalog::TypeAttributesStd& /*attr*/,
const MinMaxInfo& /*i*/) const override
{
idbassert(0);
return "Error";
}
execplan::SimpleColumn* newSimpleColumn(const DatabaseQualifiedColumnName& /*name*/,
SystemCatalog::TypeHolderStd& /*ct*/,
const SimpleColumnParam& /*prm*/) const override
{
idbassert(0);
return nullptr;
}
SimpleValue toSimpleValue(const SessionParam& /*sp*/, const SystemCatalog::TypeAttributesStd& /*attr*/,
const char* /*str*/, round_style_t& /*rf*/) const override
{
idbassert(0);
return {};
}
boost::any getNullValueForType(const SystemCatalog::TypeAttributesStd& /*attr*/) const override
{
// TODO: How to communicate with write engine?
return {};
}
boost::any convertFromString(const SystemCatalog::TypeAttributesStd& /*colType*/,
const ConvertFromStringParam& /*prm*/, const std::string& /*str*/,
bool& /*pushWarning*/) const override;
const uint8_t* getEmptyValueForType(const SystemCatalog::TypeAttributesStd& /*attr*/) const override
{
idbassert(0);
return nullptr;
}
};
class TypeHandlerInt : public TypeHandler
{
protected:

View File

@@ -217,6 +217,7 @@ enum DDL_DATATYPES
/** @brief Datatype string list
*/
const std::string DDLDatatypeString[] = {"bit",
"enum",
"tinyint",
"char",
"smallint",
@@ -261,6 +262,7 @@ const std::string AlterActionString[] = {
*/
const int DDLDatatypeLength[] = {
1, // BIT
2, // ENUM
1, // TINYINT
1, // CHAR
2, // SMALLINT

View File

@@ -1138,6 +1138,7 @@ int ColumnType::unserialize(ByteStream& bytestream)
bytestream >> nextVal;
bytestream >> charsetNum;
bytestream >> enumValuesNum;
fEnumValues.clear();
for (size_t i = 0; i<fEnumValues.size(); ++i) {
std::string value;

View File

@@ -108,6 +108,12 @@ bool typesAreSame(const CalpontSystemCatalog::ColType& colType, const ColumnType
break;
case (CalpontSystemCatalog::ENUM):
if (newType.fType == DDL_ENUM && colType.enumVals == newType.fEnumValues)
return true;
break;
case (CalpontSystemCatalog::TINYINT):
if (newType.fType == DDL_TINYINT && colType.precision == newType.fPrecision &&
colType.scale == newType.fScale)

View File

@@ -314,6 +314,12 @@ boost::any DDLIndexPopulator::convertData(const CalpontSystemCatalog::ColType& c
switch (colType.colDataType)
{
case CalpontSystemCatalog::BIT:
case CalpontSystemCatalog::ENUM:
{
string strData(colType.fEnumValues[data]);
return *reinterpret_cast<string*>(&strData);
}
case execplan::CalpontSystemCatalog::TINYINT: return *reinterpret_cast<char*>(&data);
case execplan::CalpontSystemCatalog::SMALLINT: return *reinterpret_cast<short*>(&data);
@@ -460,6 +466,10 @@ bool DDLIndexPopulator::checkNotNull(const IdxTuple& data, const CalpontSystemCa
{
case CalpontSystemCatalog::BIT: break;
case execplan::CalpontSystemCatalog::ENUM:
isNull = any_cast<short>(data.data) == any_cast<short>(nullvalue);
break;
case execplan::CalpontSystemCatalog::TINYINT:
isNull = any_cast<char>(data.data) == any_cast<char>(nullvalue);
break;

View File

@@ -197,6 +197,8 @@ execplan::CalpontSystemCatalog::ColDataType DDLPackageProcessor::convertDataType
case ddlpackage::DDL_TEXT: colDataType = CalpontSystemCatalog::TEXT; break;
case ddlpackage::DDL_ENUM: colDataType = CalpontSystemCatalog::ENUM; break;
default: throw runtime_error("Unsupported datatype!");
}

View File

@@ -471,7 +471,7 @@ void AggregateColumn::evaluate(Row& row, bool& isNull)
break;
case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::SMALLINT:
if (row.equals<2>(SMALLINTNULL, fInputIndex))
isNull = true;
else

View File

@@ -242,7 +242,7 @@ inline void ArithmeticOperator::evaluate(rowgroup::Row& row, bool& isNull, Parse
fResult.intVal = joblist::INTNULL;
}
break;
case execplan::CalpontSystemCatalog::UBIGINT:
{
// XXX: this is bandaid solution for specific customer case (MCOL-5568).

View File

@@ -113,6 +113,8 @@ const string colDataTypeToString(CalpontSystemCatalog::ColDataType cdt)
{
case CalpontSystemCatalog::BIT: return "bit"; break;
case CalpontSystemCatalog::ENUM: return "enum"; break;
case CalpontSystemCatalog::TINYINT: return "tinyint"; break;
case CalpontSystemCatalog::CHAR: return "char"; break;

View File

@@ -29,6 +29,7 @@
namespace joblist
{
const uint64_t ENUMNULL = 0xffff;
const uint64_t BIGINTNULL = 0x8000000000000000ULL;
const uint64_t BIGINTEMPTYROW = 0x8000000000000001ULL;
const uint32_t INTNULL = 0x80000000;

View File

@@ -199,6 +199,8 @@ inline int convertDataType(int dataType)
case ddlpackage::DDL_UNSIGNED_DOUBLE: calpontDataType = execplan::CalpontSystemCatalog::UDOUBLE; break;
case ddlpackage::DDL_ENUM: calpontDataType = execplan::CalpontSystemCatalog::ENUM; break;
default: throw runtime_error("Unsupported datatype!");
}