This topic describes how to use the MaxCompute Java SDK to set the SQL flag.

When using DataWorks or MaxCompute Console to submit SQL statements, you need to set the SQL flag. If you want to use a new data type of MaxCompute and enable it at the session level, add the statement set odps.sql.type.system.odps2=true; to set the SQL flag before the SQL query statement that involves the new data type.

When using the SDK to submit SQL statements, do not simply insert the statement used to set the SQL flag into SQL query statements. For example, if you use the Java SDK, you can set the SQL flag as follows:
// Create an SQLTask object.
SQLTask task = new SQLTask();
task.setName("foobar");
task.setQuery("select ...") ;
// Set the SQL flag.
Map<String, String> settings = new HashMap<>();
settings.put("odps.sql.type.system.odps2", "true");
...  // Set other flags.
task.setProperty("settings", new JSONObject(settings).toString());  // Set the settings property to the JSON string corresponding to other flags.
Instance instance = odps.instances().create(task);  // Run the SQL statement.