Merge remote-tracking branch 'upstream/master' into fix25

This commit is contained in:
proller 2019-08-09 18:36:25 +03:00
commit 1c1d624cfb
3 changed files with 28 additions and 22 deletions

View File

@ -537,7 +537,6 @@ void decompress(
if (source_size == 0 || dest_size == 0)
return;
/// Don't run timer if the block is too small.
if (dest_size >= 32768)
{

View File

@ -26,16 +26,20 @@ void NamesAndTypesList::readText(ReadBuffer & buf)
size_t count;
DB::readText(count, buf);
assertString(" columns:\n", buf);
resize(count);
for (NameAndTypePair & it : *this)
String column_name;
String type_name;
for (size_t i = 0; i < count; ++i)
{
readBackQuotedStringWithSQLStyle(it.name, buf);
readBackQuotedStringWithSQLStyle(column_name, buf);
assertChar(' ', buf);
String type_name;
readString(type_name, buf);
it.type = data_type_factory.get(type_name);
assertChar('\n', buf);
emplace_back(column_name, data_type_factory.get(type_name));
}
assertEOF(buf);
}
void NamesAndTypesList::writeText(WriteBuffer & buf) const

View File

@ -1,26 +1,29 @@
# Enum
# Enum8, Enum16
Enumerated type storing pairs of the `'string' = integer` format.
Includes the `Enum8` and `Enum16` types. `Enum` saves the finite set of pairs of `'string' = integer`. In ClickHouse, all operations with the `Enum` data type are performed as if value contains integers, although the user is working with string constants. This is more effective in terms of performance than working with the `String` data type.
ClickHouse supports:
- `Enum8` is described by pairs of `'String' = Int8`.
- `Enum16` is described by pairs of `'String' = Int16`.
- 8-bit `Enum`. It can contain up to 256 values with enumeration of `[-128, 127]`.
- 16-bit `Enum`. It can contain up to 65536 values with enumeration of `[-32768, 32767]`.
ClickHouse automatically chooses a type for `Enum` at data insertion. Also, you can use `Enum8` or `Enum16` types to be sure in size of storage.
## Usage examples
Here we create a table with an `Enum8('hello' = 1, 'world' = 2)` type column:
```
```sql
CREATE TABLE t_enum
(
x Enum8('hello' = 1, 'world' = 2)
x Enum('hello' = 1, 'world' = 2)
)
ENGINE = TinyLog
```
This column `x` can only store the values that are listed in the type definition: `'hello'` or `'world'`. If you try to save any other value, ClickHouse will generate an exception.
This column `x` can only store the values that are listed in the type definition: `'hello'` or `'world'`. If you try to save any other value, ClickHouse will generate an exception. ClickHouse automatically chooses the 8-bit size for enumeration of this `Enum`.
```
```sql
:) INSERT INTO t_enum VALUES ('hello'), ('world'), ('hello')
INSERT INTO t_enum VALUES
@ -35,12 +38,12 @@ INSERT INTO t_enum VALUES
Exception on client:
Code: 49. DB::Exception: Unknown element 'a' for type Enum8('hello' = 1, 'world' = 2)
Code: 49. DB::Exception: Unknown element 'a' for type Enum('hello' = 1, 'world' = 2)
```
When you query data from the table, ClickHouse outputs the string values from `Enum`.
```
```sql
SELECT * FROM t_enum
┌─x─────┐
@ -52,7 +55,7 @@ SELECT * FROM t_enum
If you need to see the numeric equivalents of the rows, you must cast the `Enum` value to integer type.
```
```sql
SELECT CAST(x, 'Int8') FROM t_enum
┌─CAST(x, 'Int8')─┐
@ -64,12 +67,12 @@ SELECT CAST(x, 'Int8') FROM t_enum
To create an Enum value in a query, you also need to use `CAST`.
```
SELECT toTypeName(CAST('a', 'Enum8(\'a\' = 1, \'b\' = 2)'))
```sql
SELECT toTypeName(CAST('a', 'Enum(\'a\' = 1, \'b\' = 2)'))
┌─toTypeName(CAST('a', 'Enum8(\'a\' = 1, \'b\' = 2)'))─┐
│ Enum8('a' = 1, 'b' = 2)
└─────────────────────────────────────────────────────
┌─toTypeName(CAST('a', 'Enum(\'a\' = 1, \'b\' = 2)'))─┐
│ Enum8('a' = 1, 'b' = 2) │
└─────────────────────────────────────────────────────┘
```
## General rules and usage