You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-4464 Bitwise operations not like in MariaDB
This commit is contained in:
@ -267,6 +267,57 @@ public:
|
||||
colDataType == UDECIMAL) &&
|
||||
colWidth == MAXDECIMALWIDTH;
|
||||
}
|
||||
|
||||
bool isUnsignedInteger() const
|
||||
{
|
||||
switch (colDataType)
|
||||
{
|
||||
case datatypes::SystemCatalog::UTINYINT:
|
||||
case datatypes::SystemCatalog::USMALLINT:
|
||||
case datatypes::SystemCatalog::UMEDINT:
|
||||
case datatypes::SystemCatalog::UINT:
|
||||
case datatypes::SystemCatalog::UBIGINT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool isSignedInteger() const
|
||||
{
|
||||
switch (colDataType)
|
||||
{
|
||||
case datatypes::SystemCatalog::TINYINT:
|
||||
case datatypes::SystemCatalog::SMALLINT:
|
||||
case datatypes::SystemCatalog::MEDINT:
|
||||
case datatypes::SystemCatalog::INT:
|
||||
case datatypes::SystemCatalog::BIGINT:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool canReturnXInt64() const
|
||||
{
|
||||
switch (colDataType)
|
||||
{
|
||||
case datatypes::SystemCatalog::BIT:
|
||||
case datatypes::SystemCatalog::VARBINARY:
|
||||
case datatypes::SystemCatalog::CLOB:
|
||||
case datatypes::SystemCatalog::BLOB:
|
||||
case datatypes::SystemCatalog::NUM_OF_COL_DATA_TYPE:
|
||||
case datatypes::SystemCatalog::LONGDOUBLE:
|
||||
case datatypes::SystemCatalog::STRINT:
|
||||
case datatypes::SystemCatalog::UNDEFINED:
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -464,6 +464,19 @@ class Decimal: public TSInt128
|
||||
return TSInt128(roundedValue);
|
||||
}
|
||||
|
||||
int64_t narrowRound() const
|
||||
{
|
||||
int64_t scaleDivisor;
|
||||
getScaleDivisor(scaleDivisor, scale);
|
||||
int64_t intg = value / scaleDivisor;
|
||||
int64_t frac2 = 2 * (value % scaleDivisor);
|
||||
if (frac2 >= scaleDivisor)
|
||||
return intg + 1;
|
||||
if (frac2 <= -scaleDivisor)
|
||||
return intg - 1;
|
||||
return intg;
|
||||
}
|
||||
|
||||
// MOD operator for an integer divisor to be used
|
||||
// for integer rhs
|
||||
inline TSInt128 operator%(const TSInt128& div) const
|
||||
|
168
datatypes/mcs_int64.h
Normal file
168
datatypes/mcs_int64.h
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
Copyright (C) 2020 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef MCS_INT64_H_INCLUDED
|
||||
#define MCS_INT64_H_INCLUDED
|
||||
|
||||
#include "exceptclasses.h"
|
||||
|
||||
namespace datatypes
|
||||
{
|
||||
|
||||
|
||||
class TNullFlag
|
||||
{
|
||||
protected:
|
||||
bool mIsNull;
|
||||
public:
|
||||
explicit TNullFlag(bool val) :mIsNull(val) { }
|
||||
bool isNull() const
|
||||
{
|
||||
return mIsNull;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TUInt64
|
||||
{
|
||||
protected:
|
||||
uint64_t mValue;
|
||||
public:
|
||||
TUInt64(): mValue(0) { }
|
||||
|
||||
explicit TUInt64(uint64_t value): mValue(value) { }
|
||||
|
||||
explicit operator uint64_t () const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TSInt64
|
||||
{
|
||||
protected:
|
||||
int64_t mValue;
|
||||
public:
|
||||
TSInt64(): mValue(0) { }
|
||||
|
||||
explicit TSInt64(int64_t value): mValue(value) { }
|
||||
|
||||
explicit operator int64_t () const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class TUInt64Null: public TUInt64, public TNullFlag
|
||||
{
|
||||
public:
|
||||
|
||||
TUInt64Null(): TNullFlag(true) { }
|
||||
|
||||
explicit TUInt64Null(uint64_t value, bool isNull = false):
|
||||
TUInt64(value), TNullFlag(isNull)
|
||||
{ }
|
||||
|
||||
explicit operator uint64_t () const
|
||||
{
|
||||
idbassert(!mIsNull);
|
||||
return mValue;
|
||||
}
|
||||
uint64_t nullSafeValue(bool & isNullRef) const
|
||||
{
|
||||
return (isNullRef = isNull()) ? 0 : mValue;
|
||||
}
|
||||
|
||||
TUInt64Null operator&(const TUInt64Null &rhs) const
|
||||
{
|
||||
return TUInt64Null(mValue & rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
TUInt64Null operator|(const TUInt64Null &rhs) const
|
||||
{
|
||||
return TUInt64Null(mValue | rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
TUInt64Null operator^(const TUInt64Null &rhs) const
|
||||
{
|
||||
return TUInt64Null(mValue ^ rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
TUInt64Null MariaDBShiftLeft(const TUInt64Null &rhs) const
|
||||
{
|
||||
return TUInt64Null(rhs.mValue >= 64 ? 0 : mValue << rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
TUInt64Null MariaDBShiftRight(const TUInt64Null &rhs) const
|
||||
{
|
||||
return TUInt64Null(rhs.mValue >= 64 ? 0 : mValue >> rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TSInt64Null: public TSInt64, public TNullFlag
|
||||
{
|
||||
public:
|
||||
|
||||
TSInt64Null(): TNullFlag(true) { }
|
||||
|
||||
explicit TSInt64Null(int64_t value, bool isNull = false):
|
||||
TSInt64(value), TNullFlag(isNull)
|
||||
{ }
|
||||
|
||||
explicit operator int64_t () const
|
||||
{
|
||||
idbassert(!mIsNull);
|
||||
return mValue;
|
||||
}
|
||||
|
||||
int64_t nullSafeValue(bool & isNullRef) const
|
||||
{
|
||||
return (isNullRef = isNull()) ? 0 : mValue;
|
||||
}
|
||||
|
||||
TSInt64Null operator&(const TSInt64Null &rhs) const
|
||||
{
|
||||
return TSInt64Null(mValue & rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
TSInt64Null operator|(const TSInt64Null &rhs) const
|
||||
{
|
||||
return TSInt64Null(mValue | rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
TSInt64Null operator^(const TSInt64Null &rhs) const
|
||||
{
|
||||
return TSInt64Null(mValue ^ rhs.mValue, mIsNull || rhs.mIsNull);
|
||||
}
|
||||
TSInt64Null MariaDBShiftLeft(const TUInt64Null &rhs) const
|
||||
{
|
||||
if (isNull() || rhs.isNull())
|
||||
return TSInt64Null();
|
||||
return TSInt64Null((uint64_t) rhs >= 64 ? 0 : mValue << (uint64_t) rhs, false);
|
||||
}
|
||||
TSInt64Null MariaDBShiftRight(const TUInt64Null &rhs) const
|
||||
{
|
||||
if (isNull() || rhs.isNull())
|
||||
return TSInt64Null();
|
||||
return TSInt64Null((uint64_t) rhs >= 64 ? 0 : mValue >> (uint64_t) rhs, false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} //end of namespace datatypes
|
||||
|
||||
#endif // MCS_INT64_H_INCLUDED
|
||||
// vim:ts=2 sw=2:
|
Reference in New Issue
Block a user