You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reading LowCardinality(Nullable(String)) column is not supported (for the data received from ClickHouse) #504
The testMap_LowCardinalityTString_LowCardinalityTNullableString might succeed, but this is only true because you create the column with the type ColumnLowCardinalityT<ColumnNullableT<ColumnString>> explicitly in the test.
However, for the real data received from ClickHouse the type of the underlying column will be simply ColumnLowCardinality. This is probably due to the logic implemented in #182:
Therefore the dynamic_cast inside column->As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>() will yield nullptr.
This is easily illustrated with a simple typeid check (assume that column is an instance of a ColumnRef pointer).
This is what we have for LowCardinality(String) column:
// ColumnRef column;
auto type_name = column->GetType().GetName(); // "LowCardinality(String)"
auto type_id = typeid(*column).name(); // clickhouse::ColumnLowCardinalityT<clickhouse::ColumnString> ("N10clickhouse21ColumnLowCardinalityTINS_12ColumnStringEEE")
And this is the result for LowCardinality(Nullable(String)):
// ColumnRef column;
auto type_name = column->GetType().GetName(); // "LowCardinality(Nullable(String))"
auto type_id = typeid(*column).name(); // clickhouse::ColumnLowCardinality ("N10clickhouse20ColumnLowCardinalityE")
The conclusion is that it's not possible to read LowCardinality(Nullable(String)) column in the current version of clickhouse-cpp (v2.6.1):
column->As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>() doesn't work for the reasons explained above.
While column->As<ColumnLowCardinality>() does work, it's of no help: trying to wrap the result into ColumnLowCardinalityT<ColumnNullableT<ColumnString>> will also fail because the nested type is ColumnNullable (not ColumnNullableT<ColumnString>).
Declaring ColumnLowCardinalityT<ColumnNullable> is not possible because there's no ValueType alias in ColumnNullable.
Recommendation: Close — already fixed
Fixed on master by #541 (merged 2026-08-11): As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>() now wraps the column that Select returns. The fix is not released yet: the latest release, v2.6.2, does not contain it.
Category: Bug
Status on master: Fixed on master — the same program returns nullptr on v2.6.2 and reads a NULL b a on master58453c2 (ClickHouse 26.10.4.207, default 2.x build options).
Analysis: The factory still creates a base ColumnLowCardinality with a base ColumnNullable dictionary for LowCardinality(Nullable(String)) (clickhouse/columns/factory.cpp:253-270). On v2.6.2, Column::As<T>() is only a dynamic_pointer_cast, so it returns nullptr for that column. On master, Column::As<T>() wraps the column when T has a Wrap method (clickhouse/columns/column.h:199-208), and ColumnLowCardinalityT::Wrap wraps a base dictionary into the typed dictionary (clickhouse/columns/lowcardinality.h:241-246). The README list of supported types (README.md:188) still names only LowCardinality(String) and LowCardinality(FixedString(N)).
Reproduction: complete program and output
#include<clickhouse/client.h>
#include<cstdlib>
#include<iostream>
#include<string>
#include<typeinfo>usingnamespaceclickhouse;intmain() {
constchar* host = std::getenv("CLICKHOUSE_HOST");
constchar* port = std::getenv("CLICKHOUSE_PORT");
Client client(ClientOptions()
.SetHost(host ? host : "localhost")
.SetPort(port ? std::stoi(port) : 9000));
client.Execute("DROP TABLE IF EXISTS issue504");
client.Execute("CREATE TABLE issue504 (v LowCardinality(Nullable(String))) ENGINE = Memory");
client.Execute("INSERT INTO issue504 VALUES ('a'), (NULL), ('b'), ('a')");
client.Select("SELECT v FROM issue504", [](const Block& block) {
if (block.GetRowCount() == 0) return;
ColumnRef column = block[0];
std::cout << "type name: " << column->GetType().GetName() << "\n";
std::cout << "is ColumnLowCardinality: "
<< (dynamic_cast<ColumnLowCardinality*>(column.get()) != nullptr) << "\n";
try {
auto lc = column->As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>();
if (!lc) {
std::cout << "As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>: nullptr\n";
return;
}
std::cout << "As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>: values =";
for (size_t i = 0; i < lc->Size(); ++i) {
auto v = lc->At(i);
std::cout << "" << (v ? std::string(*v) : std::string("NULL"));
}
std::cout << "\n";
} catch (const std::exception& e) {
std::cout << "exception: " << e.what() << "\n";
}
});
client.Execute("DROP TABLE IF EXISTS issue504");
return0;
}
Output on master (58453c2), ClickHouse 26.10.4.207:
type name: LowCardinality(Nullable(String))
is ColumnLowCardinality: 1
As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>: values = a NULL b a
exit=0
Output on v2.6.2 (001025c), ClickHouse 26.10.4.207:
type name: LowCardinality(Nullable(String))
is ColumnLowCardinality: 1
As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>: nullptr
exit=0
Automated triage by Polyglot AI. A maintainer makes the final decision.
Activity
polyglotAI-bot commentedon Nov 18, 2026
Recommendation: Close — already fixed
Fixed on
masterby #541 (merged 2026-08-11):As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>()now wraps the column thatSelectreturns. The fix is not released yet: the latest release, v2.6.2, does not contain it.master: Fixed on master — the same program returnsnullptron v2.6.2 and readsa NULL b aonmaster58453c2(ClickHouse 26.10.4.207, default 2.x build options).As<>/AsStrict<>#541. Related: how to read a column of LowCardinality(Nullable(string)) #326 (closed, the question this issue quotes), ColumnLowCardinalityT fail in constructor #457 (LowCardinalityof other types).Analysis: The factory still creates a base
ColumnLowCardinalitywith a baseColumnNullabledictionary forLowCardinality(Nullable(String))(clickhouse/columns/factory.cpp:253-270). On v2.6.2,Column::As<T>()is only adynamic_pointer_cast, so it returnsnullptrfor that column. Onmaster,Column::As<T>()wraps the column whenThas aWrapmethod (clickhouse/columns/column.h:199-208), andColumnLowCardinalityT::Wrapwraps a base dictionary into the typed dictionary (clickhouse/columns/lowcardinality.h:241-246). The README list of supported types (README.md:188) still names onlyLowCardinality(String)andLowCardinality(FixedString(N)).Reproduction: complete program and output
Output on
master(58453c2), ClickHouse 26.10.4.207:Output on
v2.6.2(001025c), ClickHouse 26.10.4.207:Automated triage by Polyglot AI. A maintainer makes the final decision.