Arrow Flight SQL: Go (ADBC)
The only change
Section titled “The only change”# URI grpc+tls://flight.internal:32010 grpc+tls://warehouse.internal:32010# user / password (or token) the server's account MachWarehouse accountgo mod tidyFLIGHT_SQL_URI=grpc+tls://warehouse.internal:32010 FLIGHT_SQL_USER=app FLIGHT_SQL_PASSWORD=... go run .Libraries: github.com/apache/arrow-adbc/go/adbc v1.13.0, github.com/apache/arrow-go/v18 v18.8.0 (Go 1.27).
Source
Section titled “Source”The program as it is kept and tested in the Mach Database Warehouse repository; highlighted lines read the connection setting.
// Command flight-sql-go runs a query over Arrow Flight SQL with the Go ADBC// driver and prints the Arrow record batches. Plain ADBC code.package main
import ( "context" "fmt" "log" "os"
"github.com/apache/arrow-adbc/go/adbc" "github.com/apache/arrow-adbc/go/adbc/driver/flightsql" "github.com/apache/arrow-go/v18/arrow/memory")
func main() { ctx := context.Background() drv := flightsql.NewDriver(memory.DefaultAllocator) db, err := drv.NewDatabase(map[string]string{ adbc.OptionKeyURI: os.Getenv("FLIGHT_SQL_URI"), adbc.OptionKeyUsername: os.Getenv("FLIGHT_SQL_USER"), adbc.OptionKeyPassword: os.Getenv("FLIGHT_SQL_PASSWORD"), }) if err != nil { log.Fatal(err) } defer db.Close() cnxn, err := db.Open(ctx) if err != nil { log.Fatal(err) } defer cnxn.Close()
stmt, err := cnxn.NewStatement() if err != nil { log.Fatal(err) } defer stmt.Close() if err := stmt.SetSqlQuery("SELECT country, count(*) AS events, sum(revenue) AS revenue FROM events GROUP BY country ORDER BY revenue DESC"); err != nil { log.Fatal(err) } reader, _, err := stmt.ExecuteQuery(ctx) if err != nil { log.Fatal(err) } defer reader.Release() for reader.Next() { rec := reader.Record() fmt.Println(rec) } if err := reader.Err(); err != nil { log.Fatal(err) }}module example.com/machwarehouse/flight-sql-go
go 1.27
require ( github.com/apache/arrow-adbc/go/adbc v1.13.0 github.com/apache/arrow-go/v18 v18.8.0)