You need to enable JavaScript to run this app.
导航
编码函数
最近更新时间:2022.02.28 12:33:07首次发布时间:2022.02.28 12:33:07

请注意:
下文中的一些示例引用自 ClickHouse 社区文档 并经过一定修改确保可以在 ByteHouse 中正常使用。

UUIDNumToString

Accepts a FixedString(16) value, and returns a string containing 36 characters in text format.

Syntax

UUIDNumToString(FixedString(16))

Arguments

  • a FixedString(16) value

Returned value

  • String.

Example

SELECT
    'a/<@];!~p{jTj={)' AS bytes,
    UUIDNumToString(toFixedString(bytes, 16)) AS uuid
┌─bytes────────────┬─uuid─────────────────────────────────┐
│ a/<@];!~p{jTj={) │ 612f3c40-5d3b-217e-707b-6a546a3d7b29 │
└──────────────────┴──────────────────────────────────────┘

UUIDStringToNum

Accepts a string containing 36 characters in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , and returns it as a set of bytes in a FixedString(16).

Syntax

UUIDStringToNum(String)

Arguments

  • a string in uuid format

Returned value

  • FixedString(16)

Example

SELECT
    '612f3c40-5d3b-217e-707b-6a546a3d7b29' AS uuid,
    UUIDStringToNum(uuid) AS bytes
┌─uuid─────────────────────────────────┬─bytes────────────┐
│ 612f3c40-5d3b-217e-707b-6a546a3d7b29 │ a/<@];!~p{jTj={) │
└──────────────────────────────────────┴──────────────────┘

bitmaskToArray

Accepts an integer. Returns an array of UInt64 numbers containing the list of powers of two that total the source number when summed. Numbers in the array are in ascending order.

Syntax

bitmaskToArray(num)

Arguments

  • num – an integer

Returned value

  • an array of UInt64 numbers containing the list of powers of two that total the source number when summed.

Example

SELECT bitmaskToArray(1), bitmaskToArray(3), bitmaskToArray(4)
┌─bitmaskToArray(1)─┬─bitmaskToArray(3)─┬─bitmaskToArray(4)─┐
│ [1]               │ [1, 2]            │ [4]               │
└───────────────────┴───────────────────┴───────────────────┘

1 = power(2,0)
3 = power(2,0) + power(2,1)
4 = power(2,2)

bitmaskToList

Accepts an integer. Returns a string containing the list of powers of two that total the source number when summed. They are comma-separated without spaces in text format, in ascending order.

Syntax

bitmaskToList(num)

Arguments

  • num – an integer

Returned value

  • a string containing the list of powers of two that total the source number when summed

Example

SELECT bitmaskToList(1), bitmaskToList(3), bitmaskToList(4)
┌─bitmaskToList(1)─┬─bitmaskToList(3)─┬─bitmaskToList(4)─┐
│ 1                │ 1,2              │ 4                │
└──────────────────┴──────────────────┴──────────────────┘

1 = power(2,0)
3 = power(2,0) + power(2,1)
4 = power(2,2)

hex

Returns a string containing the argument’s hexadecimal representation.

Syntax

hex(arg)

The function is using uppercase letters A-F and not using any prefixes (like 0x ) or suffixes (like h ).

For integer arguments, it prints hex digits (“nibbles”) from the most significant to least significant (big endian or “human readable” order). It starts with the most significant non-zero byte (leading zero bytes are omitted) but always prints both digits of every byte even if leading digit is zero.

Values of type Date and DateTime are formatted as corresponding integers (the number of days since Epoch for Date and the value of Unix Timestamp for DateTime).

For String and FixedString , all bytes are simply encoded as two hexadecimal numbers. Zero bytes are not omitted.