Skip to content

Commit be59b9a

Browse files
committed
Pre-create decimal columns
1 parent 21e47e2 commit be59b9a

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

integration_test.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestIntegrationSuite(t *testing.T) {
5656
suite.Run(t, new(integrationTestSuite))
5757
}
5858

59-
type writerFn func(b qdb.LineSender) error
59+
type writerFn func(t *testing.T, s qdb.LineSender, httpAddress string) error
6060

6161
type questdbContainer struct {
6262
testcontainers.Container
@@ -271,7 +271,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
271271
{
272272
"all column types",
273273
testTable,
274-
func(s qdb.LineSender) error {
274+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
275275
val, _ := big.NewInt(0).SetString("123a4", 16)
276276
err := s.
277277
Table(testTable).
@@ -320,7 +320,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
320320
{
321321
"escaped chars",
322322
"m y-awesome_test 1=2.csv",
323-
func(s qdb.LineSender) error {
323+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
324324
return s.
325325
Table("m y-awesome_test 1=2.csv").
326326
Symbol("sym_name 1=2", "value 1,2=3\n4\r5\"6\\7").
@@ -342,7 +342,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
342342
{
343343
"single symbol",
344344
testTable,
345-
func(s qdb.LineSender) error {
345+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
346346
return s.
347347
Table(testTable).
348348
Symbol("foo", "bar").
@@ -362,7 +362,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
362362
{
363363
"single column",
364364
testTable,
365-
func(s qdb.LineSender) error {
365+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
366366
return s.
367367
Table(testTable).
368368
Int64Column("foobar", 1_000_042).
@@ -382,7 +382,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
382382
{
383383
"single column long256",
384384
testTable,
385-
func(s qdb.LineSender) error {
385+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
386386
val, _ := big.NewInt(0).SetString("7fffffffffffffff", 16)
387387
return s.
388388
Table(testTable).
@@ -403,7 +403,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
403403
{
404404
"double value with exponent",
405405
testTable,
406-
func(s qdb.LineSender) error {
406+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
407407
return s.
408408
Table(testTable).
409409
Float64Column("foobar", 4.2e-100).
@@ -423,7 +423,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
423423
{
424424
"double array",
425425
testTable,
426-
func(s qdb.LineSender) error {
426+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
427427
values1D := []float64{1.0, 2.0, 3.0, 4.0, 5.0, math.NaN()}
428428
values2D := [][]float64{{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}, {math.NaN(), math.NaN()}}
429429
values3D := [][][]float64{{{1.0, 2.0}, {3.0, 4.0}}, {{5.0, 6.0}, {7.0, math.NaN()}}}
@@ -503,7 +503,15 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
503503
{
504504
"decimal type",
505505
testTable,
506-
func(s qdb.LineSender) error {
506+
func(t *testing.T, s qdb.LineSender, httpAddress string) error {
507+
// decimal columns must be pre-created
508+
ddl(t,
509+
"create table "+testTable+"("+
510+
"text_col decimal(18,3), binary_col decimal(18,3), "+
511+
"binary_neg_col decimal(18,3), binary_null_col decimal(18,3), ts timestamp"+
512+
") timestamp(ts) partition by day;",
513+
httpAddress)
514+
507515
d := qdb.NewDecimalFromInt64(12345, 2)
508516
neg_d, err := qdb.NewDecimal(big.NewInt(-12345), 2)
509517
if err != nil {
@@ -538,7 +546,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
538546
{"text_col", "DECIMAL(18,3)"},
539547
{"binary_col", "DECIMAL(18,3)"},
540548
{"binary_neg_col", "DECIMAL(18,3)"},
541-
{"timestamp", "TIMESTAMP"},
549+
{"ts", "TIMESTAMP"},
542550
},
543551
Dataset: [][]any{
544552
{"123.450", "123.450", "-123.450", "1970-01-01T00:00:00.000001Z"},
@@ -601,8 +609,7 @@ func (suite *integrationTestSuite) TestE2EValidWrites() {
601609
return
602610
}
603611

604-
dropTable(t, tc.tableName, questdbC.httpAddress)
605-
err = tc.writerFn(sender)
612+
err = tc.writerFn(t, sender, questdbC.httpAddress)
606613
assert.NoError(t, err)
607614

608615
err = sender.Flush(ctx)

tcp_integration_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,23 @@ type column struct {
508508
Type string `json:"type"`
509509
}
510510

511+
func ddl(t *testing.T, ddl, address string) {
512+
// We always query data using the QuestDB container over http
513+
address = "http://" + address
514+
u, err := url.Parse(address)
515+
assert.NoError(t, err)
516+
517+
u.Path += "exec"
518+
params := url.Values{}
519+
params.Add("query", ddl)
520+
u.RawQuery = params.Encode()
521+
url := fmt.Sprintf("%v", u)
522+
523+
res, err := http.Get(url)
524+
assert.NoError(t, err)
525+
defer res.Body.Close()
526+
}
527+
511528
func dropTable(t *testing.T, tableName, address string) {
512529
// We always query data using the QuestDB container over http
513530
address = "http://" + address

0 commit comments

Comments
 (0)