Empty tuple columns (Tuple()) cannot be read: type parser throws, and zero-width columns make Block report 0 rows
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- clickhouse, cpp
- Área
- backend-api-design, databases
Línea de trabajo
Start with the parsing path in clickhouse/types/type_parser.cpp and clickhouse/columns/factory.cpp, then trace how clickhouse/client.cpp reads the native block row count and how clickhouse/block.cpp derives it from columns. Check the TypeParser and block/client tests for coverage. Done means Tuple() parses and creates a column, and native results preserve their transmitted row count for empty and mixed tuple columns.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
A Tuple() column (zero elements, zero bytes per row on the wire) cannot be read by clickhouse-cpp. Two separate defects are involved.
1. Tuple() fails to parse. TypeParser::Parse appends a child element on every ( token, so Tuple() produces one bogus, empty TypeAst child instead of an element-less tuple (clickhouse/types/type_parser.cpp:220-226). TypeAst::meta has no default member initializer (clickhouse/types/type_parser.h:29), and TypeAst() value-initialises it to 0, which is TypeAst::Array. CreateColumnFromAst then takes the Array branch and calls GetASTChildElement(ast, 0) on an element list that is empty, which throws:
ValidationError: AST child element index out of bounds: 0
So SELECT tuple() ... fails for the whole block, even when a normal column is next to the empty tuple. CreateColumnByType("Tuple()") fails in the same way.
2. Latent: Block derives its row count from the columns, not from the block header. Client::Impl::ReadBlock reads num_rows off the wire but does not put it into the block (clickhouse/client.cpp:830, :863); Block::AppendColumn sets rows_ = col->Size() (clickhouse/block.cpp:57). ColumnTuple::Size() returns 0 when the tuple has no elements (clickhouse/columns/tuple.cpp:74). If defect 1 is fixed on its own, a result set whose columns are all zero-width becomes a silent data loss: Block::GetRowCount() returns 0 for 3 server rows and the SelectCallback sees nothing. A mixed result set (Tuple() + UInt8) would instead throw all columns in block must have same count of rows.
The native protocol does carry the real count in the block header, so unlike the text/RowBinary clients this is recoverable — the count is just discarded.
ClickHouse server version
26.11.2.4, native protocol on port 9000. Verified against a running server.
Reproduction
#include <clickhouse/client.h>
#include <clickhouse/columns/factory.h>
#include <clickhouse/columns/numeric.h>
#include <clickhouse/columns/tuple.h>
#include <iostream>
using namespace clickhouse;
int main() {
auto run = [&](const char* name, const char* sql) {
std::cout << name << ": ";
try {
Client client(ClientOptions().SetHost("localhost").SetPort(9000));
size_t rows = 0, blocks = 0;
client.Select(sql, [&](const Block& block) {
if (block.GetRowCount() == 0 && block.GetColumnCount() == 0) return;
++blocks;
rows += block.GetRowCount();
});
std::cout << "blocks=" << blocks << " rows=" << rows << std::endl;
} catch (const std::exception& e) {
std::cout << "EXCEPTION: " << e.what() << std::endl;
}
};
run("1. only tuple() ", "SELECT tuple() FROM numbers(3)");
run("2. tuple() + UInt8 ", "SELECT tuple() AS t, toUInt8(5) AS n FROM numbers(3)");
run("3. contrast UInt8 only ", "SELECT toUInt8(5) FROM numbers(3)");
std::cout << "4. CreateColumnByType(\"Tuple()\"): ";
try {
auto col = CreateColumnByType("Tuple()");
std::cout << (col ? col->Type()->GetName() : "nullptr") << std::endl;
} catch (const std::exception& e) {
std::cout << "EXCEPTION: " << e.what() << std::endl;
}
// Latent: Block derives its row count from the columns, not from num_rows.
std::cout << "5. Block of a zero-width tuple column: ";
try {
auto empty_tuple = std::make_shared<ColumnTuple>(std::vector<ColumnRef>{});
Block block;
block.AppendColumn("t", empty_tuple);
std::cout << "GetRowCount()=" << block.GetRowCount() << " (server sent 3)" << std::endl;
} catch (const std::exception& e) {
std::cout << "EXCEPTION: " << e.what() << std::endl;
}
std::cout << "6. Block of zero-width tuple + UInt8(3 rows): ";
try {
auto empty_tuple = std::make_shared<ColumnTuple>(std::vector<ColumnRef>{});
auto n = std::make_shared<ColumnUInt8>();
n->Append(5); n->Append(5); n->Append(5);
Block block;
block.AppendColumn("t", empty_tuple);
block.AppendColumn("n", n);
std::cout << "GetRowCount()=" << block.GetRowCount() << std::endl;
} catch (const std::exception& e) {
std::cout << "EXCEPTION: " << e.what() << std::endl;
}
return 0;
}
Actual output:
1. only tuple() : EXCEPTION: AST child element index out of bounds: 0
2. tuple() + UInt8 : EXCEPTION: AST child element index out of bounds: 0
3. contrast UInt8 only : blocks=2 rows=3
4. CreateColumnByType("Tuple()"): EXCEPTION: AST child element index out of bounds: 0
5. Block of a zero-width tuple column: GetRowCount()=0 (server sent 3)
6. Block of zero-width tuple + UInt8(3 rows): EXCEPTION: all columns in block must have same count of rows. Name: [n], rows: [0], columns: [3]
Expected: cases 1, 2 and 5 give 3 rows (t = (), n = 5); case 4 gives the type Tuple().
Server side, for reference:
$ curl -s 'http://localhost:8123/?query=SELECT count() FROM (SELECT tuple() FROM numbers(3))'
3
Suggested fix
clickhouse/types/type_parser.h:29— giveTypeAst::metaa default (Meta meta = Terminal;) andcodea default, so a stray empty element cannot read asArray. This is a latent trap for everyname()input, not onlyTuple().clickhouse/types/type_parser.cpp— do not create a child element for(that is immediately followed by), soTuple()parses as a tuple with zero elements.CreateColumnFromAst'sTypeAst::Tuplebranch (clickhouse/columns/factory.cpp:180) already makes a correct, 0-byteColumnTuplefrom an empty element list.clickhouse/client.cpp:829-866/clickhouse/block.cpp:55-60— carry the block header'snum_rowsinto theBlock(for exampleBlock(num_columns, num_rows)plus a size check per column) instead of inferring it fromcol->Size(). Without this, fixing the parser turns case 1 into a silent 0-row result and case 2 into aValidationError.
Note that ColumnTuple::Size() returning 0 for an element-less tuple is correct per se; the row count simply must not come from it.
Link
Found by cross-client analysis of ClickHouse/clickhouse-js#1216 (same defect class: an all-zero-width result set has no distinguishable row count). The .NET report is ClickHouse/clickhouse-cs#570.
- 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