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

feat: improve decimal API #128

Open
wangxuanyue opened this issue Jun 16, 2022 · 3 comments
Open

feat: improve decimal API #128

wangxuanyue opened this issue Jun 16, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@wangxuanyue
Copy link

I found a problem when I tested the code. Is there something wrong?

CREATE TABLE default.dev
(
    test   Decimal32(2)
)
    ENGINE = MergeTree()
        ORDER BY tuple();
var data proto.ColDecimal32
data.Append(1)
if err := c.Do(ctx, ch.Query{
    Body: "INSERT INTO default.dev VALUES",
    Input: []proto.InputColumn{
        {
            Name: "test",
            Data: data,
	},
    },
}); err != nil {
    panic(err)
}

run error:

panic: handle packet: NUMBER_OF_ARGUMENTS_DOESNT_MATCH (42): DB::Exception: Decimal data type family must have exactly two arguments: precision and scale

ColDecimal32/ColDecimal64/ColDecimal128 the same

@ernado ernado changed the title insert Decimal error feat: improve decimal API Jun 16, 2022
ernado added a commit that referenced this issue Jun 16, 2022
@ernado
Copy link
Collaborator

ernado commented Jun 16, 2022

I've managed to workaround this with proto.Alias and help of documentation:

func Test(t *testing.T) {
	conn := Conn(t)
	createTable := Query{
		Body: "CREATE TABLE test_table (v Decimal32(2)) ENGINE = Memory",
	}
	require.NoError(t, conn.Do(ctx, createTable), "create table")

	var data proto.ColDecimal32
	data.Append(1234)
	data.Append(5678)

	insertQuery := Query{
		Body: "INSERT INTO test_table VALUES",
		Input: []proto.InputColumn{
			{Name: "v", Data: proto.Alias(&data, "Decimal(9, 2)")},
		},
	}
	require.NoError(t, conn.Do(ctx, insertQuery), "insert")

	var gotData proto.ColDecimal32
	selectData := Query{
		Body: "SELECT * FROM test_table",
		Result: proto.Results{
			{Name: "v", Data: proto.Alias(&gotData, "Decimal(9, 2)")},
		},
	}
	require.NoError(t, conn.Do(ctx, selectData), "select")
	require.Equal(t, data.Rows(), gotData.Rows())
	for i := 0; i < data.Rows(); i++ {
		require.Equal(t, data.Row(i), gotData.Row(i))
	}
}

Looks like ClickHouse always uses the Decimal(P, S) form of column type.

Nothing wrong with your code, decimals API is currently incomplete and should improve soon.
Sorry for inconvenience and thank you for your report!

@ernado ernado self-assigned this Jun 16, 2022
@ernado ernado added the enhancement New feature or request label Jun 16, 2022
@ernado ernado added this to the Stable milestone Jun 16, 2022
@abhimanyusinghgaur
Copy link

Hi, is there any progress on this or any plans to fix it in near future?

@ernado
Copy link
Collaborator

ernado commented Feb 1, 2024

Hi, I'm currently not working on this feature.

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

No branches or pull requests

3 participants