Skip to content

Commit 0b3522b

Browse files
author
wangtantan
committed
support SearchIndex and GlobalIndex
1 parent 2b0d517 commit 0b3522b

37 files changed

+4593
-99
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
- 阿里云表格存储是阿里云自主研发的NoSQL数据存储服务,提供海量结构化数据的存储和实时访问。
1111

1212
## 版本
13-
- 当前版本:4.0.14
13+
- 当前版本:4.1.0
14+
15+
## 版本特性
16+
- 支持SearchIndex
17+
- 支持GlobalIndex
1418

1519
## 安装
1620

lib/client.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,57 @@ TableStore.Client = inherit({
238238
*/
239239
batchWriteRow: function batchWriteRow(params, callback) {
240240
return this.makeRequest('batchWriteRow', params, callback);
241-
}
241+
},
242+
243+
/**
244+
* 获取表下所有SearchIndex索引名。
245+
*/
246+
listSearchIndex: function listSearchIndex(params, callback) {
247+
return this.makeRequest('listSearchIndex', params, callback);
248+
},
249+
250+
/**
251+
* 获取SearchIndex索引描述信息。
252+
*/
253+
describeSearchIndex: function describeSearchIndex(params, callback) {
254+
return this.makeRequest('describeSearchIndex', params, callback);
255+
},
256+
257+
/**
258+
* SearchIndex创建新索引。
259+
*/
260+
createSearchIndex: function createSearchIndex(params, callback) {
261+
return this.makeRequest('createSearchIndex', params, callback);
262+
},
263+
264+
/**
265+
* SearchIndex删除索引。
266+
*/
267+
deleteSearchIndex: function deleteSearchIndex(params, callback) {
268+
return this.makeRequest('deleteSearchIndex', params, callback);
269+
},
270+
271+
272+
/**
273+
* SearchIndex搜索。
274+
*/
275+
search: function search(params, callback) {
276+
return this.makeRequest('search', params, callback);
277+
},
278+
279+
/**
280+
* 创建GlobalIndex索引名。
281+
*/
282+
createIndex: function createIndex(params, callback) {
283+
return this.makeRequest('createIndex', params, callback);
284+
},
285+
286+
/**
287+
* 删除GlobalIndex索引名。
288+
*/
289+
dropIndex: function dropIndex(params, callback) {
290+
return this.makeRequest('dropIndex', params, callback);
291+
},
242292

243293
/********************************** 数据操作 结束 ******************************************/
244294
});

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TableStore.Config = TableStore.util.inherit({
6161
securityToken: null, // the same with stsToken
6262
logger: null,
6363
endpoint: undefined,
64-
httpOptions: {},//timeout
64+
httpOptions: {},//timeout,maxSockets。default maxSockets = 300
6565
maxRetries: undefined,
6666
instancename: undefined,
6767
computeChecksums: true,

lib/core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ require('./http/node');
2626
require('./retry/retry_util');
2727
require('./retry/default_retry_policy');
2828
require('./client');
29+
require('./search');

lib/http/node.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ TableStore.NodeHttpClient = TableStore.util.inherit({
1515

1616
var useSSL = endpoint.protocol === 'https:';
1717
var http = useSSL ? require('https') : require('http');
18-
http.globalAgent.maxSockets = 300;
18+
if (httpOptions.maxSockets) {
19+
http.globalAgent.maxSockets = httpOptions.maxSockets;
20+
} else {
21+
http.globalAgent.maxSockets = 300;
22+
}
1923
var options = {
2024
host: endpoint.hostname,
2125
port: endpoint.port,
@@ -31,6 +35,7 @@ TableStore.NodeHttpClient = TableStore.util.inherit({
3135
TableStore.util.update(options, httpOptions);
3236
delete options.proxy; // proxy isn't an HTTP option
3337
delete options.timeout; // timeout isn't an HTTP option
38+
delete options.maxSockets; // maxSockets isn't an HTTP option
3439

3540
var stream = http.request(options, function (httpResp) {
3641
callback(httpResp);
@@ -40,15 +45,15 @@ TableStore.NodeHttpClient = TableStore.util.inherit({
4045

4146
// timeout support
4247
stream.setTimeout(httpOptions.timeout || 0);
43-
stream.once('timeout', function() {
48+
stream.once('timeout', function () {
4449
var msg = 'Connection timed out after ' + httpOptions.timeout + 'ms';
45-
errCallback(TableStore.util.error(new Error(msg), {code: 'TimeoutError'}));
50+
errCallback(TableStore.util.error(new Error(msg), { code: 'TimeoutError' }));
4651

4752
// HACK - abort the connection without tripping our error handler
4853
// since we already raised our TimeoutError. Otherwise the connection
4954
// comes back with ECONNRESET, which is not a helpful error message
5055
stream.removeListener('error', errCallback);
51-
stream.on('error', function() { });
56+
stream.on('error', function () { });
5257
stream.abort();
5358
});
5459

@@ -78,13 +83,13 @@ TableStore.NodeHttpClient = TableStore.util.inherit({
7883
var https = require('https');
7984

8085
if (!TableStore.NodeHttpClient.sslAgent) {
81-
TableStore.NodeHttpClient.sslAgent = new https.Agent({rejectUnauthorized: true});
86+
TableStore.NodeHttpClient.sslAgent = new https.Agent({ rejectUnauthorized: true });
8287
TableStore.NodeHttpClient.sslAgent.setMaxListeners(0);
8388

8489
// delegate maxSockets to globalAgent
8590
Object.defineProperty(TableStore.NodeHttpClient.sslAgent, 'maxSockets', {
8691
enumerable: true,
87-
get: function() { return https.globalAgent.maxSockets; }
92+
get: function () { return https.globalAgent.maxSockets; }
8893
});
8994
}
9095
return TableStore.NodeHttpClient.sslAgent;
@@ -94,7 +99,7 @@ TableStore.NodeHttpClient = TableStore.util.inherit({
9499
var numBytes = 0;
95100
var totalBytes = httpRequest.headers['Content-Length'];
96101
var writer = new WritableStream();
97-
writer._write = function(chunk, encoding, callback) {
102+
writer._write = function (chunk, encoding, callback) {
98103
if (chunk) {
99104
numBytes += chunk.length;
100105
stream.emit('sendProgress', {
@@ -111,7 +116,7 @@ TableStore.NodeHttpClient = TableStore.util.inherit({
111116

112117
var readable = new ReadableStream();
113118
var pos = 0;
114-
readable._read = function(size) {
119+
readable._read = function (size) {
115120
if (pos >= buffer.length) return readable.push(null);
116121

117122
var end = pos + size;

lib/metadata.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ TableStore.ReturnType = {
2323
Primarykey: 1
2424
};
2525

26+
TableStore.DefinedColumnType = {
27+
DCT_INTEGER: 1,
28+
DCT_DOUBLE: 2,
29+
DCT_BOOLEAN: 3,
30+
DCT_STRING: 4
31+
};
32+
33+
TableStore.PrimaryKeyType = {
34+
INTEGER: 1,
35+
STRING: 2,
36+
BINARY: 3
37+
}
38+
2639
TableStore.INF_MIN = {};
2740

2841
TableStore.INF_MAX = {};

lib/protocol/decoder.js

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var TableStore = require('../core');
22
var tsProtos = require('./tablestore_proto.js').tablestore.proto;
33
var tsFilterProtos = require('./tablestore_filter_proto.js').tablestore.filter.proto;
4+
var tsSearchProtos = require('./tablestore_search_proto.js').tablestore.search.proto;
45

56
TableStore.decoder = {
67
decode: function (operation, buffers) {
@@ -164,7 +165,56 @@ TableStore.decoder = {
164165
};
165166

166167
return writeRowItem;
167-
}
168+
},
169+
decodeListSearchIndex: function (buffers) {
170+
var response = tsSearchProtos.ListSearchIndexResponse.decode(buffers);
171+
return response;
172+
},
173+
decodeDescribeSearchIndex: function (buffers) {
174+
var response = tsSearchProtos.DescribeSearchIndexResponse.decode(buffers);
175+
if (response.sync_stat && response.sync_stat.current_sync_timestamp) {//nino second
176+
response.sync_stat.current_sync_timestamp = response.sync_stat.current_sync_timestamp.toString();
177+
}
178+
179+
return response;
180+
},
181+
decodeCreateSearchIndex: function (buffers) {
182+
var response = tsSearchProtos.CreateSearchIndexResponse.decode(buffers);
183+
return response;
184+
},
185+
decodeDeleteSearchIndex: function (buffers) {
186+
var response = tsSearchProtos.DeleteSearchIndexResponse.decode(buffers);
187+
return response;
188+
},
189+
decodeSearch: function (buffers) {
190+
var response = tsSearchProtos.SearchResponse.decode(buffers);
191+
var result = {};
192+
var totalCounts = response.total_hits.toString();
193+
if (totalCounts != "-1") {
194+
result.totalCounts = totalCounts;
195+
}
196+
result.isAllSucceeded = response.is_all_succeeded;
197+
result.nextToken = response.next_token;
198+
199+
var rows = [];
200+
TableStore.util.arrayEach(response.rows, function(aRow) {
201+
var inputStream = new TableStore.PlainBufferInputStream(aRow);
202+
var codedInputStream = new TableStore.PlainBufferCodedInputStream(inputStream);
203+
var row = codedInputStream.readRow();
204+
rows.push(row);
205+
});
206+
result.rows = rows;
207+
208+
return result;
209+
},
210+
decodeCreateIndex: function (buffers) {
211+
var response = tsSearchProtos.CreateSearchIndexResponse.decode(buffers);
212+
return response;
213+
},
214+
decodeDropIndex: function (buffers) {
215+
var response = tsSearchProtos.DeleteSearchIndexResponse.decode(buffers);
216+
return response;
217+
},
168218
};
169219

170220
var tsMap = {
@@ -179,5 +229,12 @@ var tsMap = {
179229
'deleteRow': TableStore.decoder.decodeDeleteRow,
180230
'getRange': TableStore.decoder.decodeGetRange,
181231
'batchGetRow': TableStore.decoder.decodeBatchGetRow,
182-
'batchWriteRow': TableStore.decoder.decodeBatchWriteRow
232+
'batchWriteRow': TableStore.decoder.decodeBatchWriteRow,
233+
'listSearchIndex': TableStore.decoder.decodeListSearchIndex,
234+
'describeSearchIndex': TableStore.decoder.decodeDescribeSearchIndex,
235+
'createSearchIndex': TableStore.decoder.decodeCreateSearchIndex,
236+
'deleteSearchIndex': TableStore.decoder.decodeDeleteSearchIndex,
237+
'search': TableStore.decoder.decodeSearch,
238+
'createIndex': TableStore.decoder.decodeCreateIndex,
239+
'dropIndex': TableStore.decoder.decodeDropIndex,
183240
};

0 commit comments

Comments
 (0)