This page answers common questions about MaxCompute SDK for Java.
How do I download a MaxCompute SDK for Java package?
Download SDK packages from Maven. For example, to get the MapReduce SDK for Java, search for odps-sdk-mapred on Maven Central, go to the Versions tab, and click the download icon next to the version you want.
For a full list of available packages, see SDK for Java.
How do I set an SQL flag using MaxCompute SDK for Java?
Setting a flag in the DataWorks console or MaxCompute client (odpscmd) — for example, adding set odps.sql.type.system.odps2=true; before a statement — does not work when submitting SQL through the SDK. Use SQLTask.setProperty() instead:
// Create an SQLTask object
SQLTask task = new SQLTask();
task.setName("foobar");
task.setQuery("select ...");
// Build the flag map
Map<String, String> settings = new HashMap<>();
settings.put("odps.sql.type.system.odps2", "true");
// Add other flags as needed
// Key step: serialize the map as a JSON string and set it on the task
task.setProperty("settings", new JSONObject(settings).toString());
// Submit the task
Instance instance = odps.instances().create(task);
How do I use LogView to troubleshoot SDK for Java errors?
Use the generateLogView method from the LogView interface:
Instance i = SQLTask.run(odps, sql);
String logview = odps.logview().generateLogView(i, 7 * 24);
Open the returned URL to inspect the job execution details and identify the error.
How do I run an SQL job from Java business code?
Call MaxCompute SDK for Java directly in your Java code. For setup instructions and code examples, see SDK for Java.
How do I retrieve more than 10,000 records from a SQLTask query?
SQLTask caps results at 10,000 records. To get the full dataset, write the query result to a MaxCompute table and then download the table using Tunnel For more information, see Methods for exporting SQL results. commands.
What is the SQLTask result set limit?
When you call SQLTask.getResult(), the result set is capped at 10,000 records:
Instance instance = SQLTask.run(odps, "SQL statement");
instance.waitForSuccess();
List<Record> records = SQLTask.getResult(instance);
For larger datasets, use the Tunnel SDK to export the data instead.
What are the differences between SQLTask and DownloadSession?
| SQLTask | DownloadSession | |
|---|---|---|
| Purpose | Execute SQL statements and return results | Download data from an existing table |
| Result limit | 10,000 records by default | No upper limit |
Use SQLTask for ad-hoc queries where the result fits in memory. Use DownloadSession when you need to export a full table or a large dataset.
How do I fix long job execution times when using MaxCompute SDK for Java?
There are two common causes:
No LogView URL obtained for the instance
After calling instance.waitForSuccess(), the call blocks until the job finishes. If the job is slow, you have no visibility into why. Get the LogView URL for every instance so you can inspect the job in real time:
Instance i = SQLTask.run(odps, sql);
String logview = odps.logview().generateLogView(i, 7 * 24);
System.out.println("LogView: " + logview);
i.waitForSuccess();
Alternatively, run WAIT <instance_id> in the MaxCompute client (odpscmd) to get the LogView URL for a running instance. For more details, see Instance LogView.
RestClient retries are silently failing
If a table access operation triggers repeated RestClient retries, the root cause is hidden unless you capture the retry logs. Implement the RetryLogger abstract class to log each retry attempt and identify the failure. For implementation details, see Return error logs.
How do I fix java.lang.ClassNotFoundException?
This usually means a dependency is missing or duplicated in your local environment. Check your project configuration:
-
Make sure all required dependencies are declared and resolved correctly.
-
Remove any duplicate package imports.
If the error occurs when running a MapReduce job in MaxCompute, check whether the required dependencies are included using the -resources parameter.
How do I fix OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory?
The directory used to store JVM temporary files is out of space. Run df to check the available space in that directory, then clear enough space to continue.