Skip to content

Commit 0542ad3

Browse files
committed
prepare for 0.50.4
1 parent adafa5e commit 0542ad3

File tree

10 files changed

+100
-57
lines changed

10 files changed

+100
-57
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
# Changelog
2+
## [0.50.4-public] - 2024-10-29
3+
4+
### Features
5+
- **PartitionSpec** Added a new constructor `(String, boolean)` that uses a boolean parameter to specify whether to trim partition values. This caters to scenarios (such as using char type as a partition field) where users may not want to trim partition values.
6+
7+
### Changes
8+
- **Instance** The OdpsException thrown when calling the stop method will no longer be wrapped a second time.
9+
10+
### Fixes
11+
- **SQLExecutor**
12+
- Fixed an issue in MCQA 1.0 mode where the user-specified `fallbackPolicy.isFallback4AttachError` did not take effect correctly.
13+
- Fixed an issue in MCQA 2.0 mode where the `cancel` method threw an exception when the job failed.
14+
- Fixed an issue in MCQA 2.0 mode where using instanceTunnel to fetch results resulted in an error when the isSelect check was incorrect.
15+
- **Table** Fixed an issue with the `getPartitionSpecs` method that trimmed partition values, causing the retrieval of non-existing partitions.
16+
217
## [0.50.3-public] - 2024-10-23
318
### Features
419
- **SQLExecutor** In MCQA 1.0 mode, it is allowed to add custom fallback policies, add subclass `FallbackPolicy.UserDefinedFallbackPolicy`.

CHANGELOG_CN.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
# 更新日志
2+
## [0.50.4-public] - 2024-10-29
3+
4+
### 功能
5+
- **PartitionSpec** 新增`(String, boolean)`构造方法,通过布尔参数指定是否对分区值进行trim操作,以满足某些场景(如使用char类型作为分区字段)用户不希望trim的需求。
6+
7+
### 变更
8+
- **Instance** 在调用stop方法时,抛出的OdpsException将不再被二次包装。
9+
10+
### 修复
11+
- **SQLExecutor**
12+
- 修复了在MCQA 1.0模式下,用户指定`fallbackPolicy.isFallback4AttachError`时未正确生效的问题。
13+
- 修复了在MCQA 2.0模式下,作业失败时`cancel`方法抛出异常的问题。
14+
- 修复了在MCQA 2.0模式下,当isSelect判断错误时,通过instanceTunnel取结果报错的问题。
15+
- **Table** 修复了`getPartitionSpecs`方法会trim分区值,导致无法获取存在的分区的问题。
16+
17+
218
## [0.50.3-public] - 2024-10-23
319
### 功能
420
- **SQLExecutor** 在 MCQA 1.0 模式下,允许增加自定义回退策略,新增类`FallbackPolicy.UserDefinedFallbackPolicy`

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/PartitionSpec.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public PartitionSpec() {
4949
* 分区定义字符串,分区列之间可以用逗号 (",") 或斜线 ("/") 分隔. 例如: "pt1=foo/pt2=1" 或 "pt1=foo,pt2=1"
5050
*/
5151
public PartitionSpec(String spec) {
52+
this(spec, true);
53+
}
54+
55+
public PartitionSpec(String spec, boolean trim) {
5256
if (spec == null) {
5357
throw new IllegalArgumentException("Argument \'spec\' cannot be null");
5458
}
@@ -59,8 +63,10 @@ public PartitionSpec(String spec) {
5963
throw new IllegalArgumentException("Invalid partition spec.");
6064
}
6165

62-
String k = kv[0].trim();
63-
String v = kv[1].trim().replaceAll("'", "").replaceAll("\"", "");
66+
String k = trim ? kv[0].trim() : kv[0];
67+
String v = (trim ? kv[1].trim() : kv[1])
68+
.replaceAll("'", "")
69+
.replaceAll("\"", "");
6470
if (k.length() == 0 || v.length() == 0) {
6571
throw new IllegalArgumentException("Invalid partition spec.");
6672
}

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/Instance.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ public void stop() throws OdpsException {
350350
String ret = SimpleXmlUtils.marshal(sm);
351351
Map<String, String> headers = getCommonHeaders();
352352
client.stringRequest(getResource(), "PUT", null, headers, ret);
353+
} catch (OdpsException e) {
354+
throw e;
353355
} catch (Exception e) {
354356
throw new OdpsException(e.getMessage(), e);
355357
}

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/Table.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ public List<PartitionSpec> getPartitionSpecs() throws OdpsException {
16901690
"GET",
16911691
params);
16921692
for (PartitionSpecModel partitionSpecModel : resp.partitionSpecs) {
1693-
partitionSpecs.add(new PartitionSpec(partitionSpecModel.partitionSpec));
1693+
partitionSpecs.add(new PartitionSpec(partitionSpecModel.partitionSpec, false));
16941694
}
16951695

16961696
return partitionSpecs;

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/sqa/SQLExecutorConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Created by dongxiao on 2020/3/16.
55
*/
6-
class SQLExecutorConstants {
6+
public class SQLExecutorConstants {
77
public static final String DEFAULT_TASK_NAME = "console_sqlrt_task";
88
public static final String DEFAULT_SERVICE = "public.default";
99
public static final String DEFAULT_OFFLINE_TASKNAME = "sqlrt_fallback_task";

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/sqa/v2/SQLExecutorImpl.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.aliyun.odps.sqa.QueryInfo;
2727
import com.aliyun.odps.sqa.SQLExecutor;
2828
import com.aliyun.odps.sqa.SQLExecutorBuilder;
29+
import com.aliyun.odps.sqa.SQLExecutorConstants;
2930
import com.aliyun.odps.sqa.SQLExecutorPool;
3031
import com.aliyun.odps.sqa.commandapi.Command;
3132
import com.aliyun.odps.sqa.commandapi.CommandInfo;
@@ -35,6 +36,7 @@
3536
import com.aliyun.odps.table.utils.Preconditions;
3637
import com.aliyun.odps.task.SQLTask;
3738
import com.aliyun.odps.tunnel.InstanceTunnel;
39+
import com.aliyun.odps.tunnel.TunnelException;
3840
import com.aliyun.odps.tunnel.io.TunnelRecordReader;
3941
import com.aliyun.odps.utils.CSVRecordParser;
4042
import com.aliyun.odps.utils.StringUtils;
@@ -191,8 +193,13 @@ public boolean isActive() {
191193
public void cancel() throws OdpsException {
192194
if (queryInfo != null) {
193195
Instance instance = queryInfo.getInstance();
194-
if (instance.getStatus() == Instance.Status.RUNNING) {
196+
try {
195197
instance.stop();
198+
} catch (OdpsException e) {
199+
// stop will throw exception when instance is not running, so we check here.
200+
if (!"InvalidStateSetting".equals(e.getErrorCode())) {
201+
throw e;
202+
}
196203
}
197204
}
198205
}
@@ -580,7 +587,12 @@ private ResultSet getResultSetByInstanceTunnel(Long offset, Long countLimit, Lon
580587
downloadSession =
581588
instanceTunnel.createDownloadSession(odps.getDefaultProject(), queryInfo.getInstance().getId(),
582589
limitEnabled);
583-
} catch (OdpsException e) {
590+
} catch (TunnelException e) {
591+
if (e.getErrorCode().equals(SQLExecutorConstants.sessionNotSelectException)
592+
|| e.getErrorMsg().contains(SQLExecutorConstants.sessionNotSelectMessage)) {
593+
queryInfo.setSelect(false);
594+
return getResultSetByInstanceTunnel(offset, countLimit, sizeLimit, limitEnabled);
595+
}
584596
if (e.getErrorCode().equals("TaskFailed")) {
585597
// wait for success will check task status and throw exception
586598
queryInfo.getInstance().waitForSuccess();

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/tunnel/impl/StreamUploadSessionImpl.java

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ private Connection getConnection(CompressOption compress, Slot slot, long size,
272272

273273
headers.put(HttpHeaders.HEADER_ODPS_SLOT_NUM, String.valueOf(slots.getSlotNum()));
274274

275-
List<String> tags = config.getTags();
276-
if (tags != null) {
277-
headers.put(HttpHeaders.HEADER_ODPS_TUNNEL_TAGS, String.join(",", tags));
278-
}
279-
280275
if (!StringUtils.isNullOrEmpty(config.getQuotaName())) {
281276
params.put(TunnelConstants.PARAM_QUOTA_NAME, config.getQuotaName());
282277
}
@@ -460,50 +455,4 @@ public TableTunnel.StreamRecordPack newRecordPack(CompressOption option) throws
460455
public Record newRecord() {
461456
return new ArrayRecord(schema.getColumns().toArray(new Column[0]));
462457
}
463-
464-
// abort does not support retry
465-
public void abort() throws TunnelException {
466-
HashMap<String, String> params = new HashMap<String, String>();
467-
468-
params.put(TunnelConstants.UPLOADID, id);
469-
470-
if (this.partitionSpec != null && this.partitionSpec.length() > 0) {
471-
params.put(TunnelConstants.RES_PARTITION, partitionSpec);
472-
}
473-
474-
HashMap<String, String> headers = Util.getCommonHeader();
475-
List<String> tags = config.getTags();
476-
if (tags != null) {
477-
headers.put(HttpHeaders.HEADER_ODPS_TUNNEL_TAGS, String.join(",", tags));
478-
}
479-
Slot slot = slots.iterator().next();
480-
headers.put(HttpHeaders.HEADER_ODPS_ROUTED_SERVER, slot.getServer());
481-
482-
Connection conn = null;
483-
String requestId = null;
484-
try {
485-
conn = httpClient.connect(getResource(), "POST", params, headers);
486-
Response resp = conn.getResponse();
487-
requestId = resp.getHeader(HEADER_ODPS_REQUEST_ID);
488-
489-
if (!resp.isOK()) {
490-
throw new TunnelException(requestId, conn.getInputStream(), resp.getStatus());
491-
}
492-
} catch (IOException e) {
493-
throw new TunnelException(requestId, "Failed abort upload session with tunnel endpoint "
494-
+ httpClient.getEndpoint(), e);
495-
} catch (TunnelException e) {
496-
// Do not delete here! TunnelException extends from OdpsException.
497-
throw e;
498-
} catch (OdpsException e) {
499-
throw new TunnelException("not available", e.getMessage(), e);
500-
} finally {
501-
if (conn != null) {
502-
try {
503-
conn.disconnect();
504-
} catch (IOException e) {
505-
}
506-
}
507-
}
508-
}
509458
}

odps-sdk/odps-sdk-core/src/test/java/com/aliyun/odps/TableTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.aliyun.odps.type.MapTypeInfo;
6464
import com.aliyun.odps.type.TypeInfo;
6565
import com.aliyun.odps.type.TypeInfoFactory;
66+
import com.google.common.collect.ImmutableMap;
6667
import com.google.gson.JsonObject;
6768
import com.google.gson.JsonParser;
6869
import com.sun.org.apache.xml.internal.utils.URI;
@@ -263,6 +264,30 @@ public void testReadTable() throws OdpsException, IOException {
263264
Assert.assertEquals(count, limit);
264265
}
265266

267+
@Test
268+
public void testListPartitionSpecsWithoutTrim() throws OdpsException {
269+
String tableName = "testListPartitionSpecsWithoutTrim";
270+
odps.tables().newTableCreator(tableName,
271+
TableSchema.builder().withBigintColumn("id")
272+
.withPartitionColumn(Column.newBuilder("char1", TypeInfoFactory.getCharTypeInfo(10)).build())
273+
.withPartitionColumn(Column.newBuilder("char2", TypeInfoFactory.getCharTypeInfo(10)).build())
274+
.build()).ifNotExists().withHints(ImmutableMap.of("odps.sql.type.system.odps2", "true")).debug().create();
275+
276+
Table table = odps.tables().get(tableName);
277+
278+
table.createPartition(new PartitionSpec("char1=' 1 ',char2=' bar '", false), true);
279+
280+
table.getPartitionSpecs().forEach(p -> {
281+
System.out.println(p.toString());
282+
try {
283+
Assert.assertTrue(table.hasPartition(p));
284+
} catch (OdpsException e) {
285+
throw new RuntimeException(e);
286+
}
287+
});
288+
}
289+
290+
/* BEGIN: opensource removal */
266291
@Test
267292
public void testColumnLabel() throws OdpsException {
268293
Table table = odps.tables().get(TABLE_NAME);

odps-sdk/odps-sdk-core/src/test/java/com/aliyun/odps/sqa/SQLExecutorV2Test.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ private static Odps getTestOdps() throws OdpsException {
4343
odps.setDefaultProject("vw2");
4444
return odps;
4545
}
46+
47+
48+
@Test
49+
public void testCancelJobTest() throws OdpsException, IOException {
50+
executor.run("select 1;", hints);
51+
executor.getResultSet().forEach(System.out::println);
52+
executor.cancel();
53+
try {
54+
executor.getInstance().stop();
55+
} catch (OdpsException e) {
56+
System.out.println(e.getErrorCode());
57+
if (e.getErrorCode().equals("InvalidStateSetting")) {
58+
System.out.println("good");
59+
}
60+
}
61+
}
62+
63+
4664
@Test
4765
public void testGetTenantId() throws OdpsException {
4866
System.out.println(odps.projects().get("three_schema_project").getTenantId());

0 commit comments

Comments
 (0)