All Products
Search
Document Center

MaxCompute:Initialize the MaxCompute SDK

Last Updated:Oct 30, 2024

To initialize the MaxCompute SDK, you need to create an ODPS object. The ODPS object serves as the entry point for the MaxCompute SDK. All object collections within the project space, such as projects, tables, and instances, are obtained through the ODPS object.

Prerequisites

Access credentials are configured. For more information, see Configure access credentials of the Go SDK.

Initialize MaxCompute SDK

The following code shows an example of the initialization:

package main

import (
	"fmt"
	"github.com/aliyun/aliyun-odps-go-sdk/odps"
	"github.com/aliyun/aliyun-odps-go-sdk/odps/account"
	"log"
)

func main() {
	// Specify the configuration file path
	configPath := "./config.ini"
	conf, err := odps.NewConfigFromIni(configPath)
	if err != nil {
		log.Fatalf("%+v", err)
	}

	aliAccount := account.NewAliyunAccount(conf.AccessId, conf.AccessKey)
	odpsIns := odps.NewOdps(aliAccount, conf.Endpoint)
	// Specify the default MaxCompute project
	odpsIns.SetDefaultProjectName(conf.ProjectName)

	fmt.Printf("odps:%#v\n", odpsIns)
}

What to do next?

After the MaxCompute SDK is initialized, you can use the Go SDK to perform various operations, such as executing SQL queries, managing data uploads and downloads, and handling tables or partitions. For more information, see Use the Go SDK.