Skip to content

Commit b3c175c

Browse files
committed
Added test case
Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com>
1 parent 0dd993b commit b3c175c

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

examples/staging/main.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"fmt"
6+
"log"
7+
"os"
8+
"strconv"
9+
10+
dbsql "github.com/databricks/databricks-sql-go"
11+
"github.com/joho/godotenv"
12+
)
13+
14+
func main() {
15+
// Opening a driver typically will not attempt to connect to the database.
16+
err := godotenv.Load()
17+
18+
if err != nil {
19+
log.Fatal(err.Error())
20+
}
21+
port, err := strconv.Atoi(os.Getenv("DATABRICKS_PORT"))
22+
if err != nil {
23+
log.Fatal(err.Error())
24+
}
25+
connector, err := dbsql.NewConnector(
26+
dbsql.WithServerHostname(os.Getenv("DATABRICKS_HOST")),
27+
dbsql.WithPort(port),
28+
dbsql.WithHTTPPath(os.Getenv("DATABRICKS_HTTPPATH")),
29+
dbsql.WithAccessToken(os.Getenv("DATABRICKS_ACCESSTOKEN")),
30+
dbsql.WithInitialNamespace("main", "staging_test"),
31+
)
32+
if err != nil {
33+
// This will not be a connection error, but a DSN parse error or
34+
// another initialization error.
35+
log.Fatal(err)
36+
}
37+
db := sql.OpenDB(connector)
38+
defer db.Close()
39+
40+
// ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
41+
// defer cancel()
42+
ctx := dbsql.StagingCtx{}.WithDefaults()
43+
if err := db.Ping(); err != nil {
44+
fmt.Println(err)
45+
}
46+
47+
localFile := "staging/file.csv"
48+
_, err1 := db.ExecContext(ctx, fmt.Sprintf(`PUT '%s' INTO '/Volumes/main/staging_test/e2etests/file1.csv' OVERWRITE`, localFile))
49+
if err1 != nil {
50+
fmt.Println(err1.Error())
51+
return
52+
}
53+
54+
}

examples/staging/staging/file.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1, 1

0 commit comments

Comments
 (0)