clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

[client-v2] No serializer found for Boolean column in kotlin class

Open BOOMeranGG opened this issue 7 months ago • 2 comments

Description

Steps to reproduce

  1. Table:
CREATE TABLE test_table
(
    my_id       Int64,
    is_bool     Boolean
) ENGINE = ReplacingMergeTree
    ORDER BY (my_id);

  1. Kotlin data class:
data class TestRecord(
    val myId: Int,
    val isBool: Boolean,
)
  1. Repository class:
private const val TEST_TABLE_NAME = "test_table"

@Repository
class TestRepository(
    private val clickHouseClient: Client,
) : CampaignStatisticRepository(clickHouseClient) {

    @PostConstruct
    fun init() {
        clickHouseClient.register(
            TestRecord::class.java,
            clickHouseClient.getTableSchema(TEST_TABLE_NAME),
        )
    }

    fun save(data: List<TestRecord>) {
        if (data.isEmpty()) {
            return
        }

        clickHouseClient.insert(TEST_TABLE_NAME, data).get().close()
    }
}
  1. On calling ::save I get an exception

Error Log or Exception StackTrace

No serializer found for column 'is_bool'. Did you forget to register it?
  • I come across this exception only for Boolean type
  • It doesn't work with "isBool" column name either
  • "isbool" works (when it's a column name and a class field)

So there's a problem when I have an underscore or capital letter

Environment

  • Client version: 0.8.6
  • Language version: kotlin 2.1.21

BOOMeranGG avatar May 24 '25 00:05 BOOMeranGG

So there's a problem when I have an underscore or capital letter

Actually, there's a problem with "is"

In java getter name is getIsBool, but in kotlin it's isBool

BOOMeranGG avatar May 24 '25 01:05 BOOMeranGG

Good day, @BOOMeranGG! Thank you for reporting the issue! We will look into it.

btw, you may customize methods matching with com.clickhouse.client.api.Client.Builder#columnToMethodMatchingStrategy .

chernser avatar May 27 '25 17:05 chernser