Skip to content

Can't use Array of Tuple in PreparedStatement #1862

@joceron

Description

@joceron

I'm trying to use an Array of Tuple in a PreparedStatement, but somehow while serializing, it seems the Tuple gets combined into a single value. I don't know if it's due to my misunderstanding of how to use the driver, or an actual bug. If it's the first case, I apologize.

I created an example table with this:

CREATE TABLE tmp (my_column Array(Tuple(String, String))) PRIMARY KEY my_column;

And this is my testing code:

val conn = DriverManager.getConnection(???, ???, ???)
val pstmt: PreparedStatement = conn.prepareStatement("insert into tmp (my_column) values (?)")
val arr  = conn.createArrayOf("Tuple(String, String)", List(("first", "second")).toArray[Object])
pstmt.setArray(1, arr)
pstmt.executeUpdate()

When executing that, it goes to BinaryDataProcessor.ArraySerializer.serialize, and then I see that at that point so far the serializing goes well:
Screenshot 2024-10-10 at 15 08 58

But then when going into ClickHouseRowBinaryProcessor.TupleSerializer.serialize later during the execution, it seems that it has combined the whole tuple into a single value:
Screenshot 2024-10-10 at 15 10 07

That throws anIndexOutOfBoundsException, because (I'm copy&pasting code from ClickHouseRowBinaryProcessor):

public void serialize(ClickHouseValue value, ClickHouseOutputStream output) throws IOException {
    List<Object> tupleValues = value.asTuple();
    int i = 0;

    for(int len = this.serializers.length; i < len; ++i) {
        this.serializers[i].serialize(this.values[i].update(tupleValues.get(i)), output);
    }

}

There, tupleValues, I suppose it's meant to have two values: each of the values of the Tuple. But since it was combined into one (see my second screenshot), in the for loop it throws an exception when trying to do tupleValues.get(1).

Amd I misunderstanding something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions