mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #11878 from ucasFL/sha256
SHA256 add FixedString support
This commit is contained in:
commit
be14b42fdb
@ -533,7 +533,7 @@ public:
|
||||
|
||||
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
||||
{
|
||||
if (!isString(arguments[0]))
|
||||
if (!isStringOrFixedString(arguments[0]))
|
||||
throw Exception("Illegal type " + arguments[0]->getName() + " of argument of function " + getName(),
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
|
||||
@ -567,6 +567,22 @@ public:
|
||||
|
||||
block.getByPosition(result).column = std::move(col_to);
|
||||
}
|
||||
else if (
|
||||
const ColumnFixedString * col_from_fix = checkAndGetColumn<ColumnFixedString>(block.getByPosition(arguments[0]).column.get()))
|
||||
{
|
||||
auto col_to = ColumnFixedString::create(Impl::length);
|
||||
const typename ColumnFixedString::Chars & data = col_from_fix->getChars();
|
||||
const auto size = col_from_fix->size();
|
||||
auto & chars_to = col_to->getChars();
|
||||
const auto length = col_from_fix->getN();
|
||||
chars_to.resize(size * Impl::length);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
Impl::apply(
|
||||
reinterpret_cast<const char *>(&data[i * length]), length, reinterpret_cast<uint8_t *>(&chars_to[i * Impl::length]));
|
||||
}
|
||||
block.getByPosition(result).column = std::move(col_to);
|
||||
}
|
||||
else
|
||||
throw Exception("Illegal column " + block.getByPosition(arguments[0]).column->getName()
|
||||
+ " of first argument of function " + getName(),
|
||||
|
22
tests/queries/0_stateless/01338_sha256_fixedstring.reference
Normal file
22
tests/queries/0_stateless/01338_sha256_fixedstring.reference
Normal file
@ -0,0 +1,22 @@
|
||||
E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
|
||||
BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD
|
||||
9B26F43380684E228B114EC7665F2D6873B32F8E4559D3B01C51F76862E265B6
|
||||
27FF49C17C67288D4E14A0907531761D6C5F7571E2C5C5B94CE577A59A4D9409
|
||||
88622FCCEF18A8BE480CBC3DB91AE2FF9882E1A1DE914C69021EFF4B7A70C7D4
|
||||
659739AAB3E9E66CF7D802864E39380F71F48D781472CD98D9433CB519304451
|
||||
9AE4EE13F8F610C5F44D2F1024865246EFA869F791C2A9BC07633915E0ABDC48
|
||||
9DAA4B5322DE507D8B9F694011F53FEE4A46B894BF136B4ABA0D4FEF42D41AD6
|
||||
F08FF2EBA5E0442C5F77F95D12ABA4743ACD15F9661F4F4670ADE67C0D2C6C25
|
||||
98BDDAA1B2BDDF0EA82EEC2AC12D9D9485D12D456D013430626C237E97F67190
|
||||
E774C2F2D07ACDFC29C1826EA8C057522CF3DEBF016B00255EF798EBB443750A
|
||||
35F515592E37C48B39757E4F26A9D9D9CF1B9CA430221E38D8DA24C64FD1D59F
|
||||
0CEBFA838844F60E3609C1A444D91269934C8BE4DC15B1B5D0C8965DCCF2C82F
|
||||
E6A8F8292D33BE8E57D264F1E2A8BB43798D72EDC9F872775DD5331E9BAFE5A0
|
||||
C7C4ADECC80A8A0C9C15BB07B114FF9F238E1ED0841168E691624A9F01138E35
|
||||
1A2B323AEC9AFCB3DD7F03B316F0D8C8AC02F45EBE981ABFD2AF5D4510A33CF8
|
||||
90DD8E06161865C991D57D9DC9018806A50DF8AD3B91E9C5C499DA7BC8DBB92A
|
||||
ED3D3E9432AD8877398D697C6E9323C9E72EA7001A006FC22E4119BD22969B43
|
||||
0D7E3778AE00F95B9CD98467C604F3B0E47271927CA957CAFBB8DE95F3618A08
|
||||
0EB9FE2FD7C84EC54DD1F757EB3752921381DCD38776DDC36EC29EAE1B7BD812
|
||||
849311C0C3A714887755640FC13D08354B51CC6A657C4F144B9281D9D93BF7CA
|
||||
EAC484A109462ECF3BF34606579456FAC4F820914FFE7E4BBFE2C92314A5AFD8
|
14
tests/queries/0_stateless/01338_sha256_fixedstring.sql
Normal file
14
tests/queries/0_stateless/01338_sha256_fixedstring.sql
Normal file
@ -0,0 +1,14 @@
|
||||
SELECT hex(SHA256(''));
|
||||
SELECT hex(SHA256('abc'));
|
||||
|
||||
DROP TABLE IF EXISTS defaults;
|
||||
CREATE TABLE defaults
|
||||
(
|
||||
s FixedString(20)
|
||||
)ENGINE = Memory();
|
||||
|
||||
INSERT INTO defaults SELECT s FROM generateRandom('s FixedString(20)', 1, 1, 1) LIMIT 20;
|
||||
|
||||
SELECT hex(SHA256(s)) FROM defaults;
|
||||
|
||||
DROP TABLE defaults;
|
Loading…
Reference in New Issue
Block a user