Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppendStruct() for FixedString does not add Proper Padding #904

Closed
kuro337 opened this issue Feb 16, 2023 · 1 comment · Fixed by #910
Closed

AppendStruct() for FixedString does not add Proper Padding #904

kuro337 opened this issue Feb 16, 2023 · 1 comment · Fixed by #910
Assignees
Labels

Comments

@kuro337
Copy link

kuro337 commented Feb 16, 2023

Issue description

I am using clickhouse-go/v2 and using AppendStruct() to flush rows into a Clickhouse ReplicatedMergeTree table.

When my table has a FixedString(10) type defined for a column , the library panics on AppendStruct().

Solution : I was able to fix this by adding a function to add necessary padding to my strings before passing the pointer to AppendStruct().

The Column Type in Clickhouse is : Col1 LowCardinality FixedString (7) DEFAULT 'unknown',

Example code

type ParquetRow struct {
	Col1       string
}

insert_row := ParquetRow{}
insert_row.Col1 = "Test"

batch, err := conn.PrepareBatch(context.Background(), "INSERT INTO example")
	if err != nil {
		return err
	}

fmt.Println("About to call AppendStruct")

err = batch.AppendStruct(&insert_row)
         if err != nil {
	        log.Fatalf("Failed Appending : ", err)
                return err
	}

Error log

About to call AppendStruct
panic: invalid size
goroutine 1 [running]:
[github.com/ClickHouse/ch-go/proto.(*ColFixedStr).Append(...)](http://github.com/ClickHouse/ch-go/proto.(*ColFixedStr).Append(...))
        /Users//go/pkg/mod/[github.com/!click!house/ch-go@v0.51.2/proto/col_fixed_str.go:64](http://github.com/!click!house/ch-go@v0.51.2/proto/col_fixed_str.go:64)
[github.com/ClickHouse/clickhouse-go/v2/lib/column.(*FixedString).AppendRow(0xc0004bd440](http://github.com/ClickHouse/clickhouse-go/v2/lib/column.(*FixedString).AppendRow(0xc0004bd440), {0x1644920?, 0xc000565ab0})
        /Users//go/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.6.1/lib/column/fixed_string.go:166](http://github.com/!click!house/clickhouse-go/v2@v2.6.1/lib/column/fixed_string.go:166) +0x37e
[github.com/ClickHouse/clickhouse-go/v2/lib/column.(*LowCardinality).AppendRow(0xc0001270e0](http://github.com/ClickHouse/clickhouse-go/v2/lib/column.(*LowCardinality).AppendRow(0xc0001270e0), {0x1644920, 0xc000565ab0})
        /Users//go/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.6.1/lib/column/lowcardinality.go:161](http://github.com/!click!house/clickhouse-go/v2@v2.6.1/lib/column/lowcardinality.go:161) +0x3ad
[github.com/ClickHouse/clickhouse-go/v2/lib/proto.(*Block).Append(0xc00036fd00](http://github.com/ClickHouse/clickhouse-go/v2/lib/proto.(*Block).Append(0xc00036fd00), {0xc000591180?, 0x51, 0x10ce92a?})
        /Users//go/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.6.1/lib/proto/block.go:62](http://github.com/!click!house/clickhouse-go/v2@v2.6.1/lib/proto/block.go:62) +0x1a7
[github.com/ClickHouse/clickhouse-go/v2.(*batch).Append(0xc000622cd0](http://github.com/ClickHouse/clickhouse-go/v2.(*batch).Append(0xc000622cd0), {0xc000591180?, 0xc?, 0xc000590c00?})
        /Users//go/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.6.1/conn_batch.go:122](http://github.com/!click!house/clickhouse-go/v2@v2.6.1/conn_batch.go:122) +0x48
[github.com/ClickHouse/clickhouse-go/v2.(*batch).AppendStruct(0xc000622cd0](http://github.com/ClickHouse/clickhouse-go/v2.(*batch).AppendStruct(0xc000622cd0), {0x1635100?, 0xc0005faa00?})
        /Users//go/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.6.1/conn_batch.go:138](http://github.com/!click!house/clickhouse-go/v2@v2.6.1/conn_batch.go:138) +0x95
main.main()
       insert_clickhouse/main.go:263 +0x1188
exit status 2
@jkaflik
Copy link
Contributor

jkaflik commented Feb 20, 2023

Thanks, @Chinmay337, for filing this issue. Here is a PR that fixes it: #910
If everything goes well, I will have it released today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants