All Products
Search
Document Center

MaxCompute:FAQ about SDK for Java

Last Updated:Jun 12, 2024

This topic provides answers to some frequently asked questions about SDK for Java.

Category

FAQ

SDK

Errors

How do I download a MaxCompute SDK for Java package?

Download a MaxCompute SDK for Java package from Maven.

For example, if you want to download the MapReduce SDK for Java package, you can search for odps-sdk-mapred in Maven, and click image of the SDK version on the Versions tab to download the MapReduce SDK for Java package.image

For more information about MaxCompute SDK for Java packages, see SDK for Java.

How do I use MaxCompute SDK for Java to set an SQL flag?

In most cases, you need to set an SQL flag when you submit SQL statements in the DataWorks console or on the MaxCompute client (odpscmd). For example, if you need to use the MaxCompute V2.0 data type edition, you can add set odps.sql.type.system.odps2=true; before your SQL statement to enable the MaxCompute V2.0 data type edition at the session level.

If you use MaxCompute SDK for Java to submit SQL statements, you cannot set an SQL flag in the same way. Use the following method to set an SQL flag:

-- Create an SQLTask object. 
SQLTask task = new SQLTask();task.setName("foobar");task.setQuery("select ...");
-- Set the flag. 
Map settings = new HashMap<>();settings.put("odps.sql.type.system.odps2", "true");...
-- Set other flags. 
task.setProperty("settings", new JSONObject(settings).toString()); -- This is the key configuration. Set the settings properties to the JSON strings that correspond to the flags. 
-- Execute the SQL statement. 
Instance instance = odps.instances().create(task);

How do I use LogView to troubleshoot errors related to SDK for Java?

Use the LogView interface i = SQLTask.run(odps, sql); String logview = odps.logview().generateLogView(i, 7×24) provided by MaxCompute SDK for Java.

How do I run an SQL job in the Java business code that is integrated into MaxCompute?

Call MaxCompute SDK for Java in your Java code to run SQL jobs. For more information, see SDK for Java.

How do I obtain all data if the query result contains more than 10,000 records when I use SQLTask to execute an SQL statement?

Write the result set to a table and download the table data by using Tunnel commands.

Is the number of data records in a result set that is returned by using the following method limited in SQLTask? What is the maximum number of data records that can be returned in the result set?

Sample statement:

Instance instance = SQLTask.run (odps, "SQL statement");
instance.waitForSuccess();
List<Record> records = SQLTask.getResult(instance);              

The maximum number of data records that can be returned in the result set is 10,000. If a large amount of data is returned, we recommend that you use the Tunnel SDK to export the data.

What are the differences between SQLTask and DownloadSession in terms of use and features?

SQLTask executes SQL statements and returns results. The number of returned results is limited. By default, a maximum of 10,000 results are returned.

DownloadSession is used to download data in an existing table. The number of returned results has no upper limit.

What do I do if the execution process requires a long period of time when I use MaxCompute SDK for Java to run jobs?

  • Problem description

    • When User A runs a job by using MaxCompute SDK for Java, the execution process requires a long period of time and User A cannot obtain job information from LogView.

    • When User B accesses a table by using MaxCompute SDK for Java and performs the RestClient Retry operation, the execution process requires a long period of time.

  • Cause

    • User A does not obtain the LogView URL of an instance. As a result, the system cannot trace the execution process of the instance. After you create an instance, the instance.waitForSuccess() method is called. If the execution of the job requires a long period of time, the system also requires a long period of time to respond. If job information is displayed in LogView, you can view the job information and identify the cause of this issue.

    • The execution process requires a long period of time and User B does not obtain job information from LogView. RestClient of SDK for Java provides a retry mechanism. If the system returns error logs each time the system performs a retry, you can quickly locate issues.

  • Solution

    • Use MaxCompute SDK for Java to generate a LogView URL for an instance.

      MaxCompute SDK for Java provides the LogView interface. For more information, see Instance LogView.

      Note
      • When you use MaxCompute SDK for Java, obtain the LogView URL for each instance. This way, you can quickly locate the issue if an error occurs.

      • Run the WAIT<instance_id> command on the MaxCompute client (odpscmd) to obtain the LogView URL.

    • The system returns error logs each time the system performs the RestClient Retry operation.

      MaxCompute SDK for Java provides the abstract class RetryLogger. For more information, see Return error logs.

What do I do if the error message "java.lang.ClassNotFoundException" appears when I execute code in MaxCompute?

When you import a package, you do not import the dependencies that are related to the package or you repeatedly import a package. Troubleshoot the configuration of the on-premises environment.

If the error occurs when you run a MapReduce job in MaxCompute, check whether the required dependencies are imported by using the -resources parameter.

What do I do if the error message "OpenJDK 64-Bit Server VM warning" appears when I execute code in MaxCompute?

  • Problem description

    The following error message appears:

    OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory
  • Cause

    The available storage space of the directory that you use to store temporary files is insufficient.

  • Solution:

    Use the df command to view the storage space of the directory that you use to store temporary files. Then, clear the storage space.