You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-07 03:22:57 +03:00
MCOL-4387 Convert dataconvert::decimalToString() into VDecimal and TSInt128 methods
This commit is contained in:
@@ -153,8 +153,10 @@ void SimpleColumn_Decimal<len>::setNullVal()
|
||||
template<int len>
|
||||
inline const std::string& SimpleColumn_Decimal<len>:: getStrVal(rowgroup::Row& row, bool& isNull)
|
||||
{
|
||||
dataconvert::DataConvert::decimalToString((int64_t)row.getIntField<len>(fInputIndex), fResultType.scale, tmp, 22, fResultType.colDataType);
|
||||
fResult.strVal = std::string(tmp);
|
||||
datatypes::VDecimal dec((int64_t)row.getIntField<len>(fInputIndex),
|
||||
fResultType.scale,
|
||||
fResultType.precision);
|
||||
fResult.strVal = dec.toString();
|
||||
return fResult.strVal;
|
||||
}
|
||||
|
||||
|
@@ -632,10 +632,10 @@ inline const std::string& TreeNode::getStrVal(const std::string& timeZone)
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
if (fResultType.colWidth == datatypes::MAXDECIMALWIDTH)
|
||||
dataconvert::DataConvert::decimalToString(&fResult.decimalVal.s128Value, fResult.decimalVal.scale, tmp, datatypes::Decimal::MAXLENGTH16BYTES, fResultType.colDataType);
|
||||
// Explicit path for TSInt128 decimals with low precision
|
||||
fResult.strVal = fResult.decimalVal.toString(true);
|
||||
else
|
||||
dataconvert::DataConvert::decimalToString(fResult.decimalVal.value, fResult.decimalVal.scale, tmp, 22, fResultType.colDataType);
|
||||
fResult.strVal = std::string(tmp);
|
||||
fResult.strVal = fResult.decimalVal.toString();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -460,13 +460,11 @@ void GroupConcator::outputRow(std::ostringstream& oss, const rowgroup::Row& row)
|
||||
|
||||
if (LIKELY(row.getColumnWidth(*i) == datatypes::MAXDECIMALWIDTH))
|
||||
{
|
||||
char buf[datatypes::Decimal::MAXLENGTH16BYTES];
|
||||
|
||||
int128_t* dec = row.getBinaryField<int128_t>(*i);
|
||||
dataconvert::DataConvert::decimalToString(dec,
|
||||
static_cast<uint32_t>(scale), buf,
|
||||
(uint8_t) sizeof(buf), types[*i]);
|
||||
oss << fixed << buf;
|
||||
datatypes::VDecimal dec(0,
|
||||
scale,
|
||||
row.getPrecision(*i),
|
||||
row.getBinaryField<int128_t>(*i));
|
||||
oss << fixed << dec;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -1099,8 +1099,8 @@ dec4: /* have to pick a scale to use for the double. using 5... */
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
int64_t val;
|
||||
int128_t val128;
|
||||
int64_t val = 0;
|
||||
int128_t val128 = 0;
|
||||
bool isInputWide = false;
|
||||
|
||||
if (in.getColumnWidth(i) == datatypes::MAXDECIMALWIDTH)
|
||||
@@ -1185,15 +1185,21 @@ dec4: /* have to pick a scale to use for the double. using 5... */
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
default:
|
||||
{
|
||||
char buf[50];
|
||||
dataconvert::DataConvert::decimalToString(val, scale, buf, 50, out->getColTypes()[i]);
|
||||
/* ostringstream oss;
|
||||
if (scale == 0)
|
||||
oss << val;
|
||||
else
|
||||
oss << (val / IDB_pow[scale]) << "."
|
||||
<< setw(scale) << setfill('0') << (val % IDB_pow[scale]); */
|
||||
out->setStringField(string(buf), i);
|
||||
if (LIKELY(isInputWide))
|
||||
{
|
||||
datatypes::VDecimal dec(0,
|
||||
in.getScale(i),
|
||||
in.getPrecision(i),
|
||||
val128);
|
||||
out->setStringField(dec.toString(), i);
|
||||
}
|
||||
else
|
||||
{
|
||||
datatypes::VDecimal dec(val,
|
||||
in.getScale(i),
|
||||
in.getPrecision(i));
|
||||
out->setStringField(dec.toString(), i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ public:
|
||||
const CalpontSystemCatalog::ColType &type() const { return m_type; }
|
||||
int32_t colWidth() const override { return m_type.colWidth; }
|
||||
int32_t precision() const override { return m_type.precision; }
|
||||
int32_t scale() const override { return m_type.scale; }
|
||||
|
||||
int store_date(int64_t val) override
|
||||
{
|
||||
@@ -160,30 +161,16 @@ public:
|
||||
return m_field->store(static_cast<double>(dl));
|
||||
}
|
||||
|
||||
int store_decimal64(int64_t val) override
|
||||
int store_decimal64(const datatypes::VDecimal& dec) override
|
||||
{
|
||||
// @bug4388 stick to InfiniDB's scale in case mysql gives wrong scale due
|
||||
// to create vtable limitation.
|
||||
//if (f2->dec < m_type.scale)
|
||||
// f2->dec = m_type.scale;
|
||||
|
||||
// WIP MCOL-641
|
||||
// This is too much
|
||||
char buf[256];
|
||||
dataconvert::DataConvert::decimalToString(val, (unsigned)m_type.scale,
|
||||
buf, sizeof(buf), m_type.colDataType);
|
||||
return m_field->store(buf, strlen(buf), m_field->charset());
|
||||
std::string decAsAStr = dec.toString();
|
||||
return m_field->store(decAsAStr.c_str(), decAsAStr.length(), m_field->charset());
|
||||
}
|
||||
|
||||
int store_decimal128(const int128_t &val) override
|
||||
int store_decimal128(const datatypes::VDecimal& dec) override
|
||||
{
|
||||
// We won't have more than [+-][0][.] + up to 38 digits
|
||||
char buf[datatypes::Decimal::MAXLENGTH16BYTES];
|
||||
dataconvert::DataConvert::decimalToString((int128_t*) &val,
|
||||
(unsigned) m_type.scale,
|
||||
buf, (uint8_t) sizeof(buf),
|
||||
m_type.colDataType);
|
||||
return m_field->store(buf, strlen(buf), m_field->charset());
|
||||
std::string decAsAStr = dec.toString(true);
|
||||
return m_field->store(decAsAStr.c_str(), decAsAStr.length(), m_field->charset());
|
||||
}
|
||||
|
||||
int store_lob(const char *str, size_t length) override
|
||||
|
@@ -112,12 +112,11 @@ static int generate_result(BRM::OID_t oid, BRM::DBRM* emp, TABLE* table, THD* th
|
||||
else
|
||||
{
|
||||
table->field[4]->set_notnull();
|
||||
|
||||
char buf[datatypes::Decimal::MAXLENGTH16BYTES];
|
||||
dataconvert::DataConvert::decimalToString(
|
||||
&iter->partition.cprange.bigLoVal,
|
||||
0, buf, (uint8_t) sizeof(buf), datatypes::SystemCatalog::DECIMAL);
|
||||
table->field[4]->store(buf, strlen(buf), table->field[4]->charset());
|
||||
std::string decAsAStr = datatypes::TSInt128(iter->partition.cprange.bigLoVal)
|
||||
.toString();
|
||||
table->field[4]->store(decAsAStr.c_str(),
|
||||
decAsAStr.length(),
|
||||
table->field[4]->charset());
|
||||
}
|
||||
|
||||
if (iter->partition.cprange.bigHiVal <= (utils::minInt128 + 1))
|
||||
@@ -127,12 +126,11 @@ static int generate_result(BRM::OID_t oid, BRM::DBRM* emp, TABLE* table, THD* th
|
||||
else
|
||||
{
|
||||
table->field[5]->set_notnull();
|
||||
|
||||
char buf[datatypes::Decimal::MAXLENGTH16BYTES];
|
||||
dataconvert::DataConvert::decimalToString(
|
||||
&iter->partition.cprange.bigHiVal,
|
||||
0, buf, (uint8_t) sizeof(buf), datatypes::SystemCatalog::DECIMAL);
|
||||
table->field[5]->store(buf, strlen(buf), table->field[5]->charset());
|
||||
std::string decAsAStr = datatypes::TSInt128(iter->partition.cprange.bigHiVal)
|
||||
.toString();
|
||||
table->field[5]->store(decAsAStr.c_str(),
|
||||
decAsAStr.length(),
|
||||
table->field[5]->charset());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user