Skip to content

Commit 01896db

Browse files
committed
removed arrow dependency, fix tests
1 parent d8a963f commit 01896db

File tree

9 files changed

+54
-513
lines changed

9 files changed

+54
-513
lines changed
File renamed without changes.

chdb/driver/arrow.go

-177
This file was deleted.

chdb/driver/driver.go

+6-14
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
chdbpurego "github.com/chdb-io/chdb-go/chdb-purego"
1414
"github.com/huandu/go-sqlbuilder"
1515
"github.com/parquet-go/parquet-go"
16-
17-
"github.com/apache/arrow/go/v15/arrow/ipc"
1816
)
1917

2018
type DriverType int
@@ -48,12 +46,6 @@ func (d DriverType) String() string {
4846

4947
func (d DriverType) PrepareRows(result chdbpurego.ChdbResult, buf []byte, bufSize int, useUnsafe bool) (driver.Rows, error) {
5048
switch d {
51-
case ARROW:
52-
reader, err := ipc.NewFileReader(bytes.NewReader(buf))
53-
if err != nil {
54-
return nil, err
55-
}
56-
return &arrowRows{localResult: result, reader: reader}, nil
5749
case PARQUET:
5850
reader := parquet.NewGenericReader[any](bytes.NewReader(buf))
5951
return &parquetRows{
@@ -214,13 +206,13 @@ func NewConnect(opts map[string]string) (ret *connector, err error) {
214206
if ok {
215207
ret.udfPath = udfPath
216208
}
217-
// if ret.session == nil {
209+
if ret.session == nil {
218210

219-
// ret.session, err = chdb.NewSession()
220-
// if err != nil {
221-
// return nil, err
222-
// }
223-
// }
211+
ret.session, err = chdb.NewSession()
212+
if err != nil {
213+
return nil, err
214+
}
215+
}
224216
return
225217
}
226218

chdb/session.go

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func (s *Session) Query(queryStr string, outputFormats ...string) (result chdbpu
6060
}
6161
return s.conn.Query(queryStr, outputFormat)
6262

63-
// return connQueryToBuffer(s.conn, queryStr, outputFormat)
6463
}
6564

6665
// Close closes the session and removes the temporary directory

chdb/wrapper_test.go

+45-43
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
package chdb
22

33
import (
4-
"os"
5-
"path/filepath"
64
"testing"
75
)
86

97
func TestQueryToBuffer(t *testing.T) {
108
// Create a temporary directory
11-
tempDir := filepath.Join(os.TempDir(), "chdb_test")
12-
defer os.RemoveAll(tempDir)
9+
sess, err := NewSession()
10+
if err != nil {
11+
t.Fatalf("could not create session: %s", err)
12+
}
13+
defer sess.Close()
1314

1415
// Define test cases
1516
testCases := []struct {
16-
name string
17-
queryStr string
18-
outputFormat string
19-
path string
17+
name string
18+
queryStr string
19+
outputFormat string
20+
2021
udfPath string
2122
expectedErrMsg string
2223
expectedResult string
2324
}{
2425
{
25-
name: "Basic Query",
26-
queryStr: "SELECT 123",
27-
outputFormat: "CSV",
28-
path: "",
26+
name: "Basic Query",
27+
queryStr: "SELECT 123",
28+
outputFormat: "CSV",
29+
2930
udfPath: "",
3031
expectedErrMsg: "",
3132
expectedResult: "123\n",
@@ -35,35 +36,35 @@ func TestQueryToBuffer(t *testing.T) {
3536
name: "Session Query 1",
3637
queryStr: "CREATE DATABASE IF NOT EXISTS testdb; " +
3738
"CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;",
38-
outputFormat: "CSV",
39-
path: tempDir,
39+
outputFormat: "CSV",
40+
4041
udfPath: "",
4142
expectedErrMsg: "",
4243
expectedResult: "",
4344
},
44-
// {
45-
// name: "Session Query 2",
46-
// queryStr: "USE testdb; INSERT INTO testtable VALUES (1), (2), (3);",
47-
// outputFormat: "CSV",
48-
// path: tempDir,
49-
// udfPath: "",
50-
// expectedErrMsg: "",
51-
// expectedResult: "",
52-
// },
53-
// {
54-
// name: "Session Query 3",
55-
// queryStr: "SELECT * FROM testtable;",
56-
// outputFormat: "CSV",
57-
// path: tempDir,
58-
// udfPath: "",
59-
// expectedErrMsg: "",
60-
// expectedResult: "1\n2\n3\n",
61-
// },
6245
{
63-
name: "Error Query",
64-
queryStr: "SELECT * FROM nonexist; ",
65-
outputFormat: "CSV",
66-
path: tempDir,
46+
name: "Session Query 2",
47+
queryStr: "USE testdb; INSERT INTO testtable VALUES (1), (2), (3);",
48+
outputFormat: "CSV",
49+
50+
udfPath: "",
51+
expectedErrMsg: "",
52+
expectedResult: "",
53+
},
54+
{
55+
name: "Session Query 3",
56+
queryStr: "SELECT * FROM testtable;",
57+
outputFormat: "CSV",
58+
59+
udfPath: "",
60+
expectedErrMsg: "",
61+
expectedResult: "1\n2\n3\n",
62+
},
63+
{
64+
name: "Error Query",
65+
queryStr: "SELECT * FROM nonexist; ",
66+
outputFormat: "CSV",
67+
6768
udfPath: "",
6869
expectedErrMsg: "Code: 60. DB::Exception: Unknown table expression identifier 'nonexist' in scope SELECT * FROM nonexist. (UNKNOWN_TABLE)",
6970
expectedResult: "",
@@ -73,23 +74,24 @@ func TestQueryToBuffer(t *testing.T) {
7374
for _, tc := range testCases {
7475
t.Run(tc.name, func(t *testing.T) {
7576
// Call queryToBuffer
76-
result, err := queryToBuffer(tc.queryStr, tc.outputFormat, tc.path, tc.udfPath)
77+
78+
result, err := sess.Query(tc.queryStr, tc.outputFormat)
7779

7880
// Verify
7981
if tc.expectedErrMsg != "" {
8082
if err == nil {
81-
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, path %v, udfPath %v, expect error message: %v, got no error",
82-
tc.name, tc.queryStr, tc.outputFormat, tc.path, tc.udfPath, tc.expectedErrMsg)
83+
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, udfPath %v, expect error message: %v, got no error",
84+
tc.name, tc.queryStr, tc.outputFormat, tc.udfPath, tc.expectedErrMsg)
8385
} else {
8486
if err.Error() != tc.expectedErrMsg {
85-
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, path %v, udfPath %v, expect error message: %v, got error message: %v",
86-
tc.name, tc.queryStr, tc.outputFormat, tc.path, tc.udfPath, tc.expectedErrMsg, err.Error())
87+
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, udfPath %v, expect error message: %v, got error message: %v",
88+
tc.name, tc.queryStr, tc.outputFormat, tc.udfPath, tc.expectedErrMsg, err.Error())
8789
}
8890
}
8991
} else {
9092
if string(result.Buf()) != tc.expectedResult {
91-
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, path %v, udfPath %v, expect result: %v, got result: %v",
92-
tc.name, tc.queryStr, tc.outputFormat, tc.path, tc.udfPath, tc.expectedResult, string(result.Buf()))
93+
t.Errorf("%v queryToBuffer() with queryStr %v, outputFormat %v, udfPath %v, expect result: %v, got result: %v",
94+
tc.name, tc.queryStr, tc.outputFormat, tc.udfPath, tc.expectedResult, string(result.Buf()))
9395
}
9496
}
9597
})

0 commit comments

Comments
 (0)