You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
MCOL-3536 use Locale from columnstore.xml when doing ORDER BY
This commit is contained in:
committed by
Roman Nozdrin
parent
3e7a964e2a
commit
3b01d5ea22
@ -130,13 +130,12 @@ int StringCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string v1 = l->row1().getStringField(fSpec.fIndex);
|
int len1 = l->row1().getStringLength(fSpec.fIndex);
|
||||||
string v2 = l->row2().getStringField(fSpec.fIndex);
|
int len2 = l->row2().getStringLength(fSpec.fIndex);
|
||||||
|
const char* s1 = (const char*)l->row1().getStringPointer(fSpec.fIndex);
|
||||||
if (v1 > v2)
|
const char* s2 = (const char*)l->row2().getStringPointer(fSpec.fIndex);
|
||||||
ret = fSpec.fAsc;
|
const std::collate<char>& coll = std::use_facet<std::collate<char> >(loc);
|
||||||
else if (v1 < v2)
|
ret = fSpec.fAsc * coll.compare(s1, s1+len1, s2, s2+len2);
|
||||||
ret = -fSpec.fAsc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -63,6 +63,7 @@ struct IdbSortSpec
|
|||||||
// TODO There are three ordering specs since 10.2
|
// TODO There are three ordering specs since 10.2
|
||||||
int fAsc; // <ordering specification> ::= ASC | DESC
|
int fAsc; // <ordering specification> ::= ASC | DESC
|
||||||
int fNf; // <null ordering> ::= NULLS FIRST | NULLS LAST
|
int fNf; // <null ordering> ::= NULLS FIRST | NULLS LAST
|
||||||
|
std::string fLocale;
|
||||||
|
|
||||||
IdbSortSpec() : fIndex(-1), fAsc(1), fNf(1) {}
|
IdbSortSpec() : fIndex(-1), fAsc(1), fNf(1) {}
|
||||||
IdbSortSpec(int i, bool b) : fIndex(i), fAsc(b ? 1 : -1), fNf(fAsc) {}
|
IdbSortSpec(int i, bool b) : fIndex(i), fAsc(b ? 1 : -1), fNf(fAsc) {}
|
||||||
@ -75,13 +76,42 @@ struct IdbSortSpec
|
|||||||
class Compare
|
class Compare
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Compare(const IdbSortSpec& spec) : fSpec(spec) {}
|
Compare(const IdbSortSpec& spec) : fSpec(spec)
|
||||||
|
{
|
||||||
|
// Save off the current Locale in case something goes wrong.
|
||||||
|
std::string curLocale = setlocale(LC_COLLATE, NULL);
|
||||||
|
if (spec.fLocale.length() > 0)
|
||||||
|
{
|
||||||
|
fLocale = spec.fLocale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fLocale = curLocale;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::locale localloc(fLocale.c_str());
|
||||||
|
loc = localloc;
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
fLocale = curLocale;
|
||||||
|
std::locale localloc(fLocale.c_str());
|
||||||
|
loc = localloc;
|
||||||
|
}
|
||||||
|
if (fLocale.find("ja_JP") != std::string::npos)
|
||||||
|
JPcodePoint = true;
|
||||||
|
}
|
||||||
virtual ~Compare() {}
|
virtual ~Compare() {}
|
||||||
|
|
||||||
virtual int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer) = 0;
|
virtual int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IdbSortSpec fSpec;
|
IdbSortSpec fSpec;
|
||||||
|
std::string fLocale;
|
||||||
|
std::locale loc;
|
||||||
|
bool JPcodePoint; // code point ordering (Japanese UTF) flag
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user