Skip to content

Commit 96083be

Browse files
Merge pull request #48 from zhanghaochenFCB/master
add updateFullRow option; update to 5.17.4
2 parents 8ba25df + 5589716 commit 96083be

File tree

16 files changed

+799
-379
lines changed

16 files changed

+799
-379
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
- 阿里云表格存储是阿里云自主研发的NoSQL数据存储服务,提供海量结构化数据的存储和实时访问。
1010

1111
## 版本
12-
- 当前版本:5.17.3
12+
- 当前版本:5.17.4
1313

1414
## 运行环境
1515
- JDK 6及其以上
1616

1717
## 安装
1818
#### Maven方式
19-
下载[最新版JAR包](https://search.maven.org/remotecontent?filepath=com/aliyun/openservices/tablestore/5.17.3/tablestore-5.17.3.jar)或者通过Maven:
19+
下载[最新版JAR包](https://search.maven.org/remotecontent?filepath=com/aliyun/openservices/tablestore/5.17.4/tablestore-5.17.4.jar)或者通过Maven:
2020
```xml
2121
<dependency>
2222
<groupId>com.aliyun.openservices</groupId>
2323
<artifactId>tablestore</artifactId>
24-
<version>5.17.3</version>
24+
<version>5.17.4</version>
2525
</dependency>
2626
```
2727

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.aliyun.openservices</groupId>
55
<artifactId>tablestore</artifactId>
6-
<version>5.17.3</version>
6+
<version>5.17.4</version>
77
<packaging>jar</packaging>
88
<name>AliCloud TableStore SDK for Java</name>
99
<url>http://www.aliyun.com</url>

src/main/java/com/alicloud/openservices/tablestore/core/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class Constants {
66
// ALL HTTP HEADERS SHOULD BE DEFINED IN LOWERCASE
77
// request headers
8-
public static final String USER_AGENT = "ots-java-sdk 5.17.3";
8+
public static final String USER_AGENT = "ots-java-sdk 5.17.4";
99
public static final String OTS_HEADER_API_VERSION = "x-ots-apiversion";
1010
public static final String OTS_HEADER_ACCESS_KEY_ID = "x-ots-accesskeyid";
1111
public static final String OTS_HEADER_OTS_CONTENT_MD5 = "x-ots-contentmd5";

src/main/java/com/alicloud/openservices/tablestore/core/protocol/OTSProtocolBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public static OtsInternalApi.CreateTableRequest buildCreateTableExRequest(Create
379379
return builder.build();
380380
}
381381

382-
private static OtsInternalApi.TableOptions buildTableOptions(TableOptions x) {
382+
public static OtsInternalApi.TableOptions buildTableOptions(TableOptions x) {
383383
OtsInternalApi.TableOptions.Builder builder = OtsInternalApi.TableOptions.newBuilder();
384384

385385
if (x.hasSetMaxVersions()) {
@@ -398,6 +398,10 @@ private static OtsInternalApi.TableOptions buildTableOptions(TableOptions x) {
398398
builder.setAllowUpdate(x.getAllowUpdate());
399399
}
400400

401+
if (x.hasSetUpdateFullRow()) {
402+
builder.setUpdateFullRow(x.getUpdateFullRow());
403+
}
404+
401405
return builder.build();
402406
}
403407

src/main/java/com/alicloud/openservices/tablestore/core/protocol/OTSProtocolParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ public static TableOptions parseTableOptions(OtsInternalApi.TableOptions tableOp
190190
result.setAllowUpdate(tableOptions.getAllowUpdate());
191191
}
192192

193+
if (tableOptions.hasUpdateFullRow()) {
194+
result.setUpdateFullRow(tableOptions.getUpdateFullRow());
195+
}
196+
193197
return result;
194198
}
195199

src/main/java/com/alicloud/openservices/tablestore/core/protocol/OtsInternalApi.java

Lines changed: 411 additions & 353 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/alicloud/openservices/tablestore/core/protocol/ots_internal_api.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ message TableOptions {
4646
optional int32 max_versions = 2;
4747
optional int64 deviation_cell_version_in_sec = 5;
4848
optional bool allow_update = 6;
49+
optional bool update_full_row = 7;
4950
}
5051

5152
enum IndexUpdateMode {

src/main/java/com/alicloud/openservices/tablestore/model/TableOptions.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ public class TableOptions implements Jsonizable {
4141
*/
4242
private OptionalValue<Boolean> allowUpdate = new OptionalValue<Boolean>("AllowUpdate");
4343

44+
/**
45+
* 表中的数据在Update时是否必须整行一起更新。
46+
* 整行更新:Update部分列,会自动将原始列的版本号填充到行上。
47+
* 比如某一行有列pk、a、b、c,Update的列参数只包含pk、a,则b、c列的版本号会被自动填充(和pk、a列的版本号一致)。
48+
* 该配置项默认设置为false。
49+
* 如果设置为true,
50+
* 优势(为什么要整行一起更新):对应的表在allow_update为true时,也能支持二级索引和多元索引的TTL功能;
51+
* 如果配置项为false且allow_update为true,则不支持索引TTL。
52+
* 劣势:1. Update操作会自动填充原始列的版本号,会增加Update请求的写负载。
53+
* 2. 同时,由于要自动填充原始列,Update操作的读负载(写前读取原始列),并增加读CU。
54+
* 在表创建后,该配置不可动态修改。
55+
*/
56+
private OptionalValue<Boolean> updateFullRow = new OptionalValue<Boolean>("UpdateFullRow");
57+
4458
/**
4559
* 构造TableOptions对象。
4660
*/
@@ -87,6 +101,17 @@ public TableOptions(boolean allowUpdate) {
87101
setAllowUpdate(allowUpdate);
88102
}
89103

104+
/**
105+
* 构造TableOptions对象。
106+
*
107+
* @param allowUpdate 是否允许有Update操作
108+
* @param updateFullRow Update时是否必须整行一起更新
109+
*/
110+
public TableOptions(boolean allowUpdate, boolean updateFullRow) {
111+
setAllowUpdate(allowUpdate);
112+
setUpdateFullRow(updateFullRow);
113+
}
114+
90115
/**
91116
* 获取TTL时间,单位为秒。
92117
*
@@ -226,9 +251,35 @@ public boolean getAllowUpdate() {
226251
return allowUpdate.getValue();
227252
}
228253

254+
/**
255+
* 查询是否调用{@link #setUpdateFullRow(boolean)}来设置在数据Update时,是否必须整行一起更新
256+
* @return 是否有设置UpdateFullRow
257+
*/
258+
public boolean hasSetUpdateFullRow() { return this.updateFullRow.isValueSet(); }
259+
260+
/**
261+
* 获取数据Update时是否必须整行一起更新
262+
* @return Update时是否必须整行一起更新
263+
* @throws java.lang.IllegalStateException 若没有配置该参数
264+
*/
265+
public boolean getUpdateFullRow() {
266+
if (!this.updateFullRow.isValueSet()) {
267+
throw new IllegalStateException("The value of UpdateFullRow is not set.");
268+
}
269+
return this.updateFullRow.getValue();
270+
}
271+
272+
/**
273+
* 设置表在数据Update时,是否必须整行一起更新
274+
* @param updateFullRow
275+
*/
276+
public void setUpdateFullRow(boolean updateFullRow) {
277+
this.updateFullRow.setValue(updateFullRow);
278+
}
279+
229280
@Override
230281
public String toString() {
231-
return timeToLive + ", " + maxVersions + ", " + maxTimeDeviation + ", " + allowUpdate;
282+
return timeToLive + ", " + maxVersions + ", " + maxTimeDeviation + ", " + allowUpdate + ", " + updateFullRow;
232283
}
233284

234285
@Override
@@ -282,6 +333,15 @@ protected boolean jsonizeFields(StringBuilder sb, boolean firstItem) {
282333
sb.append("\"AllowUpdate\": ");
283334
sb.append(this.allowUpdate.getValue());
284335
}
336+
if (this.updateFullRow.isValueSet()) {
337+
if (firstItem) {
338+
firstItem = false;
339+
} else {
340+
sb.append(", ");
341+
}
342+
sb.append("\"UpdateFullRow\": ");
343+
sb.append(this.updateFullRow.getValue());
344+
}
285345
return firstItem;
286346
}
287347

src/test/java/com/alicloud/openservices/tablestore/common/TestUtil.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.alicloud.openservices.tablestore.common;
22

33
import com.alicloud.openservices.tablestore.model.*;
4+
import junit.framework.AssertionFailedError;
45

56
import java.lang.reflect.Field;
67
import java.util.ArrayList;
@@ -9,6 +10,7 @@
910
import java.util.Random;
1011

1112
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertTrue;
1214

1315
public class TestUtil {
1416

@@ -152,4 +154,22 @@ public static void injectEnvironmentVariable(String key, String value)
152154
Map<String, String> map = (Map<String, String>) mapField.get(null);
153155
map.put(key, value);
154156
}
157+
158+
public static <T extends Throwable> T expectThrowsAndMessages(Class<T> expectedType, Runnable runnable, String... messageKeys) {
159+
try {
160+
runnable.run();
161+
} catch (Throwable e) {
162+
if (expectedType.isInstance(e)) {
163+
String message = e.getMessage();
164+
for (String key : messageKeys) {
165+
assertTrue("message key[" + key + "] not in message:" + message, message.contains(key));
166+
}
167+
return expectedType.cast(e);
168+
}
169+
AssertionFailedError assertion = new AssertionFailedError("Unexpected exception type, expected " + expectedType.getSimpleName() + " but got " + e);
170+
assertion.initCause(e);
171+
throw assertion;
172+
}
173+
throw new AssertionFailedError("Expected exception " + expectedType.getSimpleName() + " but no exception was thrown");
174+
}
155175
}

src/test/java/com/alicloud/openservices/tablestore/functiontest/TimeseriesCustomPrimaryKeysTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import com.alicloud.openservices.tablestore.common.ServiceSettings;
66
import com.alicloud.openservices.tablestore.model.*;
77
import com.alicloud.openservices.tablestore.model.timeseries.*;
8-
import org.junit.AfterClass;
9-
import org.junit.Assert;
10-
import org.junit.BeforeClass;
11-
import org.junit.Test;
8+
import org.junit.*;
129

1310
import java.util.ArrayList;
1411
import java.util.HashMap;
@@ -153,6 +150,7 @@ public void testCustomPrimaryKeys() {
153150
}
154151
}
155152

153+
@Ignore
156154
@Test
157155
public void testCustomPrimaryKeysMeta() throws InterruptedException {
158156
// create table

0 commit comments

Comments
 (0)