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?

You can 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 the Download icon to download the MapReduce SDK for Java package. odps-sdk-mapred

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 want 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 the SQL flag by adding set odps.sql.type.system.odps2=true; before the SQL statement. You can 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 step. 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?

MaxCompute SDK for Java provides the Logview interface i = SQLTask.run(odps, sql); String logview = odps.logview().generateLogView(i, 7×24) to help you quickly locate issues.

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

You can 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 number of query results exceeds 1,000 when I use SQLTask to execute an SQL statement?

You can 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);              
Yes, the number of data records is limited. A maximum of 5,000 data records can be returned. 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 1,000 results are returned.

DownloadSession is used to download data in an existing table. The number of returned results is unlimited.

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, instance.waitForSuccess() 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, you can 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 run 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 local 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 run code in MaxCompute?

  • Problem description
    The following error message appears:
    OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory
  • Cause

    The 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.