Skip to content
A Go driver for MaxCompute.
Branch: develop
Clone or download
tonyyang-svail and weiguoz Better error message (#44)
* add table not exist test

* add error-code
Latest commit 15f5c41 Jul 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Return a odpsResult instead of nil while running Exec (#17) May 24, 2019
.travis.yml Simplify CI (#13) May 23, 2019
README.md goodps -> gomaxcompute (#14) May 23, 2019
client.go Better error message (#44) Jul 18, 2019
connection.go Handle bad query (#42) Jun 17, 2019
connection_test.go Better error message (#44) Jul 18, 2019
driver.go first commit May 16, 2019
driver_test.go first commit May 16, 2019
dsn.go dsn regexp (#38) Jun 17, 2019
dsn_test.go dsn regexp (#38) Jun 17, 2019
errors.go Better error message (#44) Jul 18, 2019
errors_test.go Better error message (#44) Jul 18, 2019
index.html vanity import path, add redirecting (#4) May 17, 2019
instance.go Better error message (#44) Jul 18, 2019
instance_test.go Better error message (#44) Jul 18, 2019
job.go first commit May 16, 2019
job_test.go Add ci (#7) May 22, 2019
log.go Fix 31 (#35) Jun 15, 2019
result.go Return a odpsResult instead of nil while running Exec (#17) May 24, 2019
rows.go first commit May 16, 2019
rows_test.go Add ci (#7) May 22, 2019
task.go Append a semicolon to a SQL (#37) Jun 17, 2019
task_test.go
tunnel.go first commit May 16, 2019

README.md

MaxCompute Go Driver

Build Status GoDoc License

MaxCompute, also known as ODPS, is a distributed storage service and SQL engine provided by Alibaba Cloud. This repository contains a Go SQLdriver of MaxCompute. If you are going to write a Go program that calls the standard library database/sql to access MaxCompute databases, you could use this driver.

This project is in its early stage. Your issues and pull requests are very welcome!

What This Is and Isn't

This project is a driver that helps Go's standard database API talking to MaxCompute server. It has the following features:

  • In pure Go. Not a wrapper of any C/C++ library.
  • Connect to MaxCompute through its HTTP interface.
  • Improve I/O throughput using MaxCompute's tunnel service.

Alibaba Cloud open sourced some client SDKs of MaxCompute:

This project is not an SDK.

Alibaba Cloud also provides ODBC/JDBC drivers:

This project is a Go's database/sql driver.

How to Use

Please make sure you have Go 1.6 or high release.

You can clone the source code by running the following command.

go get -u sqlflow.org/gomaxcompute

Here is a simple example:

package main

import (
    "database/sql"
    "sqlflow.org/gomaxcompute"
)

func assertNoError(e error) {
    if e != nil {
        panic(e)
    }
}

func main() {
    config := gomaxcompute.Config{
        AccessID:  "<access_id>",
        AccessKey: "<access_key>",
        Endpoint:  "<end_point>",
        Project:   "<project_name>"}
    db, e := sql.Open("maxcompute", config.FormatDSN())
    assertNoError(e)
    defer db.Close()

    const sql = `SELECT
                    cast('1'                   AS BIGINT)  AS a,
                    cast(TRUE                  AS BOOLEAN) AS b,
                    cast('hi'                  AS STRING)  AS c,
                    cast('3.14'                AS DOUBLE)  AS d,
                    cast('2017-11-11 03:12:11' AS DATETIME) AS e,
                    cast('100.01' AS DECIMAL)  AS f;`
    rows, e := db.Query(sql)
    assertNoError(e)
    defer rows.Close()

    for rows.Next() {
        // do your stuff
    }
}

Please be aware that to connect to a MaxCompute database, the user needs to provide

  1. the access ID
  2. the access key
  3. the endpoint pointing to the MaxCompute service
  4. a project, which is something similar to a database in MySQL.

Acknowledgement

Our respect and thanks to Ruohang Feng, who wrote a Go SDK for MaxCompute when he worked in Alibaba, for his warm help that enabled this project.

You can’t perform that action at this time.