Skip to content

Commit 0ce6aaa

Browse files
adapt to test server 0.1.0
Signed-off-by: Andre Furlan <[email protected]>
1 parent 6b4144d commit 0ce6aaa

File tree

3 files changed

+65
-50
lines changed

3 files changed

+65
-50
lines changed

.github/workflows/go.yml

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,56 +20,24 @@ jobs:
2020
with:
2121
version: v1.48
2222

23-
integration:
23+
build-and-test:
24+
name: Test and Build
2425
permissions:
2526
contents: read
2627
packages: read
27-
name: Integration Tests
2828
strategy:
2929
matrix:
3030
go-version: [1.19.x]
3131
os: [ubuntu-latest]
3232
runs-on: ${{ matrix.os }}
3333
services:
3434
test-server:
35-
options: --user "appuser"
3635
credentials:
3736
username: ${{ github.repository }}
3837
password: ${{ secrets.GITHUB_TOKEN }}
39-
image: ghcr.io/databricks/databricks/databricks-thrift-test-server:main
38+
image: ghcr.io/databricks/databricks/databricks-thrift-test-server:0.1.0
4039
ports:
4140
- 8087:8087
42-
steps:
43-
- name: Check out code into the Go module directory
44-
uses: actions/checkout@v3
45-
46-
- name: Set up Go Toolchain
47-
uses: actions/setup-go@v3
48-
with:
49-
go-version: ${{ matrix.go-version }}
50-
51-
- name: Cache Go artifacts
52-
uses: actions/cache@v2
53-
with:
54-
path: |
55-
~/go/pkg/mod
56-
~/.cache/go-build
57-
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
58-
restore-keys: |
59-
${{ runner.os }}-go-${{ matrix.go-version }}-
60-
61-
62-
- name: run integration tests
63-
run: make test-integration
64-
65-
build-and-test:
66-
name: Test and Build
67-
strategy:
68-
matrix:
69-
go-version: [1.19.x]
70-
os: [ubuntu-latest]
71-
runs-on: ${{ matrix.os }}
72-
7341
steps:
7442
- name: Check out code into the Go module directory
7543
uses: actions/checkout@v3
@@ -103,10 +71,15 @@ jobs:
10371
fi
10472
go get -v -t -d ./...
10573
74+
- name: Build
75+
run: make linux
76+
10677
- name: Test
10778
run: make test
10879
env:
10980
CGO_ENABLED: 0
11081

111-
- name: Build
112-
run: make linux
82+
- name: run integration tests
83+
run: make test-integration
84+
env:
85+
CGO_ENABLED: 0

connector.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,19 @@ type connector struct {
2020
}
2121

2222
func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
23-
var catalogName *cli_service.TIdentifier
24-
var schemaName *cli_service.TIdentifier
23+
var initialNamespace *cli_service.TNamespace
2524
if c.cfg.Catalog != "" {
26-
catalogName = cli_service.TIdentifierPtr(cli_service.TIdentifier(c.cfg.Catalog))
25+
initialNamespace.CatalogName = cli_service.TIdentifierPtr(cli_service.TIdentifier(c.cfg.Catalog))
2726
}
2827
if c.cfg.Schema != "" {
29-
schemaName = cli_service.TIdentifierPtr(cli_service.TIdentifier(c.cfg.Schema))
28+
initialNamespace.SchemaName = cli_service.TIdentifierPtr(cli_service.TIdentifier(c.cfg.Schema))
3029
}
3130

3231
// we need to ensure that open session will eventually end
3332
session, err := c.client.OpenSession(ctx, &cli_service.TOpenSessionReq{
34-
ClientProtocol: c.cfg.ThriftProtocolVersion,
35-
Configuration: make(map[string]string),
36-
InitialNamespace: &cli_service.TNamespace{
37-
CatalogName: catalogName,
38-
SchemaName: schemaName,
39-
},
33+
ClientProtocol: c.cfg.ThriftProtocolVersion,
34+
Configuration: make(map[string]string),
35+
InitialNamespace: initialNamespace,
4036
CanUseMultipleCatalogs: &c.cfg.CanUseMultipleCatalogs,
4137
})
4238

integration_tests/integration_test.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
dbsql "github.com/databricks/databricks-sql-go"
11+
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213
)
1314

@@ -16,14 +17,59 @@ func TestIntegrationPing(t *testing.T) {
1617
connector, err := dbsql.NewConnector(
1718
dbsql.WithServerHostname("localhost"),
1819
dbsql.WithPort(8087),
20+
dbsql.WithHTTPPath("session"), //test case name
21+
dbsql.WithMaxRows(100),
1922
)
2023
require.NoError(t, err)
2124
db := sql.OpenDB(connector)
2225
defer db.Close()
2326

24-
t.Run("it can ping", func(t *testing.T) {
25-
if err := db.PingContext(context.Background()); err != nil {
26-
require.NoError(t, err)
27+
t.Run("it can query multiple result pages", func(t *testing.T) {
28+
rows, err1 := db.QueryContext(context.Background(), `select * from default.diamonds limit 250`)
29+
require.Nil(t, err1)
30+
require.NotNil(t, rows)
31+
defer rows.Close()
32+
type row struct {
33+
_c0 int
34+
carat float64
35+
cut string
36+
color string
37+
clarity string
38+
depth sql.NullFloat64
39+
table sql.NullFloat64
40+
price int
41+
x float64
42+
y float64
43+
z float64
2744
}
45+
expectedColumnNames := []string{"_c0", "carat", "cut", "color", "clarity", "depth", "table", "price", "x", "y", "z"}
46+
expectedDatabaseType := []string{"INT", "DOUBLE", "STRING", "STRING", "STRING", "DOUBLE", "DOUBLE", "INT", "DOUBLE", "DOUBLE", "DOUBLE"}
47+
expectedNullable := []bool{false, false, false, false, false, false, false, false, false, false, false}
48+
49+
cols, err := rows.Columns()
50+
require.NoError(t, err)
51+
require.Equal(t, expectedColumnNames, cols)
52+
53+
types, err := rows.ColumnTypes()
54+
require.NoError(t, err)
55+
56+
for i, v := range types {
57+
assert.Equal(t, expectedColumnNames[i], v.Name())
58+
assert.Equal(t, expectedDatabaseType[i], v.DatabaseTypeName())
59+
nullable, ok := v.Nullable()
60+
assert.False(t, ok)
61+
assert.Equal(t, expectedNullable[i], nullable)
62+
}
63+
var allrows []row
64+
for rows.Next() {
65+
// After row 10 this will cause one fetch call, as 10 rows (maxRows config) will come from the first execute statement call.
66+
r := row{}
67+
err := rows.Scan(&r._c0, &r.carat, &r.cut, &r.color, &r.clarity, &r.depth, &r.table, &r.price, &r.x, &r.y, &r.z)
68+
assert.Nil(t, err)
69+
allrows = append(allrows, r)
70+
}
71+
assert.Equal(t, 250, len(allrows))
72+
assert.Nil(t, rows.Err())
73+
2874
})
2975
}

0 commit comments

Comments
 (0)