Skip to content

how to read a column of LowCardinality(Nullable(string)) #326

Closed

Description

@changvin

version: 2.4.0
gcc version: 8.3.1
system: centos 7, linux version 3.10.0-957.el7.x86 64

Hi, I'm new to clickhouse so I'm testing it.
but I facing a type cast problem.
this my code :
1694159148859

but it seem no right, print std::bad_cast
1694158862679

### Tasks

Activity

  1. changed the title [-]how to a column of LowCardinality(Nullable(string) [/-] [+]how to read a column of LowCardinality(Nullable(string) [/+] on Sep 8, 2023
  2. changed the title [-]how to read a column of LowCardinality(Nullable(string) [/-] [+]how to read a column of LowCardinality(Nullable(string))[/+] on Sep 8, 2023
  3. Enmk commented on Sep 14, 2023

    @Enmk
    Contributor

    Hi @changvin ! Thanks to @den818 you can do the following:

    auto col = column->As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>();

    Then col->At(0) is going to return std::optional<std::string>.

    There is a test case for it (might be a bit convoluted) right here:

    TEST_P(RoundtripCase, LowCardinalityTNullableString) {

  4. Enmk commented on Sep 14, 2023

    @Enmk
    Contributor

    Btw, next time, please attach the code as text, not as a picture... it is much easier to play around and/or modify it like that.

  5. changvin commented on Sep 25, 2023

    @changvin
    Author

    ///@Enmk
    //> Hi @changvin ! Thanks to @den818 you can do the following:

    auto col = column->As<ColumnLowCardinalityT<ColumnNullableT<ColumnString>>>();

    Then col->At(0) is going to return std::optional<std::string>.

    There is a test case for it (might be a bit convoluted) right here:

    TEST_P(RoundtripCase, LowCardinalityTNullableString) {

    this is a insert LowCardinalityTNullableString column test case not read ,

    when read a LowCardinalityTNullableString column , col == nullptr is true

    /// use by LowCardinalitv(Nullable(string))
    void read_lowcardinality_nullable_str(clickhouse::ColumnRef column, std::vector<std::string>& output) {
    	auto col = column->As<clickhouse::ColumnLowCardinalityT<clickhouse::ColumnNullableT<clickhouse::ColumnString>>>();
    	if (col == nullptr) {
    		std::cerr <<"read_lowcardinality_nullable_str col is null"<<std::endl;
    		return;
    	}
    	for(size_t i = 0;  i < col->Size(); i++) {
    		auto op = col->At(i);
    		if (op.has_value())
    			output.emplace_back(*op);
    		else
    			output.emplace_back("");
    	}
    }

    the result is

    read_lowcardinality_nullable_str col is null
    read_lowcardinality_nullable_str col is null
    read_lowcardinality_nullable_str col is null
    read_lowcardinality_nullable_str col is null
    read_lowcardinality_nullable_str col is null
    read_lowcardinality_nullable_str col is null
    read_lowcardinality_nullable_str col is null
    read_lowcardinality_nullable_str col is null
    ...
  6. Enmk commented on Sep 26, 2023

    @Enmk
    Contributor

    Please check master now, most likely you've had ClientOptions::backward_compatibility_lowcardinality_as_wrapped_column set to true and that's why the LowCardinality(String) column was unwrapped into just String.

  7. changvin commented on Oct 11, 2023

    @changvin
    Author

    请现在检查大师,很可能您已经ClientOptions::backward_compatibility_lowcardinality_as_wrapped_column设置为true,这就是该LowCardinality(String)列已展开为String。

    @Enmk
    Thank you for your reply,
    I'm pretty sure ClientOptions::backward_compatibility_lowcardinality_as_wrapped_column set to false before,maybe ColumnLowCardinalityT not work with ColumnNullableT when read ?

  8. Enmk commented on Oct 12, 2023

    @Enmk
    Contributor

    请现在检查大师,很可能您已经ClientOptions::backward_compatibility_lowcardinality_as_wrapped_column设置为true,这就是该LowCardinality(String)列已展开为String。

    @Enmk Thank you for your reply, I'm pretty sure ClientOptions::backward_compatibility_lowcardinality_as_wrapped_column set to false before,maybe ColumnLowCardinalityT not work with ColumnNullableT when read ?

    Please see #339

    This one confirms that it works

    Perhaps, it would be helpful to know the real type of column at run-time with:

    column->GetType().GetName()

    you can include that in your error message for debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions