Type parser: escapes in a quoted Enum label / backtick identifier are not decoded like the server
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
Línea de trabajo
Start in clickhouse/types/type_parser.cpp: kUnescapeMap (around lines 87-99) and the single-quote branch of TypeParser::NextToken (around lines 276-298), then the backtick/double-quote branch (around lines 299-327). Add the \N, =, / and control-character escape handling there, and add the cases from the issue to ut/type_parser_ut.cpp next to TypeParserCase.ParseEnum_AllEscapedBytes. Done when the new test passes, labels and tuple element names match the server, and an unknown escape such as \z still keeps its backslash.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
TypeParser::NextToken (clickhouse/types/type_parser.cpp:276-298) decodes escapes inside a single-quoted Enum label with kUnescapeMap (type_parser.cpp:87-99), which only covers \0 \b \f \n \r \t \\ plus a special case for \'. Every other escape falls into the else arm on line 293 and keeps its backslash.
The server (parseComplexEscapeSequence, src/IO/ReadHelpers.cpp) additionally:
- decodes
\Nto no characters at all; - drops the backslash when the escaped character is one of
\ ' " ` / =or an ASCII control character (<= 0x1F).
So the client and the server disagree on these labels:
| Escape in a quoted label | Server | clickhouse-cpp |
|---|---|---|
\N |
removed (empty) | \N (backslash kept) |
\= |
= |
\= |
\/ |
/ |
\/ |
\ + control char 0x00-0x1F (for example a literal TAB) |
the control character | \ + the control character |
The same applies to the backtick / double-quote branch (type_parser.cpp:299-327), which decodes only \<quote> and <quote><quote> and leaves every other escape untouched. The server applies the full escape table to back-quoted identifiers too, so Tuple(`a\Nb` Int8, c Int8) is Tuple(ab Int8, c Int8) on the server but gives the element name a\Nb in the client.
Impact is low, the same as in the C# client issue linked below: the server never emits these escapes in a type name that it sends, so the read path and server-driven insert schemas are not affected. It matters only for type strings that the application writes, for example CreateColumnByType(...) or TypeParser with a DDL type copied from a CREATE TABLE. There the client builds an Enum whose label is a\Nb while the server's label for the same DDL is ab, so ColumnEnum::Append("ab") throws, and labels can collide or fail to collide differently from the server (Enum8('a\Nb' = 1, 'ab' = 2) is a duplicate-name error on the server but two distinct labels in the client).
ClickHouse server version
26.10.3.7. Server behaviour verified over HTTP:
SELECT toTypeName(CAST(1 AS Enum8('a\Nb' = 1))) -- Enum8('ab' = 1)
SELECT toTypeName(CAST(1 AS Enum8('a\=b' = 1))) -- Enum8('a=b' = 1)
SELECT hex(toString(CAST(1 AS Enum8('a\<TAB>b' = 1)))) -- 610962 (a<TAB>b)
SELECT toTypeName(CAST((1,2) AS Tuple(`a\Nb` Int8, c Int8))) -- Tuple(ab Int8, c Int8)
The client side comes from analysis of the tokenizer. The test below compiles against the library, but my sandbox could not execute the built binary, so the "clickhouse-cpp" column is the behaviour that the code produces by inspection, not a captured run.
Reproduction
Add to ut/type_parser_ut.cpp, in the style of the existing TypeParserCase.ParseEnum_AllEscapedBytes:
TEST(TypeParserCase, ParseEnum_ServerEscapes) {
const char kTab = '\t';
// {fragment as seen by the parser, expected decoded label}
const std::vector<std::pair<std::string, std::string>> cases = {
{"a\\Nb", "ab"}, // \N decodes to nothing
{"a\\=b", "a=b"}, // \= decodes to '='
{"a\\/b", "a/b"}, // \/ decodes to '/'
{std::string("a\\") + kTab + "b", // backslash + literal TAB
std::string("a") + kTab + "b"},
};
for (const auto& [label, expected] : cases) {
TypeAst ast;
ASSERT_TRUE(TypeParser("Enum8('" + label + "' = 1)").Parse(&ast));
ASSERT_EQ(ast.meta, TypeAst::Enum);
EXPECT_EQ(ast.elements[0].value_string, expected) << "label: " << label;
}
// Back-quoted element names use the same server escape table.
TypeAst tuple;
ASSERT_TRUE(TypeParser("Tuple(`a\\Nb` Int8, c Int8)").Parse(&tuple));
EXPECT_EQ(tuple.elements[0].name, "ab");
// An unknown escape keeps its backslash, like the server.
TypeAst unknown;
ASSERT_TRUE(TypeParser("Enum8('a\\zb' = 1)").Parse(&unknown));
EXPECT_EQ(unknown.elements[0].value_string, "a\\zb");
}
Expected: every EXPECT_EQ passes (labels ab, a=b, a/b, a<TAB>b, tuple element name ab).
Actual: the first five fail and give a\Nb, a\=b, a\/b, a\<TAB>b and tuple element name a\Nb. Only the last case (\z keeps its backslash) passes.
Public-API form of the same problem:
auto col = CreateColumnByType("Enum8('a\\Nb' = 1)"); // the server label for this DDL is "ab"
col->As<ColumnEnum8>()->Append(std::string("ab")); // throws: unknown enum name
Suggested fix
In clickhouse/types/type_parser.cpp:
- handle
\Nin the single-quote branch: consume both characters and append nothing; - drop the backslash also for
",`,/and=(kUnescapeMaphas only0 b f n r t \today, and'is special-cased at line 285); - drop the backslash when the escaped byte is an ASCII control character (
<= 0x1F); - apply the same table in the backtick / double-quote branch (lines 299-327), which today decodes only the quote character itself.
Keep the current behaviour for everything else: an unknown escape such as \z keeps its backslash, and \ + DEL (0x7F) keeps its backslash.
Link
Relayed from the equivalent C# client issue: https://github.com/ClickHouse/clickhouse-cs/issues/730
- Lenguaje dominante
- C
- Estrellas
- 388
- Forks
- 220
- Merge medio
- 1 d 25 min
- PR fusionados (30 d)
- 16
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ClickHouse/clickhouse-cpp
-
bug data-types
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ClickHouse/clickhouse-cpp#645 ·
Los mantenedores suelen responder en 1 día
-
bug queries
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
ClickHouse/clickhouse-cpp#644 ·
Los mantenedores suelen responder en 1 día
-
bug data-types native-format
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ClickHouse/clickhouse-cpp#643 ·
Los mantenedores suelen responder en 1 día
-
bug connectivity native-protocol
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ClickHouse/clickhouse-cpp#638 ·
Los mantenedores suelen responder en 1 día
-
Core SQL test harness: ParseSetAssignments does not skip comments inside SETPosiblemente ocupada @puretechteam la tomó hace 12 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
ClickHouse/clickhouse-cpp#626 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de ClickHouse/clickhouse-cpp
Issues similares
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
389ds/389-ds-base#8251 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100