Tüm Ürünler
Search
Belge Merkezi

MaxCompute:Java SDK'ya genel bakış

Son Güncelleme:Oct 04, 2026

Java Yazılım Geliştirme Seti (SDK), MaxCompute için bir dizi Java programlama arabirimi sağlar. Bu SDK'yı kullanarak projelerinizi, tablolarınızı, veri aktarımlarınızı ve işlevlerinizi Java kodu ile yönetebilirsiniz. Bu konuda, örnekler, kaynaklar, tablolar ve işlevler dahil olmak üzere Java SDK açıklanmaktadır.

Not

SDK aracılığıyla MaxCompute'u çağırmanın getirdiği hesaplama ve depolama ücretleri, MaxCompute'u doğrudan kullanmanın ücretleriyle aynıdır.

Arka plan bilgileri

Bu konuda MaxCompute'un ortak temel arabirimleri açıklanmaktadır. Daha fazla bilgi için bkz. SDK Java Doc.

SDK sürümünü yönetmek ve yapılandırmak için Maven kullanabilirsiniz. Aşağıdaki kodda örnek bir Maven yapılandırması gösterilmektedir.

<dependency>
  <groupId>com.aliyun.odps</groupId>
  <artifactId>odps-sdk-core</artifactId>
  <version>X.X.X-public</version>
</dependency>
Not
  • Yalnızca 0.27.2-public ve sonraki sürümler, MaxCompute V2.0'ın yeni veri türlerini destekler.

  • En son SDK sürümünü edinmek için search.maven.org adresinde odps-sdk-core araması yapabilirsiniz.

Aşağıdaki tabloda MaxCompute tarafından sağlanan SDK paketleri açıklanmaktadır.


Paket adı


Açıklama


odps-sdk-core


Tunnel ve tablo ve proje işlemleri gibi MaxCompute'un temel özelliklerini içerir.


odps-sdk-commons


Util sarmalamalarını içerir.


odps-sdk-udf


UDF özelliğinin ana arabirimlerini içerir.


odps-sdk-mapred


MapReduce özelliğini içerir.


odps-sdk-graph


Graph Java SDK'sını içerir. odps-sdk-graph anahtar sözcüğünü arayın.

AliyunAccount

Bir Alibaba Cloud hesabını temsil eder. Giriş parametreleri bir AccessKey ID ve bir AccessKey secret'tır. Bu parametreler, bir Alibaba Cloud hesabının kimliği ve kimlik doğrulama anahtarı olarak hizmet verir. MaxCompute'u başlatmak için bu sınıfı kullanabilirsiniz.

ODPS

MaxCompute SDK'sının giriş noktasıdır. Bu sınıfı kullanarak bir projedeki tüm nesne koleksiyonlarını, örneğin Projeler, Tablolar, Kaynaklar, İşlevler ve Örnekler gibi öğeleri alabilirsiniz.

Bir AliyunAccount örneği geçirerek bir MaxCompute nesnesi oluşturabilirsiniz. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
odps.setDefaultProject("my_project");
for (Table t : odps.tables()) {
    ....
}              

Toplu iş veri tüneli

MaxCompute Tunnel veri tüneli Tunnel SDK'sına dayanır. MaxCompute tabloları için veri yüklemek veya indirmek amacıyla Tunnel SDK'sını kullanabilirsiniz. Görünümler desteklenmez.

MapReduce

MapReduce'un desteklediği SDK'lar hakkında daha fazla bilgi için bkz. Native SDK'ya genel bakış.

Projeler

MaxCompute'daki tüm projelerin bir koleksiyonunu temsil eder. Koleksiyondaki öğeler Project nesneleridir. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
Project p = odps.projects().get("my_exists");
p.reload();
...

Proje

Bir projeyi ve ilgili bilgileri temsil eder. İlgili projeyi Projects koleksiyonundan alabilirsiniz.

SQLTask

SQLTask, SQL görevlerini çalıştırmak ve işlemek için kullanılan bir arabirimdir. SQL deyimlerini doğrudan run arabirimini kullanarak çalıştırabilirsiniz.

Run arabirimi bir Instance döndürür; bu örneği kullanarak SQL deyiminin çalışma durumunu ve sonucunu alabilirsiniz. Aşağıdaki kodda bir örnek verilmiştir.

import java.util.List;
import com.aliyun.odps.Instance;
import com.aliyun.odps.Odps;
import com.aliyun.odps.OdpsException;
import com.aliyun.odps.account.Account;
import com.aliyun.odps.account.AliyunAccount;
import com.aliyun.odps.data.Record;
import com.aliyun.odps.task.SQLTask;
public class TestSql {
  	// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
  	// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
  	// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
  	private static String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
  	private static String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");     
  	private static final String endPoint = "http://service.odps.aliyun.com/api";
  	private static final String project = "";
 	  private static final String sql = "select category from iris;";
    public static void
        main(String[] args) {
        Account account = new AliyunAccount(accessId, accessKey);
        Odps odps = new Odps(account);
        odps.setEndpoint(endPoint);
        odps.setDefaultProject(project);
        Instance i;
        try {
            i = SQLTask.run(odps, sql);
            i.waitForSuccess();
            List<Record> records = SQLTask.getResult(i);
            for(Record r:records){
                System.out.println(r.get(0).toString());
            }
        } catch (OdpsException e) {
            e.printStackTrace();
        }
    }
}
Not
  • Aynı anda yalnızca bir SQL deyimi gönderebilir ve çalıştırabilirsiniz.

  • Tablo oluşturmak için Table arabirimi yerine SQLTask arabirimini kullanın. tablo işlemi deyimini SQLTask arabirimine iletin.

Örnekler

MaxCompute'daki tüm örneklerin bir koleksiyonunu temsil eder. Koleksiyondaki öğeler Instance nesneleridir. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
odps.setDefaultProject("my_project");
for (Instance i : odps.instances()) {
    ....
}

Örnek

Bir örneği ve ilgili bilgileri temsil eder. İlgili örneği Instances koleksiyonundan alabilirsiniz. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
Instance instance= odps.instances().get("instance id");
Date startTime = instance.getStartTime();
Date endTime = instance.getEndTime();
...
    Status instanceStatus = instance.getStatus();
String instanceStatusStr = null;
if (instanceStatus == Status.TERMINATED) {
    instanceStatusStr = TaskStatus.Status.SUCCESS.toString();
    Map<String, TaskStatus> taskStatus = instance.getTaskStatus();
    for (Entry<String, TaskStatus> status : taskStatus.entrySet()) {
        if (status.getValue().getStatus() != TaskStatus.Status.SUCCESS) {
            instanceStatusStr = status.getValue().getStatus().toString();
            break;
        }
    }
} else {
    instanceStatusStr = instanceStatus.toString();
}
...
    TaskSummary summary = instance.getTaskSummary("task name");
String s = summary.getSummaryText();

Tablolar

MaxCompute'daki tüm tabloların bir koleksiyonunu temsil eder. Koleksiyondaki öğeler Table nesneleridir. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
odps.setDefaultProject("my_project");
for (Table t : odps.tables()) {
    ....
}

Tablo

Bir tabloyu ve ilgili bilgileri temsil eder. İlgili tabloyu Tables koleksiyonundan alabilirsiniz. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
odps.setDefaultProject("my_project");

Table table = odps.tables().get("tablename");
for(Column c : table.getSchema().getColumns()) 
{
String name = c.getName();
TypeInfo type = c.getTypeInfo();
 }

Tablo bölüm verilerini almak için aşağıdaki kodu kullanın.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
Table t = odps.tables().get("table name");
t.reload();
Partition part = t.getPartition(new PartitionSpec("partition_col=partition_col_value"));
part.reload();
...

Kaynaklar

MaxCompute'daki tüm kaynakların bir koleksiyonunu temsil eder. Koleksiyondaki öğeler Resource nesneleridir. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
odps.setDefaultProject("my_project");
for (Resource r : odps.resources()) {
    ....
}

Kaynak

Bir kaynağı ve ilgili bilgileri temsil eder. İlgili kaynağı Resources koleksiyonundan alabilirsiniz. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
Resource r = odps.resources().get("resource name");
r.reload();
if (r.getType() == Resource.Type.TABLE) {
    TableResource tr = new TableResource(r);
    String tableSource = tr.getSourceTable().getProject() + "."
        + tr.getSourceTable().getName();
    if (tr.getSourceTablePartition() != null) {
        tableSource += " partition(" + tr.getSourceTablePartition().toString()
            + ")";
    }
    ....
}

Aşağıdaki örnekte bir dosya kaynağının nasıl oluşturulacağı gösterilmektedir.

String projectName = "my_porject";
String source = "my_local_file.txt";
File file = new File(source);
InputStream is = new FileInputStream(file);
FileResource resource = new FileResource();
String name = file.getName();
resource.setName(name);
odps.resources().create(projectName, resource, is);

Aşağıdaki örnekte bir tablo kaynağının nasıl oluşturulacağı gösterilmektedir.

TableResource resource = new TableResource(tableName, tablePrj, partitionSpec);
//resource.setName(INVALID_USER_TABLE);
resource.setName("table_resource_name");
odps.resources().update(projectName, resource);

İşlevler

MaxCompute'daki tüm işlevlerin bir koleksiyonunu temsil eder. Koleksiyondaki öğeler Function nesneleridir. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
odps.setDefaultProject("my_project");
for (Function f : odps.functions()) {
    ....
}                

İşlev

Bir işlevi ve ilgili bilgileri temsil eder. İlgili işlevi Functions koleksiyonundan alabilirsiniz. Aşağıdaki kodda bir örnek verilmiştir.

// An AccessKey for an Alibaba Cloud account has all API access permissions, which poses a high security threat. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// Do not save the AccessKey and AccessKey secret in your code. This prevents key leaks.
Account account = new AliyunAccount(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
Odps odps = new Odps(account);
String odpsUrl = "<your odps endpoint>";
odps.setEndpoint(odpsUrl);
Function f = odps.functions().get("function name");
List<Resource> resources = f.getResources();               

Aşağıdaki örnekte bir işlevin nasıl oluşturulacağı gösterilmektedir.

String resources = "xxx:xxx";
String classType = "com.aliyun.odps.mapred.open.example.WordCount";
ArrayList<String> resourceList = new ArrayList<String>();
for (String r : resources.split(":")) {
    resourceList.add(r);
}
Function func = new Function();
func.setName(name);
func.setClassType(classType);
func.setResources(resourceList);
odps.functions().create(projectName, func);              

Başvurular

Python kullanarak MaxCompute ile etkileşim kurmak ve veri işlemek istiyorsanız bkz. Python SDK'ya genel bakış.