Skip to content

Instantly share code, notes, and snippets.

@backkem
Created January 5, 2024 11:51
Show Gist options
  • Save backkem/3e4e1b8adb1628ec3665d711e2c7070e to your computer and use it in GitHub Desktop.
Save backkem/3e4e1b8adb1628ec3665d711e2c7070e to your computer and use it in GitHub Desktop.
TiDB Apache Arrow Flight SQL
package main
// This is a super basic client example for the TiDB POC for Apache Arrow Flight SQL.
// Branch: https://github.com/backkem/tidb/tree/flightsql
// Related issue: https://github.com/pingcap/tidb/issues/21056
import (
"database/sql"
"fmt"
"log"
"strings"
"github.com/apache/arrow-adbc/go/adbc"
_ "github.com/apache/arrow-adbc/go/adbc/sqldriver/flightsql"
)
// The example assumes a database called `test` with the following test data:
// CREATE TABLE test (
// id INTEGER PRIMARY KEY
// );
// INSERT INTO test (id) VALUES (1);
// INSERT INTO test (id) VALUES (2);
func main() {
uri := "grpc+tcp://localhost:4001"
dsn := strings.Join([]string{
fmt.Sprintf("%s=%s", adbc.OptionKeyURI, uri),
fmt.Sprintf("%s=%s", "adbc.flight.sql.rpc.call_header.database", "test"),
}, ";")
fmt.Println("connecting to ", dsn)
db, err := sql.Open("flightsql", dsn)
if err != nil {
log.Fatal(err)
}
rows, err := db.Query("select id from test;")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var id int64
if err := rows.Scan(&id); err != nil {
log.Fatal(err)
}
log.Printf("id %d\n", id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment