├── .gitignore
├── LICENSE
├── README.md
├── README_EN.md
├── basic
└── Java
│ ├── Common
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── basic
│ │ └── common
│ │ └── Config.java
│ ├── DataManage-GetRow
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── basic
│ │ └── GetRowExample.java
│ ├── DataManage
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── basic
│ │ ├── common
│ │ └── Consts.java
│ │ └── dataManage
│ │ ├── ConditionUpdateSample.java
│ │ ├── MultiRowManage.java
│ │ ├── SingleRowAutoIncManage.java
│ │ ├── SingleRowManage.java
│ │ ├── UpdateRowExample.java
│ │ └── base
│ │ ├── BaseAutoIncManage.java
│ │ └── BaseManage.java
│ ├── GlobalIndexCRD
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── basic
│ │ ├── BaseExample.java
│ │ ├── GlobalIndexCRDExample.java
│ │ ├── common
│ │ └── Consts.java
│ │ └── model
│ │ └── CallDO.java
│ ├── LocalTransaction
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── basic
│ │ ├── BaseExample.java
│ │ └── LocalTransactionExample.java
│ ├── README.md
│ ├── TableManage
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── basic
│ │ └── TableManage.java
│ └── pom.xml
├── demos
├── Canal-press
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ ├── Application.java
│ │ └── com
│ │ │ └── aliyun
│ │ │ └── tablestore
│ │ │ └── examples
│ │ │ ├── bean
│ │ │ ├── Automobile
│ │ │ │ ├── AutomobileBean.java
│ │ │ │ └── NextMove.java
│ │ │ ├── OperationResult.java
│ │ │ └── OrderContract.java
│ │ │ ├── config
│ │ │ └── DataSourceConfig.java
│ │ │ ├── controller
│ │ │ ├── AutomobileController.java
│ │ │ └── CanalController.java
│ │ │ ├── dao
│ │ │ └── user
│ │ │ │ ├── AutomobileMapper.java
│ │ │ │ └── UserMapper.java
│ │ │ └── service
│ │ │ ├── AutomobileService.java
│ │ │ ├── CanalConnectService.java
│ │ │ └── CanalService.java
│ │ └── resources
│ │ ├── application.yml
│ │ ├── logback.xml
│ │ └── mapper
│ │ ├── AutomobileMapper.xml
│ │ └── UserMapper.xml
├── ImChart
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ ├── chart
│ │ ├── TimelineV2.java
│ │ ├── Util.java
│ │ ├── common
│ │ │ ├── Config.java
│ │ │ └── ExampleCons.java
│ │ ├── model
│ │ │ ├── AppMessage.java
│ │ │ ├── Conversation.java
│ │ │ ├── Group.java
│ │ │ ├── Sexuality.java
│ │ │ ├── TimelineType.java
│ │ │ └── User.java
│ │ └── service
│ │ │ ├── IMessageService.java
│ │ │ ├── IRelationService.java
│ │ │ ├── ITableService.java
│ │ │ ├── IUserService.java
│ │ │ ├── MessageService.java
│ │ │ ├── RelationService.java
│ │ │ ├── TableService.java
│ │ │ └── UserService.java
│ │ └── example
│ │ ├── BaseExample.java
│ │ ├── ClientRequestExample.java
│ │ ├── InitChartRoomExample.java
│ │ └── ReleaseChartRoomExample.java
├── MailManagement
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ ├── MailManagement.java
│ │ ├── ManageService.java
│ │ └── common
│ │ ├── Conf.java
│ │ └── Util.java
├── Orders
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ ├── Application.java
│ │ └── com
│ │ │ └── aliyun
│ │ │ └── tablestore
│ │ │ └── examples
│ │ │ ├── bean
│ │ │ ├── BrandAndPriceRange.java
│ │ │ ├── ConsumerOrderCount.java
│ │ │ ├── ConsumerTradeValue.java
│ │ │ ├── OperationResult.java
│ │ │ └── OrderContract.java
│ │ │ ├── config
│ │ │ ├── DLADataSourceConfig.java
│ │ │ ├── DataSourceConfig.java
│ │ │ └── SysClientConfig.java
│ │ │ ├── controller
│ │ │ ├── IndexController.java
│ │ │ └── TypeController.java
│ │ │ ├── dao
│ │ │ ├── dla
│ │ │ │ └── DLAMapper.java
│ │ │ └── user
│ │ │ │ └── UserMapper.java
│ │ │ └── service
│ │ │ ├── CommonService.java
│ │ │ ├── RdsService.java
│ │ │ └── SearchService.java
│ │ └── resources
│ │ ├── application.yml
│ │ └── mapper
│ │ ├── DALMapper.xml
│ │ └── UserMapper.xml
├── SharingCarManagement
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ ├── ApiService.java
│ │ ├── SharingCarExample.java
│ │ ├── common
│ │ ├── Conf.java
│ │ └── Util.java
│ │ └── model
│ │ ├── Car.java
│ │ ├── MonitorPoint.java
│ │ ├── Order.java
│ │ └── User.java
├── SharingPowerBank
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ ├── ApiService.java
│ │ ├── SharingPowerBankExample.java
│ │ ├── common
│ │ ├── Config.java
│ │ └── TablestoreConf.java
│ │ └── utils
│ │ ├── CabinetData.java
│ │ ├── CabinetGeo.java
│ │ ├── CabinetInfo.java
│ │ ├── CabinetTimeData.java
│ │ ├── Control.java
│ │ ├── CreateData.java
│ │ ├── Md5Utils.java
│ │ ├── OrderData.java
│ │ ├── RandomMake.java
│ │ └── StaticData.java
├── SportTrack
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ ├── example
│ │ ├── CreateStoreExample.java
│ │ ├── SportTrackQeuryExample.java
│ │ ├── TargetNearbyExample.java
│ │ ├── UploadSportTrackExample.java
│ │ └── common
│ │ │ ├── SportTrackExample.java
│ │ │ └── TablestoreConf.java
│ │ └── sporttrack
│ │ ├── ITrackStore.java
│ │ ├── ITrackWriter.java
│ │ ├── ITrackerReader.java
│ │ ├── TablestoreSportTrackConfig.java
│ │ ├── TablestoreTrack.java
│ │ ├── TablestoreTrackReader.java
│ │ ├── TablestoreTrackWriter.java
│ │ ├── consts
│ │ └── Constants.java
│ │ ├── model
│ │ ├── Coords.java
│ │ ├── Position.java
│ │ ├── SportObject.java
│ │ ├── SportObjectType.java
│ │ ├── SportTrackMeta.java
│ │ ├── SportTrackOrder.java
│ │ ├── SportType.java
│ │ ├── TargetNearbyEntity.java
│ │ ├── TargetNearbyType.java
│ │ └── TrackPosition.java
│ │ └── utils
│ │ ├── DistanceUtil.java
│ │ └── Md5Util.java
├── StreamCompute
│ ├── .gitignore
│ ├── README.md
│ ├── bin
│ │ ├── data_show_screen
│ │ └── mock_order_generator
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── assembly
│ │ └── package.xml
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── examples
│ │ ├── ReadData.java
│ │ ├── WriteData.java
│ │ └── utils
│ │ └── Conf.java
├── TableStore-Grid
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ ├── example
│ │ └── grid
│ │ │ ├── CreateStoreExample.java
│ │ │ ├── DataFetchExample.java
│ │ │ ├── DataImportExample.java
│ │ │ ├── MetaQueryExample.java
│ │ │ └── common
│ │ │ ├── ExampleConfig.java
│ │ │ ├── TableStoreConf.java
│ │ │ └── TableStoreGridExample.java
│ │ └── grid
│ │ ├── GridDataFetcher.java
│ │ ├── GridDataWriter.java
│ │ ├── GridStore.java
│ │ ├── TableStoreGrid.java
│ │ ├── TableStoreGridConfig.java
│ │ ├── consts
│ │ └── Constants.java
│ │ ├── core
│ │ ├── QueryBuilder.java
│ │ ├── RequestBuilder.java
│ │ ├── RowParser.java
│ │ ├── TableStoreDataFetcher.java
│ │ └── TableStoreDataWriter.java
│ │ ├── model
│ │ ├── GetDataParam.java
│ │ ├── GridDataSet.java
│ │ ├── GridDataSetMeta.java
│ │ ├── QueryGridDataSetResult.java
│ │ ├── QueryParams.java
│ │ ├── StoreOptions.java
│ │ └── grid
│ │ │ ├── Grid.java
│ │ │ ├── Grid2D.java
│ │ │ ├── Grid3D.java
│ │ │ ├── Grid4D.java
│ │ │ ├── Plane.java
│ │ │ ├── Point.java
│ │ │ └── Range.java
│ │ └── utils
│ │ ├── BlockUtil.java
│ │ └── ValueUtil.java
├── TraceMedicine
│ ├── .gitignore
│ ├── Readme.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── aliyun
│ │ │ └── tablestore
│ │ │ └── example
│ │ │ └── trace_medicine
│ │ │ ├── MedicineReadWriteExample.java
│ │ │ └── common
│ │ │ └── Conf.java
│ │ └── resources
│ │ ├── conf.json
│ │ └── data
│ │ ├── medicine_data.csv
│ │ └── medicine_meta.csv
├── WifiMonitor
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ ├── ManageService.java
│ │ ├── WifiMonitor.java
│ │ └── common
│ │ ├── Conf.java
│ │ └── Util.java
└── insurance-policy-management
│ ├── README.md
│ ├── pom.xml
│ └── src
│ └── main
│ └── java
│ └── com
│ └── aliyun
│ └── tablestore
│ └── example
│ ├── BaseExample.java
│ ├── CleanExampleTableAndIndex.java
│ ├── CreateExampleTableAndIndex.java
│ ├── ImportExampleData.java
│ ├── SearchPolicyExample.java
│ ├── consts
│ ├── ColumnConsts.java
│ └── NameConsts.java
│ ├── model
│ └── PolicyDO.java
│ └── utils
│ ├── ClientAndConfig.java
│ └── Utils.java
├── feature
├── AggregationAndGroupBy
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── example
│ │ ├── AggregationAndGroupBy.java
│ │ ├── BaseExample.java
│ │ ├── CleanupEnv.java
│ │ ├── consts
│ │ └── ColumnConsts.java
│ │ ├── model
│ │ └── PriceDO.java
│ │ └── utils
│ │ ├── ClientAndConfig.java
│ │ └── Utils.java
├── FuzzySearch
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── aliyun
│ │ └── tablestore
│ │ └── example
│ │ ├── BaseExample.java
│ │ ├── CleanupEnv.java
│ │ ├── FuzzySearchExample.java
│ │ ├── consts
│ │ └── ColumnConsts.java
│ │ ├── model
│ │ └── OrderDO.java
│ │ └── utils
│ │ ├── ClientAndConfig.java
│ │ └── Utils.java
├── TableCopy
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── aliyun
│ │ │ └── tablestore
│ │ │ └── examples
│ │ │ └── tablecopy
│ │ │ ├── OtsReaderProcessor.java
│ │ │ ├── TableCopySample.java
│ │ │ └── util
│ │ │ ├── OtsBaseConfig.java
│ │ │ ├── OtsReaderConfig.java
│ │ │ ├── OtsWriterConfig.java
│ │ │ └── TableCopyConfig.java
│ │ └── resources
│ │ ├── config.json
│ │ └── log4j2.xml
└── TableStoreSparkDemo
│ ├── README.md
│ ├── install.sh
│ ├── libs
│ └── emr-tablestore-2.2.0-SNAPSHOT.jar
│ ├── pic
│ ├── batch_cluster.png
│ ├── batch_local.png
│ ├── stream_local.png
│ └── streaming_cluster.png
│ ├── pom.xml
│ └── src
│ └── main
│ ├── resources
│ └── META-INF.services
│ │ └── org.apache.spark.sql.sources.DataSourceRegister
│ └── scala
│ └── com
│ └── aliyun
│ └── tablestore
│ └── spark
│ └── demo
│ ├── batch
│ ├── TableStoreBatchSample.scala
│ ├── TableStoreSearchIndexSample.scala
│ └── TableStoreSinkSample.scala
│ └── streaming
│ ├── StructuredTableStoreAggSQLSample.scala
│ ├── StructuredTableStoreAggSample.scala
│ └── StructuredTableStoreSinkSample.scala
├── image
└── QRcode.png
└── tools
├── Datax-MySQL2TableStore
├── README.md
└── mysql_to_ots.json
└── Dts-MySQL2TableStore
├── README.md
├── pom.xml
└── src
└── main
├── java
└── com
│ └── aliyun
│ └── dts
│ └── demo
│ ├── Main.java
│ └── utils
│ └── Utils.java
└── resources
├── log4j.properties
└── log4j.xml.bak
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # IDEA Files
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 |
31 | # Other Language Built Files
32 | target/
33 | node_modules/
34 | *.pyc
35 |
36 | # Others
37 | *.DS_Store
38 |
--------------------------------------------------------------------------------
/basic/Java/Common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | JavaParent
7 | com.aliyun.tablestore.basic
8 | 0.0.1
9 |
10 | 4.0.0
11 |
12 | Common
13 |
14 |
15 |
--------------------------------------------------------------------------------
/basic/Java/Common/src/main/java/com/aliyun/tablestore/basic/common/Config.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.basic.common;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.google.gson.Gson;
5 | import org.apache.commons.io.IOUtils;
6 |
7 | import java.io.FileInputStream;
8 | import java.io.InputStream;
9 |
10 | /**
11 | * @Author wtt
12 | * @create 2019/11/28 4:26 PM
13 | */
14 | public class Config {
15 | private String endpoint;
16 | private String accessId;
17 | private String accessKey;
18 | private String instanceName;
19 |
20 | public static Config newInstance(String path) {
21 | try {
22 | InputStream f = new FileInputStream(path);
23 | Gson gson = new Gson();
24 | return gson.fromJson(IOUtils.toString(f), Config.class);
25 | } catch (Exception ex) {
26 | throw new RuntimeException(ex);
27 | }
28 | }
29 |
30 | public static Config newInstance() {
31 | String os = System.getProperty("os.name");
32 | String pathSeparator = "/";
33 | if (os.toLowerCase().startsWith("win")) {
34 | pathSeparator = "\\";
35 | }
36 | return newInstance(System.getProperty("user.home") + pathSeparator + "tablestoreConf.json");
37 | }
38 |
39 | public SyncClient newClient() {
40 | return new SyncClient(
41 | getEndpoint(),
42 | getAccessId(),
43 | getAccessKey(),
44 | getInstanceName()
45 | );
46 | }
47 |
48 | public String getEndpoint() {
49 | return endpoint;
50 | }
51 |
52 | public void setEndpoint(String endpoint) {
53 | this.endpoint = endpoint;
54 | }
55 |
56 | public String getAccessId() {
57 | return accessId;
58 | }
59 |
60 | public void setAccessId(String accessId) {
61 | this.accessId = accessId;
62 | }
63 |
64 | public String getAccessKey() {
65 | return accessKey;
66 | }
67 |
68 | public void setAccessKey(String accessKey) {
69 | this.accessKey = accessKey;
70 | }
71 |
72 | public String getInstanceName() {
73 | return instanceName;
74 | }
75 |
76 | public void setInstanceName(String instanceName) {
77 | this.instanceName = instanceName;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/basic/Java/DataManage-GetRow/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | JavaParent
7 | com.aliyun.tablestore.basic
8 | 0.0.1
9 |
10 | 4.0.0
11 |
12 | DataManage-GetRow
13 |
14 |
15 | com.aliyun.tablestore.basic
16 | Common
17 | 0.0.1
18 |
19 |
20 | com.aliyun.tablestore.basic
21 | DataManage
22 | 0.0.1
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/basic/Java/DataManage/README.md:
--------------------------------------------------------------------------------
1 | # Data Manage @ Java
2 |
3 | Data Manage Based On Java SDK @ 5.3.0.
4 |
5 | ## Configuration
6 |
7 | Create the file tablestoreCong.json in the home path, and config the parameters.
8 | ```
9 | # Linux or mac system: /home/userhome/tablestoreCong.json
10 | # Windows system: C:\Documents and Settings\%userhome%\tablestoreCong.json
11 | {
12 | "endpoint": "http://instanceName.cn-hangzhou.ots.aliyuncs.com",
13 | "accessId": "***********",
14 | "accessKey": "***********************",
15 | "instanceName": "instanceName"
16 | }
17 | ```
18 | - endpoint: The endpoint of instance.
19 | - accessId: The id of AK.
20 | - accessKey: The secret of AK.
21 | - instanceName: The name of Tablestore instance.
22 |
23 |
24 | ## Getting started
25 |
26 | Table will be created when you run the project.
27 |
28 | ### 1. Single Row Management
29 |
30 | [SingleRowManage.java](src/main/java/com/aliyun/tablestore/basic/dataManage/SingleRowManage.java)
31 |
32 | ### 2. Single Row Management with Auto-Increment PrimaryKey
33 |
34 | [SingleRowAutoIncManage.java](src/main/java/com/aliyun/tablestore/basic/dataManage/SingleRowAutoIncManage.java)
35 |
36 | ### 3. Multi Row Management
37 |
38 | [MultiRowManage.java](src/main/java/com/aliyun/tablestore/basic/dataManage/MultiRowManage.java)
39 |
--------------------------------------------------------------------------------
/basic/Java/DataManage/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.aliyun.tablestore.basic
9 | JavaParent
10 | 0.0.1
11 |
12 |
13 | DataManage
14 | 0.0.1
15 |
16 |
17 |
18 | com.aliyun.tablestore.basic
19 | Common
20 | 0.0.1
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/basic/Java/DataManage/src/main/java/com/aliyun/tablestore/basic/common/Consts.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.basic.common;
2 |
3 | import com.alicloud.openservices.tablestore.model.PrimaryKeyType;
4 |
5 | /**
6 | * @Author wtt
7 | * @create 2019/11/28 4:30 PM
8 | */
9 | public class Consts {
10 | public static String TABLE_NAME = "DataManageTable";
11 | public static String TABLE_NAME_INC = "DataManageTableInc";
12 | public static int TTL = -1;
13 | public static int MAX_VERSION = 10;
14 |
15 | public static String PK1 = "pk1";
16 | public static PrimaryKeyType PK1_TYPE = PrimaryKeyType.INTEGER;
17 | public static String PK2 = "pk2";
18 | public static PrimaryKeyType PK2_TYPE = PrimaryKeyType.STRING;
19 | public static String PK3 = "pk3";
20 | public static PrimaryKeyType PK3_TYPE = PrimaryKeyType.INTEGER;
21 | }
22 |
--------------------------------------------------------------------------------
/basic/Java/DataManage/src/main/java/com/aliyun/tablestore/basic/dataManage/SingleRowAutoIncManage.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.basic.dataManage;
2 |
3 | import com.alicloud.openservices.tablestore.model.*;
4 | import com.aliyun.tablestore.basic.dataManage.base.BaseAutoIncManage;
5 | import com.aliyun.tablestore.basic.dataManage.base.BaseManage;
6 |
7 | import java.util.Arrays;
8 |
9 | import static com.aliyun.tablestore.basic.common.Consts.*;
10 |
11 | /**
12 | * @Author wtt
13 | * @create 2019/11/28 12:19 PM
14 | */
15 | public class SingleRowAutoIncManage extends BaseAutoIncManage {
16 |
17 | public static void main(String[] args) {
18 | SingleRowAutoIncManage manage = new SingleRowAutoIncManage();
19 |
20 | manage.putRow();
21 |
22 | boolean wantDeleteTable = false;
23 | manage.close(wantDeleteTable); // delete table when close
24 | }
25 |
26 | public void putRow() {
27 | PrimaryKey primaryKey = PrimaryKeyBuilder.createPrimaryKeyBuilder()
28 | .addPrimaryKeyColumn(PK1, PrimaryKeyValue.fromLong(1L))
29 | .addPrimaryKeyColumn(PK2, PrimaryKeyValue.fromString("string"))
30 | .addPrimaryKeyColumn(PK3, PrimaryKeyValue.AUTO_INCREMENT) // 自增列的特殊列值
31 | .build();
32 |
33 | RowPutChange rowChange = new RowPutChange(TABLE_NAME_INC, primaryKey);
34 | rowChange.addColumn("string", ColumnValue.fromString("string value"));
35 |
36 | rowChange.setReturnType(ReturnType.RT_PK); // 获取主键自增列实际插入的值
37 |
38 | PutRowRequest putRowRequest = new PutRowRequest(rowChange);
39 |
40 | PutRowResponse putRowResponse = syncClient.putRow(putRowRequest);
41 |
42 | // 自增列的实际存储值只有在返回的Response中才能拿到
43 | PrimaryKey returnPrimaryKey = putRowResponse.getRow().getPrimaryKey();
44 |
45 | System.out.println(String.format("PutRowSuccess: \n\tPrimaryKey: %s",
46 | returnPrimaryKey.toString()));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/basic/Java/GlobalIndexCRD/README.md:
--------------------------------------------------------------------------------
1 | # Configuration
2 | Create a file with name `tablestoreConf.json` in `${user.home}`(For windows: `C:\Documents and Settings\%username%\tablestoreCong.json`, for linux `/home/${username}/tablestoreCong.json`, for mac `/Users/${username}/tablestoreCong.json` )
3 | ```json
4 | {
5 | "endpoint": "*****",
6 | "accessId": "*******",
7 | "accessKey": "*************",
8 | "instanceName": "*****"
9 | }
10 | ```
11 |
12 | # Dependencies
13 | Tablestore java sdk.
14 | ```xml
15 |
16 | com.aliyun.openservices
17 | tablestore
18 | 5.3.0
19 |
20 | ```
21 |
22 | # Source Tree
23 | ```text
24 | .
25 | └── java
26 | └── com
27 | └── aliyun
28 | └── tablestore
29 | └── basic
30 | ├── BaseExample.java # Example base class
31 | ├── GlobalIndexCRDExample.java # Basic operations of Tablestore Global Index :)
32 | ├── common
33 | │ └── Consts.java # Consts
34 | └── model
35 | └── CallDO.java # Domain object
36 | ```
37 |
38 | # Setup environment & Example
39 | Run the main method in class [`GlobalIndexCRDExample`](src/main/java/com/aliyun/tablestore/basic/GlobalIndexCRDExample.java), the table & index would be created, mock data inserted, along with queries.
40 |
41 | ### createTableWithGlobalIndex
42 | create table & global index at the same time
43 | ### createTable & createGlobalIndex
44 | create table & global index independently
45 |
46 | ### listGlobalIndex
47 | list all global indices on a specific table
48 |
49 | ### describeGlobalIndex
50 | describe meta of a global index
51 |
52 | ### queryCalledNumber
53 | query a global index
54 |
55 | ### deleteGlobalIndex
56 | delete a global index
57 |
--------------------------------------------------------------------------------
/basic/Java/GlobalIndexCRD/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.aliyun.tablestore.basic
9 | JavaParent
10 | 0.0.1
11 |
12 |
13 | GlobalIndex-CRD
14 |
15 |
16 |
17 | com.aliyun.tablestore.basic
18 | Common
19 | 0.0.1
20 |
21 |
22 |
--------------------------------------------------------------------------------
/basic/Java/GlobalIndexCRD/src/main/java/com/aliyun/tablestore/basic/BaseExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.basic;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.aliyun.tablestore.basic.common.Config;
5 |
6 | public abstract class BaseExample {
7 |
8 | protected final SyncClient syncClient;
9 |
10 |
11 | public BaseExample(Config config) {
12 | syncClient = config.newClient();
13 | }
14 |
15 | protected abstract void doMain();
16 |
17 | protected void main() {
18 | try {
19 | doMain();
20 | } finally {
21 | syncClient.shutdown();
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/basic/Java/GlobalIndexCRD/src/main/java/com/aliyun/tablestore/basic/common/Consts.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.basic.common;
2 |
3 | /**
4 | * @author Sam
5 | */
6 | public interface Consts {
7 |
8 | String TABLE_NAME = "global_index_example_table";
9 | String INDEX_NAME = "global_index_example_index";
10 |
11 | // pk columns
12 | String CELL_NUMBER = "cell_number";
13 | String START_TIME = "start_time";
14 |
15 | // attribute columns
16 | String CALLED_NUMBER = "called_number";
17 | String DURATION = "duration";
18 | String BASE_STATION_NUMBER = "base_station_number";
19 | }
20 |
--------------------------------------------------------------------------------
/basic/Java/LocalTransaction/README.md:
--------------------------------------------------------------------------------
1 | # Configuration
2 | Create a file with name `tablestoreConf.json` in `${user.home}`(For windows: `C:\Documents and Settings\%username%\tablestoreCong.json`, for linux `/home/${username}/tablestoreCong.json`, for mac `/Users/${username}/tablestoreCong.json` )
3 | ```json
4 | {
5 | "endpoint": "*****",
6 | "accessId": "*******",
7 | "accessKey": "*************",
8 | "instanceName": "*****"
9 | }
10 | ```
11 |
12 | # Dependencies
13 | Tablestore java sdk.
14 | ```xml
15 |
16 | com.aliyun.openservices
17 | tablestore
18 | 5.3.0
19 |
20 | ```
21 |
22 | # Source Tree
23 | ```text
24 | .
25 | ├── README.md
26 | ├── pom.xml
27 | └── src
28 | ├── main
29 | │ └── java
30 | └── test
31 | └── java
32 | └── com
33 | └── aliyun
34 | └── tablestore
35 | └── basic
36 | ├── BaseExample.java
37 | └── LocalTransactionExample.java # examples
38 |
39 |
40 |
41 | ```
42 |
43 | # Setup environment & Example
44 | Run tests in [`LocalTransactionExample`](src/test/java/com/aliyun/tablestore/basic/LocalTransactionExample.java).
45 |
46 | # Examples
47 | 1. testPutMultipleRow: put two row separately in one transaction
48 | 1. testPutRowWithAbortTransaction: put row then abort transaction
49 | 1. testPutRowWithoutTransactionId: put one row A in transaction and put row B with same partition key with row A out of transaction
50 | 1. testBatchWriteRow: two `batchWriteRow` in one transaction
51 | 1. testReadThenWriteWithConcurrentModification: concurrent modification out of transaction
52 |
53 |
--------------------------------------------------------------------------------
/basic/Java/LocalTransaction/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore.basic
8 | JavaParent
9 | 0.0.1
10 |
11 |
12 | com.aliyun.tablestore.basic
13 | LocalTransaction
14 | 0.0.1
15 |
16 |
17 |
18 | com.aliyun.openservices
19 | tablestore
20 | 5.3.0
21 |
22 |
23 | commons-io
24 | commons-io
25 | 2.4
26 |
27 |
28 | com.aliyun.tablestore.basic
29 | Common
30 | 0.0.1
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.apache.maven.plugins
38 | maven-compiler-plugin
39 |
40 | 8
41 | 8
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/basic/Java/LocalTransaction/src/test/java/com/aliyun/tablestore/basic/BaseExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.basic;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.aliyun.tablestore.basic.common.Config;
5 | import org.apache.commons.io.IOUtils;
6 | import org.junit.After;
7 | import org.junit.AfterClass;
8 | import org.junit.Before;
9 | import org.junit.BeforeClass;
10 |
11 | import java.io.Closeable;
12 | import java.io.IOException;
13 |
14 | public abstract class BaseExample {
15 |
16 | protected static Config config;
17 |
18 | protected static SyncClient syncClient;
19 |
20 | @BeforeClass
21 | public static void beforeClass() {
22 | config = Config.newInstance();
23 | syncClient = config.newClient();
24 | }
25 |
26 | @AfterClass
27 | public static void afterClass() {
28 | IOUtils.closeQuietly(syncClient::shutdown);
29 | }
30 |
31 | @Before
32 | public abstract void init();
33 |
34 | @After
35 | public abstract void tearDown();
36 | }
37 |
--------------------------------------------------------------------------------
/basic/Java/README.md:
--------------------------------------------------------------------------------
1 | # 表格存储基本功能使用样例(Java)
2 | # Tablestore Examples of Basic Usage (Java)
3 |
4 | ## 项目列表
5 | 分类 | 功能 | 子项目链接
6 | --- | --- | ---
7 | 数据管理 | 数据管理接口概览 | [DataManage](/basic/Java/DataManage)
8 | 数据管理 | GetRow使用 | [DataManage-GetRow](/basic/Java/DataManage-GetRow)
9 | 二级索引 | 二级索引使用 | [GlobalIndex](/basic/Java/GlobalIndexCRD)
10 | 局部事务 | 局部事务使用 | [LocalTransaction](/basic/Java/LocalTransaction)
11 |
12 |
13 | ## 项目模块
14 | 项目目录为:Java
15 | 项目子模块:(其中Common为公共模块)
16 | ```
17 |
18 | DataManage
19 | GlobalIndexCRD
20 | LocalTransaction
21 | Common
22 | DataManage-GetRow
23 |
24 |
25 | ```
26 |
--------------------------------------------------------------------------------
/basic/Java/TableManage/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | JavaParent
7 | com.aliyun.tablestore.basic
8 | 0.0.1
9 |
10 | 4.0.0
11 |
12 | TableManage
13 |
14 |
15 |
16 | com.aliyun.tablestore.basic
17 | Common
18 | 0.0.1
19 |
20 |
21 |
--------------------------------------------------------------------------------
/basic/Java/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | com.aliyun.tablestore.basic
7 | JavaParent
8 | 0.0.1
9 | pom
10 |
11 |
12 | DataManage
13 | GlobalIndexCRD
14 | LocalTransaction
15 | Common
16 | DataManage-GetRow
17 | TableManage
18 |
19 |
20 |
21 |
22 | com.aliyun.openservices
23 | tablestore
24 | 5.4.0
25 |
26 |
27 | commons-io
28 | commons-io
29 | 2.4
30 |
31 |
32 | junit
33 | junit
34 | 4.12
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-compiler-plugin
44 | 3.8.1
45 |
46 | 1.8
47 | 1.8
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/demos/Canal-press/README.md:
--------------------------------------------------------------------------------
1 | 程序为
2 | 基于 MySQL + Tablestore 分层存储的大规模订单系统系列文章中,canal部分的压测程序。
3 | 程序为 Springboot 服务,通过 Application.java启动服务。服务启动后通过接口完成对应功能。
4 | 压测接口见controller。
5 |
6 | 部署说明
7 | 通过mvn指令打出jar包,假设jar包名为test-1.0-SNAPSHOT,(假设在linux上进行部署),
8 | 通过脚本启动jar包,指令为:
9 | nohup java -jar -Dspring.config.location=application.yml test-1.0-SNAPSHOT.jar &
10 | 其中application.yml与jar包处于同一路径。可以在application.yml中进行数据库配置等。
11 |
12 | 车辆信息压测接口指令如下。carNum为要压入的车辆数,point为每辆车历史记录数。
13 | curl "ip:8082/car/press?carNum=1000&point=10000" -X POST
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/Application.java:
--------------------------------------------------------------------------------
1 | import org.mybatis.spring.annotation.MapperScan;
2 | import org.springframework.boot.SpringApplication;
3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.ComponentScan;
6 | import org.springframework.scheduling.annotation.EnableScheduling;
7 |
8 | @ComponentScan(basePackages={"com.aliyun.tablestore.examples"})
9 | @SpringBootApplication
10 | @EnableAutoConfiguration
11 | @EnableScheduling
12 | public class Application {
13 |
14 | public static void main(String[] args) {
15 | SpringApplication.run(Application.class, args);
16 | }
17 | }
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/com/aliyun/tablestore/examples/bean/Automobile/NextMove.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.bean.Automobile;
2 |
3 |
4 |
5 | public class NextMove {
6 |
7 | private boolean stop = false;
8 |
9 | // 分钟为单位
10 | private int minuteLeft;
11 |
12 | private int direction;
13 |
14 | public boolean isStop() {
15 | return stop;
16 | }
17 |
18 | public void setStop(boolean stop) {
19 | this.stop = stop;
20 | }
21 |
22 | public int getMinuteLeft() {
23 | return minuteLeft;
24 | }
25 |
26 | public void setMinuteLeft(int minuteLeft) {
27 | this.minuteLeft = minuteLeft;
28 | }
29 |
30 | public int getDirection() {
31 | return direction;
32 | }
33 |
34 | public void setDirection(int direction) {
35 | this.direction = direction;
36 | }
37 |
38 | public void passOneMinute() {
39 | minuteLeft--;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/com/aliyun/tablestore/examples/bean/OperationResult.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.bean;
2 |
3 | public class OperationResult {
4 |
5 | private Integer code;
6 | private Object data;
7 |
8 | public static OperationResult toResult(Object data) {
9 | OperationResult res = new OperationResult();
10 | res.setCode(1);
11 | res.setData(data);
12 | return res;
13 | }
14 |
15 | public Integer getCode() {
16 | return code;
17 | }
18 |
19 | public void setCode(Integer code) {
20 | this.code = code;
21 | }
22 |
23 | public Object getData() {
24 | return data;
25 | }
26 |
27 | public void setData(Object data) {
28 | this.data = data;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/com/aliyun/tablestore/examples/config/DataSourceConfig.java:
--------------------------------------------------------------------------------
1 |
2 | package com.aliyun.tablestore.examples.config;
3 |
4 | import org.apache.ibatis.session.SqlSessionFactory;
5 | import org.mybatis.spring.SqlSessionFactoryBean;
6 | import org.mybatis.spring.SqlSessionTemplate;
7 | import org.mybatis.spring.annotation.MapperScan;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.beans.factory.annotation.Value;
10 | import org.springframework.boot.context.properties.ConfigurationProperties;
11 | import org.springframework.boot.jdbc.DataSourceBuilder;
12 | import org.springframework.context.annotation.Bean;
13 | import org.springframework.context.annotation.Configuration;
14 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
15 |
16 | import javax.sql.DataSource;
17 |
18 | @Configuration
19 | @MapperScan(basePackages = "com.aliyun.tablestore.examples.dao.user", sqlSessionTemplateRef = "sqlSessionTemplate")
20 | public class DataSourceConfig {
21 |
22 |
23 | @Value("${mybatis.mapperLocations}")
24 | private String locations;
25 |
26 |
27 | @Bean(name = "dataSource")
28 | @ConfigurationProperties(prefix = "spring.datasource")
29 | public DataSource testDataSource() {
30 | DataSource dataSource=DataSourceBuilder.create()
31 | .type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
32 | return dataSource;
33 | }
34 |
35 | @Bean(name = "sqlSessionFactory")
36 | public SqlSessionFactory testSqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
37 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
38 | bean.setDataSource(dataSource);
39 | bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(locations));
40 |
41 | return bean.getObject();
42 | }
43 |
44 | @Bean(name = "sqlSessionTemplate")
45 | public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("sqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
46 | return new SqlSessionTemplate(sqlSessionFactory);
47 | }
48 | }
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/com/aliyun/tablestore/examples/controller/AutomobileController.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.controller;
2 |
3 | import com.aliyun.tablestore.examples.bean.OperationResult;
4 | import com.aliyun.tablestore.examples.service.AutomobileService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestParam;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | @RestController
12 | @RequestMapping("/car")
13 | public class AutomobileController {
14 |
15 | @Autowired
16 | private AutomobileService automobileService;
17 |
18 | @PostMapping("/press")
19 | public OperationResult press(@RequestParam("carNum") int num,
20 | @RequestParam(value = "point", defaultValue = "300") int point){
21 | automobileService.createTable();
22 | Thread t = new Thread(() -> automobileService.generateData(num, point));
23 | t.start();
24 | return OperationResult.toResult(true);
25 | }
26 |
27 |
28 |
29 | @PostMapping("/prepareTable")
30 | public OperationResult press(){
31 | automobileService.createTable();
32 | return OperationResult.toResult(true);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/com/aliyun/tablestore/examples/controller/CanalController.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.controller;
2 |
3 |
4 | import com.aliyun.tablestore.examples.bean.OperationResult;
5 | import com.aliyun.tablestore.examples.service.CanalService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.PostMapping;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | @RestController
13 | @RequestMapping("/canal")
14 | public class CanalController {
15 |
16 |
17 |
18 | @Autowired
19 | private CanalService canalService;
20 |
21 | @PostMapping("/press")
22 | public OperationResult press(@RequestParam("rps") int rps, @RequestParam("threads") int threads){
23 | canalService.pressForCanal(rps, threads);
24 | return OperationResult.toResult(true);
25 | }
26 |
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/com/aliyun/tablestore/examples/dao/user/AutomobileMapper.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.dao.user;
2 |
3 | import com.aliyun.tablestore.examples.bean.Automobile.AutomobileBean;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import java.util.List;
8 |
9 | @Mapper
10 | public interface AutomobileMapper {
11 |
12 | void batchInsertHis(List list);
13 |
14 | void insert(@Param("item") AutomobileBean bean);
15 |
16 | void createTableIfNotExitsAutoMobile();
17 |
18 | void createTableIfNotExitsHisAutoMobile();
19 | }
20 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/java/com/aliyun/tablestore/examples/dao/user/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.dao.user;
2 |
3 |
4 | import com.aliyun.tablestore.examples.bean.OrderContract;
5 | import org.apache.ibatis.annotations.Mapper;
6 | import org.apache.ibatis.annotations.Param;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * @Author:wjup
12 | * @Date: 2018/9/26 0026
13 | * @Time: 15:20
14 | */
15 | @Mapper
16 | public interface UserMapper {
17 |
18 | void batchInsertCanal(@Param("list") List list);
19 | }
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8082
3 |
4 |
5 |
6 | spring:
7 | datasource:
8 | jdbcUrl:
9 | user:
10 | password:
11 | driverClass: com.mysql.jdbc.Driver
12 |
13 |
14 | mybatis:
15 | mapperLocations: classpath:mapper/*Mapper.xml
16 |
17 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
7 |
8 |
9 |
10 |
11 | logs/example.log
12 | true
13 |
14 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/demos/Canal-press/src/main/resources/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | insert into order_contract_canal2(oId,create_time,pay_time,has_paid,c_id,c_name,p_brand,
8 | p_count,p_id,p_name,p_price,s_id,s_name,total_price)
9 | values
10 |
11 | (#{item.oId},#{item.createTime},#{item.payTime},#{item.hasPaid},#{item.cId},#{item.cName},#{item.pBrand},
12 | #{item.pCount},#{item.pId},#{item.pName},#{item.pPrice},#{item.sId},#{item.sName},#{item.totalPrice})
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/demos/ImChart/README.md:
--------------------------------------------------------------------------------
1 | # Chart Room
2 |
3 | Chart Room (Instant Message) Based On Timeline 2.0.
4 |
5 | ## Configuration
6 |
7 | Create the file tablestoreCong.json in the home path, and config the parameters.
8 | ```
9 | # Linux or mac system: /home/userhome/tablestoreCong.json
10 | # Windows system: C:\Documents and Settings\%userhome%\tablestoreCong.json
11 | {
12 | "endpoint": "http://instanceName.cn-hangzhou.ots.aliyuncs.com",
13 | "accessId": "***********",
14 | "accessKey": "***********************",
15 | "instanceName": "instanceName"
16 | }
17 | ```
18 | - endpoint: The endpoint of instance.
19 | - accessId: The id of AK.
20 | - accessKey: The secret of AK.
21 | - instanceName: The name of Tablestore instance.
22 |
23 |
24 | ## Getting started
25 |
26 | Before start, you should make sure that GlobalIndex service has been opened.
27 |
28 | ### 1. Init tables and indexes
29 |
30 | [InitChartRoomExample.java](src/main/java/com/aliyun/tablestore/example/InitChartRoomExample.java)
31 |
32 | ### 2. Mock user's request
33 |
34 | [ClientRequestExample.java](src/main/java/com/aliyun/tablestore/example/ClientRequestExample.java)
35 |
36 | ### 3. Drop Indexes and Tables
37 |
38 | [ReleaseChartRoomExample.java](src/main/java/com/aliyun/tablestore/example/ReleaseChartRoomExample.java)
39 |
--------------------------------------------------------------------------------
/demos/ImChart/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore.demo
8 | ImChart
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | com.aliyun.openservices
14 | tablestore
15 | 5.0.0
16 |
17 |
18 | commons-io
19 | commons-io
20 | 2.4
21 |
22 |
23 | com.alibaba
24 | fastjson
25 | 1.2.50
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/common/Config.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.common;
2 |
3 | import com.google.gson.Gson;
4 | import org.apache.commons.io.IOUtils;
5 |
6 | import java.io.FileInputStream;
7 | import java.io.InputStream;
8 |
9 | public class Config {
10 |
11 | private String endpoint;
12 | private String accessId;
13 | private String accessKey;
14 | private String instanceName;
15 |
16 | public static Config newInstance(String path) {
17 | try {
18 | InputStream f = new FileInputStream(path);
19 | Gson gson = new Gson();
20 | return gson.fromJson(IOUtils.toString(f), Config.class);
21 | } catch (Exception ex) {
22 | throw new RuntimeException(ex);
23 | }
24 | }
25 |
26 | public String getEndpoint() {
27 | return endpoint;
28 | }
29 |
30 | public void setEndpoint(String endpoint) {
31 | this.endpoint = endpoint;
32 | }
33 |
34 | public String getAccessId() {
35 | return accessId;
36 | }
37 |
38 | public void setAccessId(String accessId) {
39 | this.accessId = accessId;
40 | }
41 |
42 | public String getAccessKey() {
43 | return accessKey;
44 | }
45 |
46 | public void setAccessKey(String accessKey) {
47 | this.accessKey = accessKey;
48 | }
49 |
50 | public String getInstanceName() {
51 | return instanceName;
52 | }
53 |
54 | public void setInstanceName(String instanceName) {
55 | this.instanceName = instanceName;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/common/ExampleCons.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.common;
2 |
3 | public class ExampleCons {
4 | /**
5 | * table name and index name
6 | */
7 | public static String USER_TABLE = "im_user_table";
8 | public static String USER_RELATION_TABLE = "im_user_relation_table";
9 | public static String GROUP_RELATION_TABLE = "im_group_relation_table";
10 | public static String GROUP_RELATION_GLOBAL_INDEX = "im_group_relation_global_index";
11 |
12 | public static String TIMELINE_META_TABLE = "im_timeline_meta_table";
13 | public static String TIMELINE_META_INDEX = "im_timeline_meta_index";
14 | public static String TIMELINE_STORE_TABLE = "im_timeline_store_table";
15 | public static String TIMELINE_STORE_INDEX = "im_timeline_store_index";
16 | public static String TIMELINE_SYNC_TABLE = "im_timeline_sync_table";
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/model/AppMessage.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.model;
2 |
3 | import com.alicloud.openservices.tablestore.timeline.model.TimelineEntry;
4 | import com.alicloud.openservices.tablestore.timeline.model.TimelineMessage;
5 |
6 | public class AppMessage {
7 | private String timelineId;
8 | private long sequenceId;
9 | private TimelineMessage timelineMessage;
10 |
11 | public AppMessage(String timelineId, TimelineEntry timelineEntry) {
12 | this.timelineId = timelineId;
13 | this.sequenceId = timelineEntry.getSequenceID();
14 | this.timelineMessage = timelineEntry.getMessage();
15 | }
16 |
17 | public AppMessage(String timelineId, TimelineMessage timelineMessage) {
18 | this.timelineId = timelineId;
19 | this.timelineMessage = timelineMessage;
20 | }
21 |
22 | public String getTimelineId() {
23 | return timelineId;
24 | }
25 |
26 | public void setTimelineId(String timelineId) {
27 | this.timelineId = timelineId;
28 | }
29 |
30 | public long getSequenceId() {
31 | return sequenceId;
32 | }
33 |
34 | public void setSequenceId(long sequenceId) {
35 | this.sequenceId = sequenceId;
36 | }
37 |
38 | public TimelineMessage getTimelineMessage() {
39 | return timelineMessage;
40 | }
41 |
42 | public void setTimelineMessage(TimelineMessage timelineMessage) {
43 | this.timelineMessage = timelineMessage;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/model/Conversation.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.model;
2 |
3 |
4 | public class Conversation {
5 | private String timelineId;
6 | private TimelineType type;
7 | private User user;
8 | private Group group;
9 |
10 | public Conversation(String timelineId, User user) {
11 | this.timelineId = timelineId;
12 | this.type = TimelineType.SINGLE;
13 | this.user = user;
14 | }
15 |
16 | public Conversation(String timelineId, Group group) {
17 | this.timelineId = timelineId;
18 | this.type = TimelineType.GROUP;
19 | this.group = group;
20 | }
21 |
22 |
23 | public String getTimelineId() {
24 | return timelineId;
25 | }
26 |
27 | public TimelineType getType() {
28 | return type;
29 | }
30 |
31 | public User getUser() {
32 | return user;
33 | }
34 |
35 | public Group getGroup() {
36 | return group;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/model/Group.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.model;
2 |
3 | public class Group {
4 | private String timelineId;
5 | private String groupName;
6 | private long createdTime;
7 |
8 | public Group(String timelineId, String groupName) {
9 | this.timelineId = timelineId;
10 | this.groupName = groupName;
11 | }
12 |
13 | public String getTimelineId() {
14 | return timelineId;
15 | }
16 |
17 | public Group setTimelineId(String timelineId) {
18 | this.timelineId = timelineId;
19 | return this;
20 | }
21 |
22 | public String getGroupName() {
23 | return groupName;
24 | }
25 |
26 | public Group setGroupName(String groupName) {
27 | this.groupName = groupName;
28 | return this;
29 | }
30 |
31 | public long getCreatedTime() {
32 | return createdTime;
33 | }
34 |
35 | public Group setCreatedTime(long createdTime) {
36 | this.createdTime = createdTime;
37 | return this;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/model/Sexuality.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.model;
2 |
3 | public enum Sexuality {
4 | MALE, FEMALE
5 | }
6 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/model/TimelineType.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.model;
2 |
3 | public enum TimelineType {
4 | SINGLE, GROUP
5 | }
6 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/model/User.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.model;
2 |
3 | public class User {
4 | private String userId;
5 | private String userName;
6 | private Sexuality sexuality;
7 |
8 | public String getUserId() {
9 | return userId;
10 | }
11 |
12 | public User setUserId(String userId) {
13 | this.userId = userId;
14 |
15 | return this;
16 | }
17 |
18 | public String getUserName() {
19 | return userName;
20 | }
21 |
22 | public User setUserName(String userName) {
23 | this.userName = userName;
24 |
25 | return this;
26 | }
27 |
28 | public Sexuality getSexuality() {
29 | return sexuality;
30 | }
31 |
32 | public User setSexuality(Sexuality sexuality) {
33 | this.sexuality = sexuality;
34 |
35 | return this;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/service/IMessageService.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.service;
2 |
3 | import com.aliyun.tablestore.chart.model.AppMessage;
4 |
5 | import java.util.List;
6 |
7 | public interface IMessageService {
8 |
9 | /**
10 | * 发送消息后,写入存储库,然后依据会话用户列表写扩散到同步库
11 | *
12 | * 写扩散方式建议用户通过任务队列,做异步的写扩散。
13 | */
14 | public void sendSingleMessage(String friendId, AppMessage message);
15 |
16 | public void sendGroupMessage(AppMessage message, UserService userService);
17 |
18 | /**
19 | * 从同步库获取未读消息,依据lastSequenceId标识已读位置
20 | *
21 | * 在客户端或者应用内将消息按会话分组,统计各会话新的未读消息数,并完成会话未读数的累加。
22 | */
23 | public List fetchSyncMessage(String userId, long lastSequenceId);
24 |
25 | /**
26 | * 从存储库获取消息,通过sequenceId做倒序范围查询;默认返回30条
27 | */
28 | public List fetchConversationMessage(String timelineId, long sequenceId);
29 |
30 | public List searchMessage(String timelineId, String content);
31 | }
32 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/service/IRelationService.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.service;
2 |
3 | public interface IRelationService {
4 |
5 | public void establishFriendship(String userA, String userB, String timelineId);
6 |
7 | public void breakupFriendship(String userA, String userB);
8 |
9 | public void joinGroup(String userId, String groupTimelineId);
10 |
11 | public void leaveGroup(String userId, String groupTimelineId);
12 | }
13 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/service/ITableService.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.service;
2 |
3 | public interface ITableService {
4 |
5 | public void createUserTable();
6 |
7 | public void dropUserTable();
8 |
9 | public void createRelationTables();
10 |
11 | public void dropRelationTables();
12 |
13 | public void createTimelineMetaAndStoreTables();
14 |
15 | public void dropTimelineMetaAndStoreTables();
16 | }
17 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/chart/service/IUserService.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.chart.service;
2 |
3 | import com.aliyun.tablestore.chart.model.Conversation;
4 | import com.aliyun.tablestore.chart.model.Group;
5 | import com.aliyun.tablestore.chart.model.User;
6 |
7 | import java.util.List;
8 |
9 | public interface IUserService {
10 |
11 | public User createUser(User user);
12 |
13 | public User describeUser(String userId);
14 |
15 | public List listGroupUsers(String groupId);
16 |
17 | public String getSingleConversationTimelineId(String mainUser, String subUser);
18 |
19 | public Group describeGroup(String timelineId);
20 |
21 | public Conversation describeConversation(String userId, String timelineId);
22 |
23 | public void createGroupConversation(Group group);
24 |
25 | public void createSingleConversation(String timelineId, User mainUser, User subUser);
26 |
27 | public List listMySingleConversations(String userId);
28 |
29 | public List listMyGroupConversations(String userId);
30 |
31 | public List searchGroupConversation(String groupName);
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/example/BaseExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.aliyun.tablestore.chart.common.Config;
5 |
6 | public abstract class BaseExample {
7 | protected Config config;
8 | protected SyncClient syncClient;
9 | private String pathSeperator = "/";
10 |
11 | public BaseExample() {
12 | String os = System.getProperty("os.name");
13 | if (os.toLowerCase().startsWith("win")) {
14 | pathSeperator = "\\";
15 | }
16 | config = Config.newInstance(System.getProperty("user.home") + pathSeperator + "tablestoreConf.json");
17 |
18 | syncClient = new SyncClient(
19 | config.getEndpoint(),
20 | config.getAccessId(),
21 | config.getAccessKey(),
22 | config.getInstanceName()
23 | );
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/example/InitChartRoomExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.aliyun.tablestore.chart.service.ITableService;
4 | import com.aliyun.tablestore.chart.service.TableService;
5 |
6 | public class InitChartRoomExample extends BaseExample {
7 |
8 | public static void main(String[] args) {
9 | InitChartRoomExample example = new InitChartRoomExample();
10 |
11 | ITableService initTableService = new TableService(example.syncClient);
12 |
13 | initTableService.createUserTable();
14 | System.out.println("[Create Table]: im_user_table");
15 |
16 | initTableService.createRelationTables();
17 | System.out.println("[Create Table]: im_user_relation_table, im_group_relation_table");
18 |
19 | initTableService.createTimelineMetaAndStoreTables();
20 | System.out.println("[Create Table]: im_timeline_meta_table, im_timeline_store_table, im_timeline_sync_table");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/demos/ImChart/src/main/java/com/aliyun/tablestore/example/ReleaseChartRoomExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.aliyun.tablestore.chart.service.ITableService;
4 | import com.aliyun.tablestore.chart.service.TableService;
5 |
6 | public class ReleaseChartRoomExample extends BaseExample {
7 |
8 | public static void main(String[] args) {
9 | ReleaseChartRoomExample example = new ReleaseChartRoomExample();
10 |
11 | ITableService initTableService = new TableService(example.syncClient);
12 |
13 | initTableService.dropUserTable();
14 | System.out.println("[Drop Table]: im_user_table");
15 |
16 | initTableService.dropRelationTables();
17 | System.out.println("[Drop Table]: im_user_relation_table, im_group_relation_table");
18 |
19 | initTableService.dropTimelineMetaAndStoreTables();
20 | System.out.println("[Drop Table]: im_timeline_meta_table, im_timeline_store_table, im_timeline_sync_table");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/demos/MailManagement/README.md:
--------------------------------------------------------------------------------
1 | # MailManagement
2 |
3 | Manage mail meta and data by Timestream of TableStore.
--------------------------------------------------------------------------------
/demos/MailManagement/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore.examples
8 | MailManagement
9 | 1.0-SNAPSHOT
10 |
11 |
12 | UTF-8
13 |
14 |
15 |
16 |
17 | com.aliyun.openservices
18 | tablestore
19 | 4.11.0
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.4
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | maven-compiler-plugin
33 |
34 | 1.8
35 | 1.8
36 | ${project-sourceEncoding}
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/demos/MailManagement/src/main/java/com/aliyun/tablestore/MailManagement.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore;
2 |
3 | public class MailManagement {
4 |
5 | public static void main(String[] args) {
6 | ManageService demo = new ManageService("timestream_mail_meta", "timestream_mail_data");
7 | /**
8 | * init timestream:
9 | * the timestream of mail: meta and track data of each mail;
10 | * */
11 | demo.init();
12 |
13 | /**
14 | * create meta table and data table for mail:
15 | * 1. mailMetaTableName: which stores the mail meta such as mailing id, mail address and mailing destination;
16 | * 2. mailDataTableName: which stores the location data changing with time;
17 | * */
18 | demo.createMailTable();
19 | demo.writeMail();
20 |
21 |
22 | demo.searchMail();
23 | demo.scanMailTrace();
24 |
25 | /**
26 | * delete all the dataTables
27 | * */
28 | demo.deleteMailTable();
29 |
30 | /**
31 | * shut down the connections;
32 | * */
33 | demo.close();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/demos/MailManagement/src/main/java/com/aliyun/tablestore/common/Conf.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import com.google.gson.Gson;
4 | import org.apache.commons.io.IOUtils;
5 |
6 | import java.io.FileInputStream;
7 | import java.io.InputStream;
8 |
9 | public class Conf {
10 |
11 | private String endpoint;
12 | private String accessId;
13 | private String accessKey;
14 | private String instanceName;
15 |
16 | public static Conf newInstance(String path) {
17 | try {
18 | InputStream f = new FileInputStream(path);
19 | Gson gson = new Gson();
20 | return gson.fromJson(IOUtils.toString(f), Conf.class);
21 | } catch (Exception ex) {
22 | throw new RuntimeException(ex);
23 | }
24 | }
25 |
26 | public String getEndpoint() {
27 | return endpoint;
28 | }
29 |
30 | public void setEndpoint(String endpoint) {
31 | this.endpoint = endpoint;
32 | }
33 |
34 | public String getAccessId() {
35 | return accessId;
36 | }
37 |
38 | public void setAccessId(String accessId) {
39 | this.accessId = accessId;
40 | }
41 |
42 | public String getAccessKey() {
43 | return accessKey;
44 | }
45 |
46 | public void setAccessKey(String accessKey) {
47 | this.accessKey = accessKey;
48 | }
49 |
50 | public String getInstanceName() {
51 | return instanceName;
52 | }
53 |
54 | public void setInstanceName(String instanceName) {
55 | this.instanceName = instanceName;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/demos/MailManagement/src/main/java/com/aliyun/tablestore/common/Util.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import java.util.Random;
4 |
5 | public class Util {
6 | public static String getMailRandomLocation() {
7 | return String.format("%f,%f", 30. + new Random().nextDouble() * 10, 120. + new Random().nextDouble() * 10);
8 | }
9 |
10 | public static String formatMId(long index) {
11 | String oId = "" + index;
12 | StringBuilder oIdBuider = new StringBuilder("m");
13 | for (int i = 0; i < 10 - oId.length(); i ++) {
14 | oIdBuider.append("0");
15 | }
16 | oIdBuider.append(oId);
17 | return oIdBuider.toString();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/demos/Orders/README.md:
--------------------------------------------------------------------------------
1 | 程序为
2 | 基于 MySQL + Tablestore 分层存储的大规模订单系统系列文章中 测试代码
3 |
4 | 程序为 Springboot 服务,通过 Application.java启动服务。服务启动后通过接口完成对应功能。
5 | IndexController中接口为使用Tablestore sdk,根据多元索引和二级索引来查询数据,具体功能可以参考各接口注释
6 | TypeController中为MySQL 以及DLA的连通测试接口,订单的压测接口也在TypeController中,具体功能可以参考各接口注释
7 |
8 |
9 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/Application.java:
--------------------------------------------------------------------------------
1 | import org.mybatis.spring.annotation.MapperScan;
2 | import org.springframework.boot.SpringApplication;
3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.ComponentScan;
6 | import org.springframework.scheduling.annotation.EnableScheduling;
7 |
8 | @ComponentScan(basePackages={"com.aliyun.tablestore.examples"})
9 | @SpringBootApplication
10 | @EnableAutoConfiguration
11 | @EnableScheduling
12 | public class Application {
13 |
14 | public static void main(String[] args) {
15 | SpringApplication.run(Application.class, args);
16 | }
17 | }
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/bean/BrandAndPriceRange.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.bean;
2 |
3 | public class BrandAndPriceRange {
4 |
5 | private String brand;
6 | private Double high;
7 | private Double low;
8 |
9 | public String getBrand() {
10 | return brand;
11 | }
12 |
13 | public void setBrand(String brand) {
14 | this.brand = brand;
15 | }
16 |
17 | public Double getHigh() {
18 | return high;
19 | }
20 |
21 | public void setHigh(Double high) {
22 | this.high = high;
23 | }
24 |
25 | public Double getLow() {
26 | return low;
27 | }
28 |
29 | public void setLow(Double low) {
30 | this.low = low;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/bean/ConsumerOrderCount.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.bean;
2 |
3 | public class ConsumerOrderCount {
4 |
5 | private String cId;
6 |
7 | private int count;
8 |
9 | public String getcId() {
10 | return cId;
11 | }
12 |
13 | public void setcId(String cId) {
14 | this.cId = cId;
15 | }
16 |
17 | public int getCount() {
18 | return count;
19 | }
20 |
21 | public void setCount(int count) {
22 | this.count = count;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/bean/ConsumerTradeValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.bean;
2 |
3 | public class ConsumerTradeValue {
4 |
5 | private String cId;
6 | private Double tradeValue;
7 |
8 | public ConsumerTradeValue(String cId, Double tradeValue) {
9 | this.cId = cId;
10 | this.tradeValue = tradeValue;
11 | }
12 |
13 | public String getcId() {
14 | return cId;
15 | }
16 |
17 | public void setcId(String cId) {
18 | this.cId = cId;
19 | }
20 |
21 | public Double getTradeValue() {
22 | return tradeValue;
23 | }
24 |
25 | public void setTradeValue(Double tradeValue) {
26 | this.tradeValue = tradeValue;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/bean/OperationResult.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.bean;
2 |
3 | public class OperationResult {
4 |
5 | private Integer code;
6 | private Object data;
7 |
8 | public static OperationResult toResult(Object data) {
9 | OperationResult res = new OperationResult();
10 | res.setCode(1);
11 | res.setData(data);
12 | return res;
13 | }
14 |
15 | public Integer getCode() {
16 | return code;
17 | }
18 |
19 | public void setCode(Integer code) {
20 | this.code = code;
21 | }
22 |
23 | public Object getData() {
24 | return data;
25 | }
26 |
27 | public void setData(Object data) {
28 | this.data = data;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/config/DLADataSourceConfig.java:
--------------------------------------------------------------------------------
1 |
2 | package com.aliyun.tablestore.examples.config;
3 |
4 | import org.apache.ibatis.session.SqlSessionFactory;
5 | import org.mybatis.spring.SqlSessionFactoryBean;
6 | import org.mybatis.spring.SqlSessionTemplate;
7 | import org.mybatis.spring.annotation.MapperScan;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.beans.factory.annotation.Value;
10 | import org.springframework.boot.context.properties.ConfigurationProperties;
11 | import org.springframework.boot.jdbc.DataSourceBuilder;
12 | import org.springframework.context.annotation.Bean;
13 | import org.springframework.context.annotation.Configuration;
14 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
15 |
16 | import javax.sql.DataSource;
17 |
18 | @Configuration
19 | @MapperScan(basePackages = "com.aliyun.tablestore.examples.dao.dla", sqlSessionTemplateRef = "dlaSqlSessionTemplate")
20 | public class DLADataSourceConfig {
21 |
22 |
23 | @Value("${mybatis.mapperLocations}")
24 | private String locations;
25 |
26 |
27 | @Bean(name = "dlaDataSource")
28 | @ConfigurationProperties(prefix = "spring.dlasource")
29 | public DataSource testDataSource() {
30 | DataSource dataSource=DataSourceBuilder.create()
31 | .type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
32 | return dataSource;
33 | }
34 |
35 | @Bean(name = "dlaSqlSessionFactory")
36 | public SqlSessionFactory testSqlSessionFactory(@Qualifier("dlaDataSource") DataSource dataSource) throws Exception {
37 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
38 | bean.setDataSource(dataSource);
39 | bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(locations));
40 |
41 | return bean.getObject();
42 | }
43 |
44 | @Bean(name = "dlaSqlSessionTemplate")
45 | public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("dlaSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
46 | return new SqlSessionTemplate(sqlSessionFactory);
47 | }
48 | }
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/config/DataSourceConfig.java:
--------------------------------------------------------------------------------
1 |
2 | package com.aliyun.tablestore.examples.config;
3 |
4 | import org.apache.ibatis.session.SqlSessionFactory;
5 | import org.mybatis.spring.SqlSessionFactoryBean;
6 | import org.mybatis.spring.SqlSessionTemplate;
7 | import org.mybatis.spring.annotation.MapperScan;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.beans.factory.annotation.Value;
10 | import org.springframework.boot.context.properties.ConfigurationProperties;
11 | import org.springframework.boot.jdbc.DataSourceBuilder;
12 | import org.springframework.context.annotation.Bean;
13 | import org.springframework.context.annotation.Configuration;
14 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
15 |
16 | import javax.sql.DataSource;
17 |
18 | @Configuration
19 | @MapperScan(basePackages = "com.aliyun.tablestore.examples.dao.user", sqlSessionTemplateRef = "sqlSessionTemplate")
20 | public class DataSourceConfig {
21 |
22 |
23 | @Value("${mybatis.mapperLocations}")
24 | private String locations;
25 |
26 |
27 | @Bean(name = "dataSource")
28 | @ConfigurationProperties(prefix = "spring.datasource")
29 | public DataSource testDataSource() {
30 | DataSource dataSource=DataSourceBuilder.create()
31 | .type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
32 | return dataSource;
33 | }
34 |
35 | @Bean(name = "sqlSessionFactory")
36 | public SqlSessionFactory testSqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
37 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
38 | bean.setDataSource(dataSource);
39 | bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(locations));
40 |
41 | return bean.getObject();
42 | }
43 |
44 | @Bean(name = "sqlSessionTemplate")
45 | public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("sqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
46 | return new SqlSessionTemplate(sqlSessionFactory);
47 | }
48 | }
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/config/SysClientConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.config;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | @Configuration
9 | public class SysClientConfig {
10 |
11 | @Bean
12 | public SyncClient getSysClinet(@Value("${ots.endpoint}") String endpoint, @Value("${ots.accessId}") String accessKeyId,
13 | @Value("${ots.accessKey}") String accessKeySecret, @Value("${ots.instanceName}") String instanceName) {
14 | return new SyncClient(endpoint, accessKeyId, accessKeySecret, instanceName);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/controller/TypeController.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.controller;
2 |
3 | import com.aliyun.tablestore.examples.service.RdsService;
4 | import com.aliyun.tablestore.examples.service.CommonService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Controller;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 |
10 | @Controller
11 | @RequestMapping("/test")
12 | public class TypeController {
13 |
14 | @Autowired
15 | CommonService commonService;
16 | @Autowired
17 | RdsService rdsService;
18 |
19 |
20 | /**
21 | * 测试连接MySQL
22 | */
23 | @GetMapping("/mysql")
24 | public void mysql(){
25 | commonService.testMysql();
26 | }
27 |
28 | /**
29 | * 测试以MySQL方式连接DLA
30 | */
31 | @GetMapping("/dla")
32 | public void dla(){
33 | commonService.testDla();
34 | }
35 |
36 | /**
37 | * 向MySQL表中压入订单单数
38 | */
39 | @GetMapping("/initOrders")
40 | public void initOrders(){
41 | rdsService.initOrders();
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/dao/dla/DLAMapper.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.dao.dla;
2 |
3 | import com.aliyun.tablestore.examples.bean.ConsumerOrderCount;
4 | import org.apache.ibatis.annotations.Mapper;
5 |
6 | import java.util.List;
7 |
8 | @Mapper
9 | public interface DLAMapper {
10 | List getOrderByConsumers();
11 | }
12 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/dao/user/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.dao.user;
2 |
3 |
4 | import com.aliyun.tablestore.examples.bean.OrderContract;
5 | import org.apache.ibatis.annotations.Mapper;
6 | import org.apache.ibatis.annotations.Param;
7 |
8 | import java.util.List;
9 |
10 |
11 | @Mapper
12 | public interface UserMapper {
13 |
14 | Integer count();
15 |
16 | void insert(OrderContract item);
17 |
18 | void batchInsert(@Param("list") List list);
19 | }
--------------------------------------------------------------------------------
/demos/Orders/src/main/java/com/aliyun/tablestore/examples/service/CommonService.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.service;
2 |
3 | import com.aliyun.tablestore.examples.bean.ConsumerOrderCount;
4 | import com.aliyun.tablestore.examples.dao.dla.DLAMapper;
5 | import com.aliyun.tablestore.examples.dao.user.UserMapper;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.List;
10 |
11 | @Service
12 | public class CommonService {
13 |
14 | @Autowired
15 | UserMapper userMapper;
16 |
17 | @Autowired
18 | DLAMapper dLAMapper;
19 |
20 | public void testMysql() {
21 | int c = userMapper.count();
22 | System.out.println("count is:" + c);
23 | }
24 |
25 |
26 | public void testDla() {
27 | List list = dLAMapper.getOrderByConsumers();
28 |
29 | System.out.println("A");
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 |
4 |
5 |
6 | spring:
7 | datasource:
8 | jdbcUrl:
9 | user:
10 | password:
11 | driverClass: com.mysql.jdbc.Driver
12 |
13 | dlasource:
14 | jdbcUrl:
15 | user:
16 | password:
17 | driverClass: com.mysql.jdbc.Driver
18 |
19 |
20 |
21 | mybatis:
22 | mapperLocations: classpath:mapper/*Mapper.xml
23 |
24 |
25 | ots:
26 | endpoint:
27 | accessId:
28 | accessKey:
29 | instanceName:
30 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/resources/mapper/DALMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/demos/Orders/src/main/resources/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | insert into order_contract(oId,create_time,pay_time,has_paid,c_id,c_name,p_brand,
12 | p_count,p_id,p_name,p_price,s_id,s_name,total_price)
13 | values(#{oId},#{createTime},#{payTime},#{hasPaid},#{cId},#{cName},#{pBrand},
14 | #{pCount},#{pId},#{pName},#{pPrice},#{sId},#{sName},#{totalPrice})
15 |
16 |
17 |
18 |
19 |
20 |
21 | insert into order_contract(oId,create_time,pay_time,has_paid,c_id,c_name,p_brand,
22 | p_count,p_id,p_name,p_price,s_id,s_name,total_price)
23 | values
24 |
25 | (#{item.oId},#{item.createTime},#{item.payTime},#{item.hasPaid},#{item.cId},#{item.cName},#{item.pBrand},
26 | #{item.pCount},#{item.pId},#{item.pName},#{item.pPrice},#{item.sId},#{item.sName},#{item.totalPrice})
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/README.md:
--------------------------------------------------------------------------------
1 | # Sharing Car Management
2 |
3 | - Manage sharing car meta and data by Timestream of TableStore.
4 | - Manage car use orders.
5 |
6 | # SampleCode
7 | [SharingCarExample.java](src/main/java/com/aliyun/tablestore/SharingCarExample.java)
8 |
9 | # Class tree
10 | ```
11 | com
12 | └── aliyun
13 | └── tablestore
14 | ├── ApiService.java
15 | ├── SharingCarExample.java
16 | ├── common
17 | │ ├── Conf.java
18 | │ └── Util.java
19 | └── model
20 | ├── Car.java
21 | ├── MonitorPoint.java
22 | ├── Order.java
23 | └── User.java
24 | ```
25 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore.examples
8 | sharing-car-management
9 | 1.0-SNAPSHOT
10 |
11 |
12 | UTF-8
13 |
14 |
15 |
16 |
17 | com.aliyun.openservices
18 | tablestore
19 | 4.11.0
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.4
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | maven-compiler-plugin
33 |
34 | 1.8
35 | 1.8
36 | ${project-sourceEncoding}
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/src/main/java/com/aliyun/tablestore/SharingCarExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore;
2 |
3 | public class SharingCarExample {
4 |
5 | public static void main(String[] args) {
6 | ApiService demo = new ApiService("sharingCarMeta", "sharingCarData");
7 | /**
8 | * init TimeStream and Order Client:
9 | * the TimeStream of sharingCar: meta and monitor data of each sharing car;
10 | * */
11 | demo.init();
12 |
13 | /**
14 | * 1. Create meta table and data table for sharing car by TimeStream;
15 | * 2. Create order table and index by TableStore api;
16 | * */
17 | demo.createShareCarTable();
18 | demo.createOrderTableAndIndex();
19 |
20 |
21 |
22 | demo.insertCarAndMonitor();
23 | demo.insertCarOrder();
24 |
25 |
26 | /**
27 | * Wait for a wile for the sync of index;
28 | * */
29 | demo.waitForSync(30000);
30 |
31 | /**
32 | * 1. Search car by params;
33 | * 2. Search car order;
34 | * 3. Get car monitor within an order;
35 | *
36 | * */
37 | demo.searchCar();
38 | demo.searchOrder();
39 | demo.getOrderMonitor();
40 |
41 | /**
42 | * delete all the tables and index
43 | * */
44 | demo.deleteShareCarTable();
45 | demo.deleteOrderIndexAndTable();
46 |
47 | /**
48 | * shut down the connections;
49 | * */
50 | demo.close();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/src/main/java/com/aliyun/tablestore/common/Conf.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import com.google.gson.Gson;
4 | import org.apache.commons.io.IOUtils;
5 |
6 | import java.io.FileInputStream;
7 | import java.io.InputStream;
8 |
9 | public class Conf {
10 |
11 | private String endpoint;
12 | private String accessId;
13 | private String accessKey;
14 | private String instanceName;
15 |
16 | public static Conf newInstance(String path) {
17 | try {
18 | InputStream f = new FileInputStream(path);
19 | Gson gson = new Gson();
20 | return gson.fromJson(IOUtils.toString(f), Conf.class);
21 | } catch (Exception ex) {
22 | throw new RuntimeException(ex);
23 | }
24 | }
25 |
26 | public String getEndpoint() {
27 | return endpoint;
28 | }
29 |
30 | public void setEndpoint(String endpoint) {
31 | this.endpoint = endpoint;
32 | }
33 |
34 | public String getAccessId() {
35 | return accessId;
36 | }
37 |
38 | public void setAccessId(String accessId) {
39 | this.accessId = accessId;
40 | }
41 |
42 | public String getAccessKey() {
43 | return accessKey;
44 | }
45 |
46 | public void setAccessKey(String accessKey) {
47 | this.accessKey = accessKey;
48 | }
49 |
50 | public String getInstanceName() {
51 | return instanceName;
52 | }
53 |
54 | public void setInstanceName(String instanceName) {
55 | this.instanceName = instanceName;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/src/main/java/com/aliyun/tablestore/common/Util.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import java.util.Random;
4 |
5 | public class Util {
6 | public static String getMailRandomLocation() {
7 | return String.format("%f,%f", 30. + new Random().nextDouble() * 10, 120. + new Random().nextDouble() * 10);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/src/main/java/com/aliyun/tablestore/model/Car.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.model;
2 |
3 | public class Car {
4 | private String carNo;
5 | private String company;
6 | private String province;
7 | private String type;
8 | private String status;
9 | private long seats;
10 | private double remain;
11 | private double expected;
12 | private String location;
13 |
14 |
15 | public String getCarNo() {
16 | return carNo;
17 | }
18 |
19 | public Car setCarNo(String carNo) {
20 | this.carNo = carNo;
21 | return this;
22 | }
23 |
24 | public String getCompany() {
25 | return company;
26 | }
27 |
28 | public Car setCompany(String company) {
29 | this.company = company;
30 | return this;
31 | }
32 |
33 | public String getProvince() {
34 | return province;
35 | }
36 |
37 | public Car setProvince(String province) {
38 | this.province = province;
39 | return this;
40 | }
41 |
42 | public String getType() {
43 | return type;
44 | }
45 |
46 | public Car setType(String type) {
47 | this.type = type;
48 | return this;
49 | }
50 |
51 | public String getStatus() {
52 | return status;
53 | }
54 |
55 | public Car setStatus(String status) {
56 | this.status = status;
57 | return this;
58 | }
59 |
60 | public long getSeats() {
61 | return seats;
62 | }
63 |
64 | public Car setSeats(long seats) {
65 | this.seats = seats;
66 | return this;
67 | }
68 |
69 | public double getRemain() {
70 | return remain;
71 | }
72 |
73 | public Car setRemain(double remain) {
74 | this.remain = remain;
75 | return this;
76 | }
77 |
78 | public double getExpected() {
79 | return expected;
80 | }
81 |
82 | public Car setExpected(double expected) {
83 | this.expected = expected;
84 | return this;
85 | }
86 |
87 | public String getLocation() {
88 | return location;
89 | }
90 |
91 | public Car setLocation(String location) {
92 | this.location = location;
93 | return this;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/src/main/java/com/aliyun/tablestore/model/MonitorPoint.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.model;
2 |
3 | public class MonitorPoint {
4 | private long time;
5 | private String location;
6 | private double speed;
7 | private double remain;
8 | private double expected;
9 | private double total;
10 |
11 | public long getTime() {
12 | return time;
13 | }
14 |
15 | public MonitorPoint setTime(long time) {
16 | this.time = time;
17 | return this;
18 | }
19 |
20 | public String getLocation() {
21 | return location;
22 | }
23 |
24 | public MonitorPoint setLocation(String location) {
25 | this.location = location;
26 | return this;
27 | }
28 |
29 | public double getSpeed() {
30 | return speed;
31 | }
32 |
33 | public MonitorPoint setSpeed(double speed) {
34 | this.speed = speed;
35 | return this;
36 | }
37 |
38 | public double getRemain() {
39 | return remain;
40 | }
41 |
42 | public MonitorPoint setRemain(double remain) {
43 | this.remain = remain;
44 | return this;
45 | }
46 |
47 | public double getExpected() {
48 | return expected;
49 | }
50 |
51 | public MonitorPoint setExpected(double expexted) {
52 | this.expected = expected;
53 | return this;
54 | }
55 |
56 | public double getTotal() {
57 | return total;
58 | }
59 |
60 | public MonitorPoint setTotal(double total) {
61 | this.total = total;
62 | return this;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/demos/SharingCarManagement/src/main/java/com/aliyun/tablestore/model/User.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.model;
2 |
3 | public class User {
4 | private String userName;
5 | private String mobile;
6 |
7 | public String getUserName() {
8 | return userName;
9 | }
10 |
11 | public void setUserName(String userName) {
12 | this.userName = userName;
13 | }
14 |
15 | public String getMobile() {
16 | return mobile;
17 | }
18 |
19 | public void setMobile(String mobile) {
20 | this.mobile = mobile;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore
8 | insurance-policy-management
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | com.aliyun.openservices
14 | tablestore
15 | 5.10.3
16 |
17 |
18 | commons-io
19 | commons-io
20 | 2.4
21 |
22 |
23 | com.fasterxml.jackson.core
24 | jackson-databind
25 | 2.9.8
26 |
27 |
28 | org.apache.commons
29 | commons-lang3
30 | 3.8.1
31 |
32 |
33 | commons-io
34 | commons-io
35 | 2.4
36 | compile
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-compiler-plugin
45 |
46 | 8
47 | 8
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/SharingPowerBankExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore;
2 |
3 | import com.aliyun.tablestore.common.Config;
4 | import com.aliyun.tablestore.utils.*;
5 | import org.checkerframework.checker.units.qual.A;
6 |
7 | import java.util.ArrayList;
8 |
9 | public class SharingPowerBankExample {
10 | public static void main(String[] args) {
11 | //Config参数校验
12 | if(Control.checkParam()){
13 | return;
14 | }
15 |
16 | StaticData.init();
17 |
18 | ApiService apiService = new ApiService();
19 | apiService.clientInit();
20 |
21 | //创建数据表
22 | apiService.prepareTables();//数据表创建不计费,读写数据有一定免费额度
23 | apiService.createSearchIndex();//多元索引创建后即会开始计费
24 |
25 | apiService.writerInit();
26 |
27 | int cabinetProcess = 0 , cabinetTimeProcess = 0 , orderProcess = 0;
28 |
29 | for(int i = 1; i <= Config.CABINET_NUM; i++){
30 | CabinetData cabinetData = CreateData.makeCabinetData();
31 | apiService.cabinetAdd(cabinetData);
32 | cabinetProcess += 1;
33 | if(Control.needWriteCabinetTime(i)) {
34 | ArrayList cabinetTimeDatas = CreateData.makeCabinetTimeData(cabinetData);
35 | for(CabinetTimeData cabinetTimeData : cabinetTimeDatas){
36 | apiService.cabinetTimeAdd(cabinetTimeData);
37 | }
38 | cabinetTimeProcess += cabinetTimeDatas.size();
39 | }
40 | ArrayList orderDatas = CreateData.makeOrderData(cabinetData);
41 | for (OrderData orderData : orderDatas){
42 | apiService.orderAdd(orderData);
43 | }
44 | orderProcess += orderDatas.size();
45 |
46 | //打印部分进度log
47 | if(i == Config.CABINET_NUM/100 || i == Config.CABINET_NUM){
48 | System.out.println(Thread.currentThread()+"[schedule] cabinet write rows: " + cabinetProcess);
49 | System.out.println(Thread.currentThread()+"[schedule] cabinet_time table write rows: " + cabinetTimeProcess);
50 | System.out.println(Thread.currentThread()+"[schedule] order table write rows: " + orderProcess);
51 | }
52 | }
53 | apiService.shutdown();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/common/Config.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import com.alicloud.openservices.tablestore.AsyncClient;
4 | import com.alicloud.openservices.tablestore.SyncClient;
5 |
6 | public class Config {
7 | /**
8 | * 数据表名
9 | */
10 | public static String CABINET_TABLENAME = "cabinet";//元数据表名
11 | public static String ORDER_TALENAME = "order";//订单数据表名
12 | public static String CABINET_TIME_TABLENAME = "cabinet_time";//元数据时序表名
13 |
14 | /**
15 | * 多远索引名
16 | */
17 | public static String CABINET_TABLENAME_INDEX = "cabinet_index";//元数据索引名
18 |
19 |
20 | /**
21 | * 数据规模配置 元数据表行数 = CABINET_NUM , 元数据时序表行数 = CABINET_TIME_NUM * CABINET_TIME_POINTS , 订单数据表行数 = CABINET_NUM * ORDER_PER_CABINET
22 | */
23 | public static long CABINET_NUM = 10000;//元数据表行数
24 | public static long CABINET_TIME_POINTS = 1000;//元数据时序表时间点个数
25 | public static long CABINET_TIME_NUM = 100;//跟踪的机柜数量
26 | public static long ORDER_PER_CABINET = 5;//每台机柜产生订单的个数
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/common/TablestoreConf.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import com.google.gson.Gson;
4 | import org.apache.commons.io.IOUtils;
5 | import java.io.FileInputStream;
6 | import java.io.InputStream;
7 |
8 | /**
9 | * 加载本地文件中的endpoint ,ak ,isntanceName配置
10 | */
11 | public class TablestoreConf {
12 | private String endpoint;
13 | private String accessId;
14 | private String accessKey;
15 | private String instanceName;
16 |
17 | public static TablestoreConf newInstance(String path) {
18 | try {
19 | InputStream f = new FileInputStream(path);
20 | Gson gson = new Gson();
21 | return gson.fromJson(IOUtils.toString(f), TablestoreConf.class);
22 | } catch (Exception ex) {
23 | throw new RuntimeException(ex);
24 | }
25 | }
26 |
27 | public String getEndpoint() {
28 | return endpoint;
29 | }
30 |
31 | public void setEndpoint(String endpoint) {
32 | this.endpoint = endpoint;
33 | }
34 |
35 | public String getAccessId() {
36 | return accessId;
37 | }
38 |
39 | public void setAccessId(String accessId) {
40 | this.accessId = accessId;
41 | }
42 |
43 | public String getAccessKey() {
44 | return accessKey;
45 | }
46 |
47 | public void setAccessKey(String accessKey) {
48 | this.accessKey = accessKey;
49 | }
50 |
51 | public String getInstanceName() {
52 | return instanceName;
53 | }
54 |
55 | public void setInstanceName(String instanceName) {
56 | this.instanceName = instanceName;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/utils/CabinetGeo.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.utils;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | * 地理位置信息。省份,地理位置,城市列表。用于模拟机柜地理位置信息。
7 | */
8 | public class CabinetGeo {
9 |
10 | private String province;
11 | private String geo;
12 | private ArrayList citys;
13 |
14 | public CabinetGeo(String province,String geo,ArrayList citys){
15 | this.province = province;
16 | this.geo = geo;
17 | this.citys = citys;
18 | }
19 |
20 | public String getProvince() {
21 | return province;
22 | }
23 |
24 | public void setProvince(String province) {
25 | this.province = province;
26 | }
27 |
28 | public String getGeo() {
29 | return geo;
30 | }
31 |
32 | public void setGeo(String geo) {
33 | this.geo = geo;
34 | }
35 |
36 | public ArrayList getCitys() {
37 | return citys;
38 | }
39 |
40 | public void setCitys(ArrayList citys) {
41 | this.citys = citys;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/utils/CabinetInfo.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.utils;
2 |
3 | /**
4 | * 品牌、型号、槽位、时价信息。用于模拟机柜元数据信息
5 | */
6 | public class CabinetInfo {
7 | public String brand;
8 | public String ID;
9 | public long size;
10 | public double pricePerHour;
11 |
12 | public CabinetInfo(String brand, String ID, long size, double pricePerHour) {
13 | this.brand = brand;
14 | this.ID = ID;
15 | this.size = size;
16 | this.pricePerHour = pricePerHour;
17 | }
18 |
19 | public String getBrand() {
20 | return brand;
21 | }
22 |
23 | public void setBrand(String brand) {
24 | this.brand = brand;
25 | }
26 |
27 | public String getID() {
28 | return ID;
29 | }
30 |
31 | public void setID(String ID) {
32 | this.ID = ID;
33 | }
34 |
35 | public long getSize() {
36 | return size;
37 | }
38 |
39 | public void setSize(long size) {
40 | this.size = size;
41 | }
42 |
43 | public double getPricePerHour() {
44 | return pricePerHour;
45 | }
46 |
47 | public void setPricePerHour(double pricePerHour) {
48 | this.pricePerHour = pricePerHour;
49 | }
50 | }
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/utils/CabinetTimeData.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.utils;
2 |
3 | /**
4 | * 临时存储模拟数据,元数据时序数据
5 | */
6 | public class CabinetTimeData {
7 |
8 | public CabinetData cabinetData;
9 | public long cabinetStateTimestamp;
10 |
11 | public CabinetTimeData(CabinetData cabinetData, long cabinetStateTimestamp) {
12 | this.cabinetData = cabinetData;
13 | this.cabinetStateTimestamp = cabinetStateTimestamp;
14 | }
15 |
16 |
17 | public CabinetTimeData(){
18 |
19 | }
20 |
21 | public CabinetData getCabinetData() {
22 | return cabinetData;
23 | }
24 |
25 | public void setCabinetData(CabinetData cabinetData) {
26 | this.cabinetData = cabinetData;
27 | }
28 |
29 | public long getCabinetStateTimestamp() {
30 | return cabinetStateTimestamp;
31 | }
32 |
33 | public void setCabinetStateTimestamp(long cabinetStateTimestamp) {
34 | this.cabinetStateTimestamp = cabinetStateTimestamp;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/utils/Control.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.utils;
2 |
3 | import com.aliyun.tablestore.common.Config;
4 |
5 | public class Control {
6 | public static boolean checkParam(){
7 | if(Config.CABINET_NUM<0||Config.CABINET_TIME_NUM<0||Config.ORDER_PER_CABINET<0||Config.CABINET_TIME_POINTS<0){
8 | System.err.println("[err msg]:cabinet_num,cabinet_time_num,order_per_cabinet,cabinet_time_points must greater than 0!");
9 | return true;
10 | }
11 | if(Config.CABINET_NUM < Config.CABINET_TIME_NUM * 2){
12 | System.err.println("[err msg]:cabinet_num must greater or equal double cabinet_time_num");
13 | return true;
14 | }
15 | return false;
16 | }
17 |
18 | public static boolean needWriteCabinetTime(int cabinet_size) {
19 | if(cabinet_size%((Config.CABINET_NUM - (Config.CABINET_NUM%Config.CABINET_TIME_NUM))/Config.CABINET_TIME_NUM) == 0){
20 | return true;
21 | }
22 | return false;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/demos/SharingPowerBank/src/main/java/com/aliyun/tablestore/utils/Md5Utils.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.utils;
2 |
3 | import java.math.BigInteger;
4 | import java.security.MessageDigest;
5 | import java.security.NoSuchAlgorithmException;
6 |
7 | public class Md5Utils {
8 | public static String stringToMD5(String plainText) {
9 | byte[] secretBytes = null;
10 | try {
11 | secretBytes = MessageDigest.getInstance("md5").digest(
12 | plainText.getBytes());
13 | } catch (NoSuchAlgorithmException e) {
14 | throw new RuntimeException();
15 | }
16 | String md5code = new BigInteger(1, secretBytes).toString(16);
17 | for (int i = 0; i < 32 - md5code.length(); i++) {
18 | md5code = "0" + md5code;
19 | }
20 | return md5code;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/demos/SportTrack/README.md:
--------------------------------------------------------------------------------
1 | ## Sport Track
2 | Store and query sport track、targetNearby by Tablestore.
3 |
4 | ## SampleCode
5 | ### 1. Create TableStore timestream db
6 |
7 | [CreateStoreExample.java](src/main/java/com/aliyun/tablestore/example/CreateStoreExample.java)
8 |
9 | ### 2. Upload sport track
10 |
11 | [UploadSportTrackExample.java](src/main/java/com/aliyun/tablestore/example/UploadSportTrackExample.java)
12 |
13 | ### 3. Sport track qeury example
14 |
15 | [SportTrackQeuryExample.java](src/main/java/com/aliyun/tablestore/example/SportTrackQeuryExample.java)
16 |
17 | ### 4. targetNearby example
18 |
19 | [TargetNearbyExample.java](src/main/java/com/aliyun/tablestore/example/TargetNearbyExample.java)
20 |
--------------------------------------------------------------------------------
/demos/SportTrack/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore
8 | SportTrack
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 1.8
13 | 1.8
14 | 1.8
15 | UTF-8
16 | UTF-8
17 |
18 |
19 |
20 |
21 |
22 | com.aliyun.openservices
23 | tablestore
24 | 4.11.0
25 |
26 |
27 | commons-io
28 | commons-io
29 | 2.4
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/example/CreateStoreExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.aliyun.tablestore.example.common.SportTrackExample;
4 |
5 | public class CreateStoreExample extends SportTrackExample {
6 | /**
7 | * we must create store before we can use it.
8 | *
9 | * @throws Exception
10 | */
11 | public void createStore() {
12 | sportTrack.createTable();
13 | }
14 |
15 | public static void main(String[] args) {
16 | CreateStoreExample example = new CreateStoreExample();
17 | example.createStore();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/example/SportTrackQeuryExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.aliyun.tablestore.sporttrack.TablestoreTrackReader;
4 | import com.aliyun.tablestore.sporttrack.model.SportObject;
5 | import com.aliyun.tablestore.sporttrack.model.SportObjectType;
6 | import com.aliyun.tablestore.example.common.SportTrackExample;
7 |
8 |
9 | public class SportTrackQeuryExample extends SportTrackExample {
10 | private TablestoreTrackReader reader;
11 |
12 | public SportTrackQeuryExample() {
13 | reader = new TablestoreTrackReader(sportTrack);
14 | }
15 |
16 | public static void main(String[] args) {
17 | SportTrackQeuryExample example = new SportTrackQeuryExample();
18 |
19 | example.listTrackMeta();
20 | example.getTrackData();
21 | }
22 |
23 | public void listTrackMeta() {
24 | SportObject object = mockSportObject(SportObjectType.trackOrder);
25 | reader.listTrackMeta(object);
26 | }
27 |
28 | public void getTrackData() {
29 | SportObject object = mockSportObject(SportObjectType.trackOrder);
30 | reader.getTrackData(object);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/example/common/SportTrackExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.common;
2 |
3 | import com.aliyun.tablestore.sporttrack.TablestoreSportTrackConfig;
4 | import com.aliyun.tablestore.sporttrack.TablestoreTrack;
5 | import com.aliyun.tablestore.sporttrack.model.*;
6 |
7 | public class SportTrackExample {
8 | private String pathSeperator = "/";
9 | private TablestoreConf conf;
10 | final String metaTableName = "sporttrack_meta";
11 | final String dataTableName = "sporttrack_data";
12 |
13 | protected TablestoreTrack sportTrack;
14 |
15 | public SportTrackExample() {
16 | String os = System.getProperty("os.name");
17 | if (os.toLowerCase().startsWith("win")) {
18 | pathSeperator = "\\";
19 | }
20 | conf = TablestoreConf.newInstance(System.getProperty("user.home") + pathSeperator + "tablestoreConf.json");
21 |
22 | String endPoint = conf.getEndpoint();
23 | String accessId = conf.getAccessId();
24 | String accessKey = conf.getAccessKey();
25 | String instanceName = conf.getInstanceName();
26 |
27 | TablestoreSportTrackConfig config = new TablestoreSportTrackConfig(endPoint, accessId, accessKey, instanceName, metaTableName, dataTableName);
28 | sportTrack = new TablestoreTrack(config);
29 | }
30 |
31 |
32 | protected SportObject mockSportObject(String sportObjectType) {
33 | SportObject object = new SportObject();
34 | object.setObjectName("mock_app_uid");
35 | object.setObjectId("mock_device_id");
36 | object.setSportObjectType(sportObjectType);
37 |
38 | return object;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/example/common/TablestoreConf.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.common;
2 |
3 | import com.google.gson.Gson;
4 |
5 | import java.io.FileInputStream;
6 | import java.io.InputStream;
7 |
8 | import org.apache.commons.io.IOUtils;
9 |
10 | public class TablestoreConf {
11 |
12 | private String endpoint;
13 | private String accessId;
14 | private String accessKey;
15 | private String instanceName;
16 |
17 | public static TablestoreConf newInstance(String path) {
18 | try {
19 | InputStream f = new FileInputStream(path);
20 | Gson gson = new Gson();
21 | return gson.fromJson(IOUtils.toString(f), TablestoreConf.class);
22 | } catch (Exception ex) {
23 | throw new RuntimeException(ex);
24 | }
25 | }
26 |
27 | public String getEndpoint() {
28 | return endpoint;
29 | }
30 |
31 | public void setEndpoint(String endpoint) {
32 | this.endpoint = endpoint;
33 | }
34 |
35 | public String getAccessId() {
36 | return accessId;
37 | }
38 |
39 | public void setAccessId(String accessId) {
40 | this.accessId = accessId;
41 | }
42 |
43 | public String getAccessKey() {
44 | return accessKey;
45 | }
46 |
47 | public void setAccessKey(String accessKey) {
48 | this.accessKey = accessKey;
49 | }
50 |
51 | public String getInstanceName() {
52 | return instanceName;
53 | }
54 |
55 | public void setInstanceName(String instanceName) {
56 | this.instanceName = instanceName;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/ITrackStore.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack;
2 |
3 | public interface ITrackStore {
4 | void createTable();
5 | }
6 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/ITrackWriter.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack;
2 |
3 | import com.aliyun.tablestore.sporttrack.model.SportObject;
4 | import com.aliyun.tablestore.sporttrack.model.SportTrackMeta;
5 | import com.aliyun.tablestore.sporttrack.model.SportTrackOrder;
6 | import com.aliyun.tablestore.sporttrack.model.TrackPosition;
7 |
8 | import java.util.List;
9 |
10 | public interface ITrackWriter {
11 |
12 | /**
13 | * 写入位置点meta信息,包括附近的人、附近的跑步路线
14 | * @param sportObject
15 | * @param sportTrackMeta
16 | */
17 | void writeTrackMeta(SportObject sportObject, SportTrackMeta sportTrackMeta);
18 |
19 | /**
20 | * 写入跑步、骑行等运动记录信息
21 | * @param sportObject
22 | * @param sportTrackOrder
23 | */
24 | void writeTrackOrderMeta(SportObject sportObject, SportTrackOrder sportTrackOrder);
25 |
26 | /**
27 | * 写入轨迹点信息
28 | * @param sportObject
29 | * @param positions
30 | */
31 | void writeTrackPosition(SportObject sportObject, List positions);
32 | }
33 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/ITrackerReader.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack;
2 |
3 | import com.aliyun.tablestore.sporttrack.model.Position;
4 | import com.aliyun.tablestore.sporttrack.model.SportObject;
5 |
6 | public interface ITrackerReader {
7 |
8 | /**
9 | * 获取所有的跑步记录
10 | * @param sportObject
11 | */
12 | void listTrackMeta(SportObject sportObject);
13 |
14 | /**
15 | * 获取一次跑步、骑行的轨迹点
16 | * @param sportObject
17 | */
18 | void getTrackData(SportObject sportObject);
19 |
20 | /**
21 | * 获取distanceInMeter范围内,附近的人、附近的跑步路线 信息,根据距离排序
22 | * @param targetType
23 | * @param centerPoint
24 | * @param distanceInMeter
25 | */
26 | void listTargetNearbyOrderbyDistance(String targetType, Position centerPoint, int distanceInMeter);
27 | }
28 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/TablestoreSportTrackConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack;
2 |
3 | public class TablestoreSportTrackConfig {
4 | private String accessId;
5 | private String accessKey;
6 | private String endPoint;
7 | private String instanceName;
8 |
9 | private String trackMetaTableName;
10 | private String trackDataTableName;
11 |
12 | public TablestoreSportTrackConfig(String endPoint, String accessId, String accessKey, String instanceName,
13 | String trackMetaTableName, String trackDataTableName) {
14 | this.endPoint = endPoint;
15 | this.accessId = accessId;
16 | this.accessKey = accessKey;
17 | this.instanceName = instanceName;
18 | this.trackMetaTableName = trackMetaTableName;
19 | this.trackDataTableName = trackDataTableName;
20 | }
21 |
22 |
23 | public String getAccessId() {
24 | return accessId;
25 | }
26 |
27 | public String getAccessKey() {
28 | return accessKey;
29 | }
30 |
31 | public String getEndPoint() {
32 | return endPoint;
33 | }
34 |
35 | public String getInstanceName() {
36 | return instanceName;
37 | }
38 |
39 | public String getTrackMetaTableName() {
40 | return trackMetaTableName;
41 | }
42 |
43 | public String getTrackDataTableName() {
44 | return trackDataTableName;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/TablestoreTrack.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack;
2 |
3 | import com.alicloud.openservices.tablestore.AsyncClient;
4 | import com.alicloud.openservices.tablestore.SyncClient;
5 | import com.alicloud.openservices.tablestore.timestream.TimestreamDBClient;
6 | import com.alicloud.openservices.tablestore.timestream.TimestreamDBConfiguration;
7 | import com.alicloud.openservices.tablestore.timestream.model.AttributeIndexSchema;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class TablestoreTrack implements ITrackStore {
13 | public TimestreamDBClient timestreamClient;
14 | public SyncClient client;
15 | public TablestoreSportTrackConfig config;
16 |
17 |
18 | public TablestoreTrack(TablestoreSportTrackConfig config) {
19 | this.config = config;
20 | AsyncClient asyncClient = new AsyncClient(config.getEndPoint(), config.getAccessId(), config.getAccessKey(), config.getInstanceName());
21 | TimestreamDBConfiguration conf = new TimestreamDBConfiguration(config.getTrackMetaTableName());
22 | conf.setDumpMeta(false);
23 | timestreamClient = new TimestreamDBClient(asyncClient, conf);
24 |
25 | client = new SyncClient(config.getEndPoint(), config.getAccessId(), config.getAccessKey(), config.getInstanceName());
26 | }
27 |
28 | @Override
29 | public void createTable() {
30 | List indexSchemas = new ArrayList();
31 | indexSchemas.add(new AttributeIndexSchema("timestamp", AttributeIndexSchema.Type.LONG));
32 | indexSchemas.add(new AttributeIndexSchema("location", AttributeIndexSchema.Type.GEO_POINT));
33 | indexSchemas.add(new AttributeIndexSchema("starttime", AttributeIndexSchema.Type.LONG));
34 | indexSchemas.add(new AttributeIndexSchema("endtime", AttributeIndexSchema.Type.LONG));
35 |
36 | //create meta table
37 | timestreamClient.createMetaTable(indexSchemas);
38 | //create data table
39 | timestreamClient.createDataTable(config.getTrackDataTableName());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/consts/Constants.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.consts;
2 |
3 | public class Constants {
4 | public final static String PRIMARY_KEY_OBJECTID = "objectID";
5 | public final static String PRIMARY_KEY_OBJECTTYPE = "objectType";
6 | public final static String ATTRIBUTE_COL_GEO = "location";
7 | public final static String ATTRIBUTE_COL_DISTANCE= "distance";
8 | public final static String ATTRIBUTE_COL_STARTTIME = "starttime";
9 | }
10 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/Coords.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class Coords {
4 | private double longitude;
5 |
6 | private double latitude;
7 |
8 | public double getLongitude() {
9 | return longitude;
10 | }
11 |
12 | public void setLongitude(double longitude) {
13 | this.longitude = longitude;
14 | }
15 |
16 | public double getLatitude() {
17 | return latitude;
18 | }
19 |
20 | public void setLatitude(double latitude) {
21 | this.latitude = latitude;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/Position.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class Position {
4 | private long timestamp;
5 |
6 | private Coords coords;
7 |
8 | public long getTimestamp() {
9 | return timestamp;
10 | }
11 |
12 | public void setTimestamp(long timestamp) {
13 | this.timestamp = timestamp;
14 | }
15 |
16 | public Coords getCoords() {
17 | return coords;
18 | }
19 |
20 | public void setCoords(Coords coords) {
21 | this.coords = coords;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/SportObject.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 |
4 | public class SportObject {
5 | private String objectName;
6 |
7 | private String objectId;
8 |
9 | private String sportObjectType;
10 |
11 |
12 | public String getObjectName() {
13 | return objectName;
14 | }
15 |
16 | public void setObjectName(String objectName) {
17 | this.objectName = objectName;
18 | }
19 |
20 | public String getObjectId() {
21 | return objectId;
22 | }
23 |
24 | public void setObjectId(String objectId) {
25 | this.objectId = objectId;
26 | }
27 |
28 | public String getSportObjectType() {
29 | return sportObjectType;
30 | }
31 |
32 | public void setSportObjectType(String sportObjectType) {
33 | this.sportObjectType = sportObjectType;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/SportObjectType.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class SportObjectType {
4 | public final static String trackOrder = "trackOrder";
5 |
6 | public final static String device = "device";
7 | }
8 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/SportTrackMeta.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class SportTrackMeta {
4 | private String targetNearbyType;
5 |
6 | private long timestamp;
7 |
8 | private String location;
9 |
10 | public String getTargetNearbyType() {
11 | return targetNearbyType;
12 | }
13 |
14 | public void setTargetNearbyType(String targetNearbyType) {
15 | this.targetNearbyType = targetNearbyType;
16 | }
17 |
18 | public long getTimestamp() {
19 | return timestamp;
20 | }
21 |
22 | public void setTimestamp(long timestamp) {
23 | this.timestamp = timestamp;
24 | }
25 |
26 | public String getLocation() {
27 | return location;
28 | }
29 |
30 | public void setLocation(String location) {
31 | this.location = location;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/SportTrackOrder.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class SportTrackOrder {
4 |
5 | private String sportTrackType;
6 |
7 | private long startTime;
8 |
9 | private long endTime;
10 |
11 | private int distance;
12 |
13 | public String getSportTrackType() {
14 | return sportTrackType;
15 | }
16 |
17 | public void setSportTrackType(String sportTrackType) {
18 | this.sportTrackType = sportTrackType;
19 | }
20 |
21 | public long getStartTime() {
22 | return startTime;
23 | }
24 |
25 | public void setStartTime(long startTime) {
26 | this.startTime = startTime;
27 | }
28 |
29 | public long getEndTime() {
30 | return endTime;
31 | }
32 |
33 | public void setEndTime(long endTime) {
34 | this.endTime = endTime;
35 | }
36 |
37 | public int getDistance() {
38 | return distance;
39 | }
40 |
41 | public void setDistance(int distance) {
42 | this.distance = distance;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/SportType.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class SportType {
4 | public final static String RUN = "run";
5 | public final static String RIDING = "riding";
6 | public final static String WALK = "walk";
7 | }
8 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/TargetNearbyEntity.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class TargetNearbyEntity {
4 | private Position position;
5 |
6 | private SportObject sportObject;
7 |
8 | private int distanceInMeterBetweenCenter;
9 |
10 | public Position getPosition() {
11 | return position;
12 | }
13 |
14 | public void setPosition(Position position) {
15 | this.position = position;
16 | }
17 |
18 | public SportObject getSportObject() {
19 | return sportObject;
20 | }
21 |
22 | public void setSportObject(SportObject sportObject) {
23 | this.sportObject = sportObject;
24 | }
25 |
26 | public int getDistanceInMeterBetweenCenter() {
27 | return distanceInMeterBetweenCenter;
28 | }
29 |
30 | public void setDistanceInMeterBetweenCenter(int distanceInMeterBetweenCenter) {
31 | this.distanceInMeterBetweenCenter = distanceInMeterBetweenCenter;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/TargetNearbyType.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class TargetNearbyType {
4 | public final static String PEOPLE = "people";
5 | public final static String RIDING_ROUTE = "riding_route";
6 | public final static String SPORTS_GROUP = "sports_group";
7 | }
8 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/model/TrackPosition.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.model;
2 |
3 | public class TrackPosition extends Position {
4 | private int accuracy;
5 |
6 | private int altitude;
7 |
8 | private int altitudeAccuracy;
9 |
10 | private int speed;
11 |
12 | public int getAccuracy() {
13 | return accuracy;
14 | }
15 |
16 | public void setAccuracy(int accuracy) {
17 | this.accuracy = accuracy;
18 | }
19 |
20 | public int getAltitude() {
21 | return altitude;
22 | }
23 |
24 | public void setAltitude(int altitude) {
25 | this.altitude = altitude;
26 | }
27 |
28 | public int getAltitudeAccuracy() {
29 | return altitudeAccuracy;
30 | }
31 |
32 | public void setAltitudeAccuracy(int altitudeAccuracy) {
33 | this.altitudeAccuracy = altitudeAccuracy;
34 | }
35 |
36 | public int getSpeed() {
37 | return speed;
38 | }
39 |
40 | public void setSpeed(int speed) {
41 | this.speed = speed;
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/utils/DistanceUtil.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.utils;
2 |
3 | public class DistanceUtil {
4 | private final static double EARTH_RADIUS = 6378137;
5 |
6 | private static double rad(double d) {
7 | return d * Math.PI / 180.0;
8 | }
9 |
10 | /**
11 | * 根据两点间经纬度坐标(double值),计算两点间距离,单位为米
12 | */
13 | public static double distance(double lat1, double lng1, double lat2, double lng2) {
14 | double radLat1 = rad(lat1);
15 | double radLat2 = rad(lat2);
16 | double a = radLat1 - radLat2;
17 | double b = rad(lng1) - rad(lng2);
18 | double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
19 | Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
20 | s = s * EARTH_RADIUS;
21 | s = Math.round(s * 10000) / 10000;
22 | return s;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/demos/SportTrack/src/main/java/com/aliyun/tablestore/sporttrack/utils/Md5Util.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.sporttrack.utils;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | public class Md5Util {
7 | // 计算字符串的MD5
8 | public static String computeMD5(String source) {
9 | try {
10 | MessageDigest md = MessageDigest.getInstance("MD5");
11 | md.update(source.getBytes());
12 | byte b[] = md.digest();
13 |
14 | int i;
15 |
16 | StringBuffer buf = new StringBuffer("");
17 | for (int offset = 0; offset < b.length; offset++) {
18 | i = b[offset];
19 | if (i < 0)
20 | i += 256;
21 | if (i < 16)
22 | buf.append("0");
23 | buf.append(Integer.toHexString(i));
24 | }
25 | // 32位加密
26 | return buf.toString();
27 | // 16位的加密
28 | // return buf.toString().substring(8, 24);
29 | } catch (NoSuchAlgorithmException e) {
30 | e.printStackTrace();
31 | return null;
32 | }
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/demos/StreamCompute/.gitignore:
--------------------------------------------------------------------------------
1 | tagrte
2 | .idea
3 | log*
4 |
--------------------------------------------------------------------------------
/demos/StreamCompute/README.md:
--------------------------------------------------------------------------------
1 | # Stream Compute Example
2 |
3 | ### Step
4 |
5 | ```
6 | 1. build source code
7 | > mvn install
8 |
9 | 2. configuration config
10 | > vim ~/tablestoreConf.json
11 |
12 | 3. Prepare the tables and blink task
13 |
14 | 4. mock data
15 | > ./bin/mock_order_generator
16 |
17 | 5. get screen data
18 | > ./bind/data_show_screen
19 | ```
--------------------------------------------------------------------------------
/demos/StreamCompute/bin/data_show_screen:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | bin=`dirname "$0"`
4 | cd "${bin}/.."
5 |
6 | home=`pwd`
7 | CLASSPATH="${home}/libs"
8 |
9 | LOG="${home}/log"
10 | CONF="${home}/conf"
11 |
12 | for f in $CLASSPATH/*.jar;
13 | do CLASSPATH=${CLASSPATH}:$f;
14 | done
15 | CLASSPATH=${home}/conf/:${CLASSPATH};
16 |
17 | if [ ! -x "$LOG" ];
18 | then
19 | mkdir "$LOG"
20 | fi
21 |
22 | java -classpath ".:${CLASSPATH}" -Xms1g -Xmx2g com.aliyun.tablestore.examples.ReadData "$@"
--------------------------------------------------------------------------------
/demos/StreamCompute/bin/mock_order_generator:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | bin=`dirname "$0"`
4 | cd "${bin}/.."
5 |
6 | home=`pwd`
7 | CLASSPATH="${home}/libs"
8 |
9 | LOG="${home}/log"
10 | CONF="${home}/conf"
11 |
12 | for f in $CLASSPATH/*.jar;
13 | do CLASSPATH=${CLASSPATH}:$f;
14 | done
15 | CLASSPATH=${home}/conf/:${CLASSPATH};
16 |
17 | if [ ! -x "$LOG" ];
18 | then
19 | mkdir "$LOG"
20 | fi
21 |
22 | java -classpath ".:${CLASSPATH}" -Xms1g -Xmx2g com.aliyun.tablestore.examples.WriteData "$@"
--------------------------------------------------------------------------------
/demos/StreamCompute/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore.examples
8 | stream-compute
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 |
14 | com.aliyun.openservices
15 | tablestore
16 | 4.11.2
17 |
18 |
19 | com.google.code.gson
20 | gson
21 | 2.8.2
22 |
23 |
24 | joda-time
25 | joda-time
26 | 2.9.1
27 |
28 |
29 |
30 |
31 |
32 |
33 | maven-assembly-plugin
34 |
35 |
36 | src/main/assembly/package.xml
37 |
38 |
39 |
40 |
41 |
42 | dwzip
43 | package
44 |
45 | single
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/demos/StreamCompute/src/main/assembly/package.xml:
--------------------------------------------------------------------------------
1 |
5 | release
6 |
7 | tar.gz
8 |
9 | false
10 |
11 |
12 | false
13 | libs
14 | runtime
15 |
16 |
17 |
18 |
19 | ./conf/
20 |
21 | **/**
22 |
23 | conf
24 |
25 |
26 | ./bin/
27 |
28 | **/**
29 |
30 | 0777
31 | bin
32 |
33 |
34 | ./libs/
35 |
36 | **/**
37 |
38 | libs
39 |
40 |
41 | ./target/
42 |
43 | stream-compute*.jar
44 |
45 | libs
46 |
47 |
48 |
--------------------------------------------------------------------------------
/demos/StreamCompute/src/main/java/com/aliyun/tablestore/examples/utils/Conf.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.utils;
2 |
3 | import com.google.gson.Gson;
4 |
5 | import java.io.FileNotFoundException;
6 | import java.io.FileReader;
7 | import java.io.Reader;
8 |
9 | public class Conf {
10 | private String endpoint;
11 | private String accessId;
12 | private String accessKey;
13 | private String instanceName;
14 | private String sourceTableName = "source_order";
15 | private String sinkTableName = "sink_order";
16 |
17 | public String getEndpoint() {
18 | return endpoint;
19 | }
20 |
21 | public void setEndpoint(String endpoint) {
22 | this.endpoint = endpoint;
23 | }
24 |
25 | public String getAccessId() {
26 | return accessId;
27 | }
28 |
29 | public void setAccessId(String accessId) {
30 | this.accessId = accessId;
31 | }
32 |
33 | public String getAccessKey() {
34 | return accessKey;
35 | }
36 |
37 | public void setAccessKey(String accessKey) {
38 | this.accessKey = accessKey;
39 | }
40 |
41 | public String getInstanceName() {
42 | return instanceName;
43 | }
44 |
45 | public void setInstanceName(String instanceName) {
46 | this.instanceName = instanceName;
47 | }
48 |
49 | public String getSourceTableName() {
50 | return sourceTableName;
51 | }
52 |
53 | public void setSourceTableName(String sourceTableName) {
54 | this.sourceTableName = sourceTableName;
55 | }
56 |
57 | public String getSinkTableName() {
58 | return sinkTableName;
59 | }
60 |
61 | public void setSinkTableName(String sinkTableName) {
62 | this.sinkTableName = sinkTableName;
63 | }
64 |
65 | public static Conf newInstance() throws FileNotFoundException {
66 | String pathSeperator = "/";
67 | String os = System.getProperty("os.name");
68 | if (os.toLowerCase().startsWith("win")) {
69 | pathSeperator = "\\";
70 | }
71 |
72 | Reader r = new FileReader(System.getProperty("user.home") + pathSeperator + "tablestoreConf.json");
73 | Gson gson = new Gson();
74 | Conf c = gson.fromJson(r, Conf.class);
75 | return c;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/README.md:
--------------------------------------------------------------------------------
1 | # TableStore-Grid
2 |
3 | Store and query gridded data by TableStore.
4 |
5 | ## Getting started
6 |
7 | ### 1. download example data:
8 |
9 | Before we begin, you should download the following test data(test_echam_spectral.nc) which we will use in this example and configure the file path in ExampleConfig.java.
10 |
11 |
12 |
13 | [test_echam_spectral.nc](https://www.unidata.ucar.edu/software/netcdf/examples/test_echam_spectral.nc)
14 |
15 | ### 2. create store and index
16 |
17 | [CreateStoreExample.java](src/main/java/com/aliyun/tablestore/example/grid/CreateStoreExample.java)
18 |
19 | ### 3. import data
20 |
21 | [DataImportExample.java](src/main/java/com/aliyun/tablestore/example/grid/DataImportExample.java)
22 |
23 | ### 4. fetch data
24 |
25 | [DataFetchExample.java](src/main/java/com/aliyun/tablestore/example/grid/DataFetchExample.java)
26 |
27 | ### 5. query dataset by combination conditions
28 |
29 | [MetaQueryExample.java](src/main/java/com/aliyun/tablestore/example/grid/MetaQueryExample.java)
30 |
31 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore
8 | tablestore-grid
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | org.apache.maven.plugins
14 | maven-compiler-plugin
15 |
16 | 6
17 | 6
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | edu.ucar
26 | netcdf4
27 | 4.5.5
28 |
29 |
30 | com.aliyun.openservices
31 | tablestore
32 | 4.10.2
33 | jar-with-dependencies
34 |
35 |
36 | org.apache.httpcomponents
37 | httpasyncclient
38 |
39 |
40 |
41 |
42 | commons-io
43 | commons-io
44 | 2.4
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/example/grid/CreateStoreExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.grid;
2 |
3 | import com.alicloud.openservices.tablestore.model.search.FieldSchema;
4 | import com.alicloud.openservices.tablestore.model.search.FieldType;
5 | import com.alicloud.openservices.tablestore.model.search.IndexSchema;
6 | import com.aliyun.tablestore.example.grid.common.ExampleConfig;
7 | import com.aliyun.tablestore.example.grid.common.TableStoreGridExample;
8 |
9 | import java.util.Arrays;
10 |
11 | /**
12 | * this example will create table and index.
13 | */
14 | public class CreateStoreExample extends TableStoreGridExample {
15 |
16 | public CreateStoreExample() {
17 | super(ExampleConfig.GRID_DATA_TABLE_NAME, ExampleConfig.GRID_META_TABLE_NAME);
18 | }
19 |
20 | /**
21 | * we must create store before we can use it.
22 | * @throws Exception
23 | */
24 | private void createStore() throws Exception {
25 | this.tableStoreGrid.createStore();
26 | }
27 |
28 | /**
29 | * this example create an index which contains these columns: status, tag1, tag2, create_time.
30 | * you can create an index which contains any other columns.
31 | *
32 | * @throws Exception
33 | */
34 | private void createIndex() throws Exception {
35 | IndexSchema indexSchema = new IndexSchema();
36 | indexSchema.setFieldSchemas(Arrays.asList(
37 | new FieldSchema("status", FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true),
38 | new FieldSchema("tag1", FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true),
39 | new FieldSchema("tag2", FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true),
40 | new FieldSchema("create_time", FieldType.LONG).setIndex(true).setEnableSortAndAgg(true)
41 | ));
42 | this.tableStoreGrid.createMetaIndex(ExampleConfig.GRID_META_INDEX_NAME, indexSchema);
43 | }
44 |
45 | public static void main(String[] args) throws Exception {
46 | CreateStoreExample example = new CreateStoreExample();
47 | try {
48 | example.createStore();
49 | example.createIndex();
50 | } finally {
51 | example.close();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/example/grid/common/ExampleConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.grid.common;
2 |
3 | import ucar.ma2.DataType;
4 |
5 | public class ExampleConfig {
6 |
7 | /**
8 | * table name and index name
9 | */
10 | public static String GRID_DATA_TABLE_NAME = "GRID_DATA_TABLE_EXAMPLE";
11 | public static String GRID_META_TABLE_NAME = "GRID_META_TABLE_EXAMPLE";
12 | public static String GRID_META_INDEX_NAME = "GRID_META_INDEX";
13 |
14 |
15 | /**
16 | * data set config
17 | */
18 | public static String EXAMPLE_GRID_DATA_SET_ID = "test_echam_spectral_example";
19 | public static String EXAMPLE_GRID_DATA_SET_NC_FILE_PATH = "test_echam_spectral.nc";
20 | public static String EXAMPLE_GRID_DATA_VARIABLE = "tpot";
21 | public static int[] EXAMPLE_GRID_DATA_SHAPE = new int[]{8, 47, 96, 192};
22 | public static DataType EXAMPLE_GRID_DATA_TYPE = DataType.FLOAT;
23 | }
24 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/example/grid/common/TableStoreConf.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.grid.common;
2 |
3 | import com.google.gson.Gson;
4 | import org.apache.commons.io.IOUtils;
5 |
6 | import java.io.FileInputStream;
7 | import java.io.InputStream;
8 |
9 | public class TableStoreConf {
10 |
11 | private String endpoint;
12 | private String accessId;
13 | private String accessKey;
14 | private String instanceName;
15 |
16 | public static TableStoreConf newInstance(String path) {
17 | try {
18 | InputStream f = new FileInputStream(path);
19 | Gson gson = new Gson();
20 | return gson.fromJson(IOUtils.toString(f), TableStoreConf.class);
21 | } catch (Exception ex) {
22 | throw new RuntimeException(ex);
23 | }
24 | }
25 |
26 | public String getEndpoint() {
27 | return endpoint;
28 | }
29 |
30 | public void setEndpoint(String endpoint) {
31 | this.endpoint = endpoint;
32 | }
33 |
34 | public String getAccessId() {
35 | return accessId;
36 | }
37 |
38 | public void setAccessId(String accessId) {
39 | this.accessId = accessId;
40 | }
41 |
42 | public String getAccessKey() {
43 | return accessKey;
44 | }
45 |
46 | public void setAccessKey(String accessKey) {
47 | this.accessKey = accessKey;
48 | }
49 |
50 | public String getInstanceName() {
51 | return instanceName;
52 | }
53 |
54 | public void setInstanceName(String instanceName) {
55 | this.instanceName = instanceName;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/example/grid/common/TableStoreGridExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.grid.common;
2 |
3 | import com.aliyun.tablestore.grid.TableStoreGrid;
4 | import com.aliyun.tablestore.grid.TableStoreGridConfig;
5 |
6 | public abstract class TableStoreGridExample {
7 |
8 | protected TableStoreGrid tableStoreGrid;
9 | private String pathSeperator = "/";
10 |
11 | public TableStoreGridExample(String dataTableName, String metaTableName) {
12 | String os = System.getProperty("os.name");
13 | if (os.toLowerCase().startsWith("win")) {
14 | pathSeperator = "\\";
15 | }
16 | TableStoreConf conf = TableStoreConf.newInstance(System.getProperty("user.home") + pathSeperator + "tablestoreConf.json");
17 | TableStoreGridConfig config = new TableStoreGridConfig();
18 | config.setTableStoreEndpoint(conf.getEndpoint());
19 | config.setAccessId(conf.getAccessId());
20 | config.setAccessKey(conf.getAccessKey());
21 | config.setTableStoreInstance(conf.getInstanceName());
22 | config.setDataTableName(dataTableName);
23 | config.setMetaTableName(metaTableName);
24 | tableStoreGrid = new TableStoreGrid(config);
25 | }
26 |
27 | public void close() {
28 | if (tableStoreGrid != null) {
29 | tableStoreGrid.close();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/GridDataFetcher.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid;
2 |
3 | import com.aliyun.tablestore.grid.model.GridDataSet;
4 | import com.aliyun.tablestore.grid.model.grid.Range;
5 |
6 | import java.util.Collection;
7 |
8 | public interface GridDataFetcher {
9 |
10 | GridDataFetcher setVariablesToGet(Collection variables);
11 |
12 | GridDataFetcher setT(int t);
13 |
14 | GridDataFetcher setTRange(Range tRange);
15 |
16 | GridDataFetcher setZ(int z);
17 |
18 | GridDataFetcher setZRange(Range zRange);
19 |
20 | GridDataFetcher setX(int x);
21 |
22 | GridDataFetcher setXRange(Range xRange);
23 |
24 | GridDataFetcher setY(int y);
25 |
26 | GridDataFetcher setYRange(Range yRange);
27 |
28 | GridDataFetcher setOriginShape(int[] origin, int[] shape);
29 |
30 | GridDataSet fetch() throws Exception;
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/GridDataWriter.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid;
2 |
3 | import com.aliyun.tablestore.grid.model.grid.Grid2D;
4 |
5 | public interface GridDataWriter {
6 |
7 | void writeGrid2D(String variable, int t, int z, Grid2D grid2D) throws Exception;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/GridStore.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid;
2 |
3 | import com.alicloud.openservices.tablestore.model.search.IndexSchema;
4 | import com.alicloud.openservices.tablestore.model.search.query.Query;
5 | import com.aliyun.tablestore.grid.model.GridDataSetMeta;
6 | import com.aliyun.tablestore.grid.model.QueryGridDataSetResult;
7 | import com.aliyun.tablestore.grid.model.QueryParams;
8 |
9 | public interface GridStore {
10 |
11 | void createStore() throws Exception;
12 |
13 | void putDataSetMeta(GridDataSetMeta meta) throws Exception;
14 |
15 | void updateDataSetMeta(GridDataSetMeta meta) throws Exception;
16 |
17 | GridDataSetMeta getDataSetMeta(String uniqueKey) throws Exception;
18 |
19 | void createMetaIndex(String indexName, IndexSchema indexSchema) throws Exception;
20 |
21 | QueryGridDataSetResult queryDataSets(String indexName, Query query, QueryParams queryParams) throws Exception;
22 |
23 | GridDataWriter getDataWriter(GridDataSetMeta meta);
24 |
25 | GridDataFetcher getDataFetcher(GridDataSetMeta meta);
26 |
27 | void close();
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/TableStoreGridConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid;
2 |
3 | public class TableStoreGridConfig {
4 |
5 | private String tableStoreEndpoint;
6 | private String accessId;
7 | private String accessKey;
8 | private String tableStoreInstance;
9 |
10 | private String metaTableName;
11 | private String dataTableName;
12 |
13 | private long dataSizeLimitForFetch = 20 * 1024 * 1024;
14 |
15 | public String getTableStoreEndpoint() {
16 | return tableStoreEndpoint;
17 | }
18 |
19 | public void setTableStoreEndpoint(String tableStoreEndpoint) {
20 | this.tableStoreEndpoint = tableStoreEndpoint;
21 | }
22 |
23 | public String getAccessId() {
24 | return accessId;
25 | }
26 |
27 | public void setAccessId(String accessId) {
28 | this.accessId = accessId;
29 | }
30 |
31 | public String getAccessKey() {
32 | return accessKey;
33 | }
34 |
35 | public void setAccessKey(String accessKey) {
36 | this.accessKey = accessKey;
37 | }
38 |
39 | public String getTableStoreInstance() {
40 | return tableStoreInstance;
41 | }
42 |
43 | public void setTableStoreInstance(String tableStoreInstance) {
44 | this.tableStoreInstance = tableStoreInstance;
45 | }
46 |
47 | public String getMetaTableName() {
48 | return metaTableName;
49 | }
50 |
51 | public void setMetaTableName(String metaTableName) {
52 | this.metaTableName = metaTableName;
53 | }
54 |
55 | public String getDataTableName() {
56 | return dataTableName;
57 | }
58 |
59 | public void setDataTableName(String dataTableName) {
60 | this.dataTableName = dataTableName;
61 | }
62 |
63 | public long getDataSizeLimitForFetch() {
64 | return dataSizeLimitForFetch;
65 | }
66 |
67 | public void setDataSizeLimitForFetch(long dataSizeLimitForFetch) {
68 | this.dataSizeLimitForFetch = dataSizeLimitForFetch;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/consts/Constants.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.consts;
2 |
3 |
4 | public class Constants {
5 |
6 | public static String GRID_DATA_SET_ID_PK_NAME = "_id";
7 | public static String VARIABLE_PK_NAME = "_variable";
8 | public static String T_PK_NAME = "_t";
9 | public static String Z_PK_NAME = "_z";
10 |
11 | public static String DATA_TYPE_COL_NAME = "_data_type";
12 | public static String VARIABLE_LIST_COL_NAME = "_variable_list";
13 | public static String T_SIZE_COL_NAME = "_t_size";
14 | public static String Z_SIZE_COL_NAME = "_z_size";
15 | public static String X_SIZE_COL_NAME = "_x_size";
16 | public static String Y_SIZE_COL_NAME = "_y_size";
17 | public static String STORE_TYPE_COL_NAME = "_store_type";
18 | public static String X_SPLIT_COUNT_COL_NAME = "_x_split_count";
19 | public static String Y_SPLIT_COUNT_COL_NAME = "_y_split_count";
20 |
21 | public static String DATA_BLOCK_COL_NAME_PREFIX = "block_";
22 | public static String DATA_BLOCK_COL_NAME_FORMAT = "block_%s_%s";
23 |
24 |
25 | public static int MAX_REQUEST_SIZE = 2 * 1024 * 1024;
26 | }
27 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/GetDataParam.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model;
2 |
3 | import java.util.List;
4 |
5 | public class GetDataParam {
6 |
7 | private String dataTableName;
8 | private String dataSetId;
9 | private String variable;
10 | private int t;
11 | private int z;
12 | private List columnsToGet;
13 |
14 | public GetDataParam(String dataTableName, String dataSetId, String variable, int t, int z, List columnsToGet) {
15 | this.dataTableName = dataTableName;
16 | this.dataSetId = dataSetId;
17 | this.variable = variable;
18 | this.t = t;
19 | this.z = z;
20 | this.columnsToGet = columnsToGet;
21 | }
22 |
23 | public String getDataTableName() {
24 | return dataTableName;
25 | }
26 |
27 | public void setDataTableName(String dataTableName) {
28 | this.dataTableName = dataTableName;
29 | }
30 |
31 | public String getDataSetId() {
32 | return dataSetId;
33 | }
34 |
35 | public void setDataSetId(String dataSetId) {
36 | this.dataSetId = dataSetId;
37 | }
38 |
39 | public String getVariable() {
40 | return variable;
41 | }
42 |
43 | public void setVariable(String variable) {
44 | this.variable = variable;
45 | }
46 |
47 | public int getT() {
48 | return t;
49 | }
50 |
51 | public void setT(int t) {
52 | this.t = t;
53 | }
54 |
55 | public int getZ() {
56 | return z;
57 | }
58 |
59 | public void setZ(int z) {
60 | this.z = z;
61 | }
62 |
63 | public List getColumnsToGet() {
64 | return columnsToGet;
65 | }
66 |
67 | public void setColumnsToGet(List columnsToGet) {
68 | this.columnsToGet = columnsToGet;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/GridDataSet.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model;
2 |
3 | import com.aliyun.tablestore.grid.model.grid.Grid4D;
4 |
5 | import java.util.Map;
6 | import java.util.concurrent.ConcurrentHashMap;
7 |
8 | public class GridDataSet {
9 |
10 | private GridDataSetMeta meta;
11 |
12 | private Map variables;
13 |
14 | public GridDataSet(GridDataSetMeta meta) {
15 | this.meta = meta;
16 | this.variables = new ConcurrentHashMap();
17 | }
18 |
19 | public GridDataSet(GridDataSetMeta meta, Map variables) {
20 | this.meta = meta;
21 | this.variables = variables;
22 | }
23 |
24 | public void addVariable(String variable, Grid4D grid4D) {
25 | this.variables.put(variable, grid4D);
26 | }
27 |
28 | public Grid4D getVariable(String variable) {
29 | if (variables == null) {
30 | return null;
31 | }
32 | return variables.get(variable);
33 | }
34 |
35 | public Map getVariables() {
36 | return variables;
37 | }
38 |
39 | public GridDataSetMeta getMeta() {
40 | return meta;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/QueryGridDataSetResult.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model;
2 |
3 | import java.util.List;
4 |
5 | public class QueryGridDataSetResult {
6 |
7 | private List gridDataSetMetas;
8 | private long totalCount;
9 | private boolean isAllSuccess;
10 | private byte[] nextToken;
11 |
12 | public List getGridDataSetMetas() {
13 | return gridDataSetMetas;
14 | }
15 |
16 | public void setGridDataSetMetas(List gridDataSetMetas) {
17 | this.gridDataSetMetas = gridDataSetMetas;
18 | }
19 |
20 | public long getTotalCount() {
21 | return totalCount;
22 | }
23 |
24 | public void setTotalCount(long totalCount) {
25 | this.totalCount = totalCount;
26 | }
27 |
28 | public boolean isAllSuccess() {
29 | return isAllSuccess;
30 | }
31 |
32 | public void setAllSuccess(boolean allSuccess) {
33 | isAllSuccess = allSuccess;
34 | }
35 |
36 | public byte[] getNextToken() {
37 | return nextToken;
38 | }
39 |
40 | public void setNextToken(byte[] nextToken) {
41 | this.nextToken = nextToken;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/QueryParams.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model;
2 |
3 |
4 | import com.alicloud.openservices.tablestore.model.search.sort.Sort;
5 |
6 | public class QueryParams {
7 |
8 | private Integer offset;
9 | private Integer limit;
10 | private Sort sort;
11 | private byte[] token;
12 | private boolean getTotalCount = false;
13 |
14 | public QueryParams() {
15 | }
16 |
17 | public QueryParams(int limit) {
18 | this.limit = limit;
19 | }
20 |
21 | public QueryParams(int offset, int limit) {
22 | this.offset = offset;
23 | this.limit = limit;
24 | }
25 |
26 | public QueryParams(int offset, int limit, Sort sort) {
27 | this.offset = offset;
28 | this.limit = limit;
29 | this.sort = sort;
30 | }
31 |
32 | public QueryParams(byte[] token, int limit) {
33 | this.token = token;
34 | this.limit = limit;
35 | }
36 |
37 |
38 | public Integer getOffset() {
39 | return offset;
40 | }
41 |
42 | public QueryParams setOffset(Integer offset) {
43 | this.offset = offset;
44 | return this;
45 | }
46 |
47 | public Integer getLimit() {
48 | return limit;
49 | }
50 |
51 | public QueryParams setLimit(Integer limit) {
52 | this.limit = limit;
53 | return this;
54 | }
55 |
56 | public Sort getSort() {
57 | return sort;
58 | }
59 |
60 | public QueryParams setSort(Sort sort) {
61 | this.sort = sort;
62 | return this;
63 | }
64 |
65 | public byte[] getToken() {
66 | return token;
67 | }
68 |
69 | public QueryParams setToken(byte[] token) {
70 | this.token = token;
71 | return this;
72 | }
73 |
74 | public boolean isGetTotalCount() {
75 | return getTotalCount;
76 | }
77 |
78 | public QueryParams setGetTotalCount(boolean getTotalCount) {
79 | this.getTotalCount = getTotalCount;
80 | return this;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/StoreOptions.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model;
2 |
3 | public class StoreOptions {
4 |
5 | public enum StoreType {
6 | SLICE
7 | }
8 |
9 | private StoreType storeType;
10 | private int xSplitCount = 10;
11 | private int ySplitCount = 10;
12 |
13 | public StoreOptions(StoreType storeType) {
14 | this.storeType = storeType;
15 | }
16 |
17 | public StoreType getStoreType() {
18 | return storeType;
19 | }
20 |
21 | public void setStoreType(StoreType storeType) {
22 | this.storeType = storeType;
23 | }
24 |
25 | public int getxSplitCount() {
26 | return xSplitCount;
27 | }
28 |
29 | public void setxSplitCount(int xSplitCount) {
30 | this.xSplitCount = xSplitCount;
31 | }
32 |
33 | public int getySplitCount() {
34 | return ySplitCount;
35 | }
36 |
37 | public void setySplitCount(int ySplitCount) {
38 | this.ySplitCount = ySplitCount;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/grid/Grid.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model.grid;
2 |
3 | import ucar.ma2.Array;
4 | import ucar.ma2.DataType;
5 |
6 | import java.nio.ByteBuffer;
7 |
8 | public abstract class Grid {
9 |
10 | protected ByteBuffer buffer;
11 | protected DataType dataType;
12 | protected int[] origin;
13 | protected int[] shape;
14 |
15 | public Grid(ByteBuffer buffer, DataType dataType, int[] origin, int[] shape) {
16 | this.buffer = buffer;
17 | this.dataType = dataType;
18 | this.origin = origin;
19 | this.shape = shape;
20 | int size = dataType.getSize();
21 | for (int i = 0; i < shape.length; i++) {
22 | size *= shape[i];
23 | }
24 | if (buffer.remaining() != size) {
25 | throw new IllegalArgumentException("data length and shape mismatch");
26 | }
27 | if (origin.length != shape.length) {
28 | throw new IllegalArgumentException("the length of origin and shape mismatch");
29 | }
30 | }
31 |
32 | public int getDataSize() {
33 | return buffer.remaining();
34 | }
35 |
36 | public byte[] getDataAsByteArray() {
37 | byte[] data = new byte[getDataSize()];
38 | buffer.duplicate().get(data);
39 | return data;
40 | }
41 |
42 | public int[] getOrigin() {
43 | return origin;
44 | }
45 |
46 | public int[] getShape() {
47 | return shape;
48 | }
49 |
50 | public DataType getDataType() {
51 | return dataType;
52 | }
53 |
54 | public Array toArray() {
55 | Array array = Array.factory(dataType, shape, buffer.duplicate());
56 | return array;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/grid/Grid2D.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model.grid;
2 |
3 | import ucar.ma2.DataType;
4 |
5 | import java.nio.ByteBuffer;
6 |
7 | public class Grid2D extends Grid {
8 |
9 | public Grid2D(ByteBuffer data, DataType dataType, int[] origin, int[] shape) {
10 | super(data, dataType, origin, shape);
11 | if (origin.length != 2 || shape.length != 2) {
12 | throw new IllegalArgumentException("the length of origin and shape must be 2");
13 | }
14 | }
15 |
16 | public Plane getPlane() {
17 | return new Plane(getOrigin(), getShape());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/grid/Grid3D.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model.grid;
2 |
3 | import ucar.ma2.DataType;
4 |
5 | import java.nio.ByteBuffer;
6 | import java.util.Arrays;
7 |
8 | public class Grid3D extends Grid {
9 |
10 | public Grid3D(ByteBuffer data, DataType dataType, int[] origin, int[] shape) {
11 | super(data, dataType, origin, shape);
12 | if (origin.length != 3 || shape.length != 3) {
13 | throw new IllegalArgumentException("the length of origin and shape must be 2");
14 | }
15 | }
16 |
17 | public Grid2D getGrid2D(int idx) {
18 | if (idx < 0 || idx >= shape[0]) {
19 | throw new IllegalArgumentException("index out of range");
20 | }
21 | int itemSize = shape[1] * shape[2] * dataType.getSize();
22 | int pos = idx * itemSize;
23 | ByteBuffer newBuffer = buffer.slice();
24 | newBuffer.position(pos);
25 | newBuffer.limit(pos + itemSize);
26 | newBuffer = newBuffer.slice();
27 | return new Grid2D(newBuffer, dataType, Arrays.copyOfRange(origin, 1, origin.length),
28 | Arrays.copyOfRange(shape, 1, shape.length));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/grid/Grid4D.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model.grid;
2 |
3 | import ucar.ma2.DataType;
4 |
5 | import java.nio.ByteBuffer;
6 | import java.util.Arrays;
7 |
8 | public class Grid4D extends Grid {
9 |
10 | public Grid4D(ByteBuffer data, DataType dataType, int[] origin, int[] shape) {
11 | super(data, dataType, origin, shape);
12 | if (origin.length != 4 || shape.length != 4) {
13 | throw new IllegalArgumentException("the length of origin and shape must be 2");
14 | }
15 | }
16 |
17 | public Grid3D getGrid3D(int idx) {
18 | if (idx < 0 || idx >= shape[0]) {
19 | throw new IllegalArgumentException("index out of range");
20 | }
21 | int itemSize = shape[1] * shape[2] * shape[3] * dataType.getSize();
22 | int pos = idx * itemSize;
23 | ByteBuffer newBuffer = buffer.slice();
24 | newBuffer.position(pos);
25 | newBuffer.limit(pos + itemSize);
26 | newBuffer = newBuffer.slice();
27 | return new Grid3D(newBuffer, dataType, Arrays.copyOfRange(origin, 1, origin.length),
28 | Arrays.copyOfRange(shape, 1, shape.length));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/grid/Plane.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model.grid;
2 |
3 | public class Plane {
4 |
5 | private Range xRange;
6 | private Range yRange;
7 |
8 | public Plane(Range xRange, Range yRange) {
9 | this.xRange = xRange;
10 | this.yRange = yRange;
11 | }
12 |
13 | public Plane(int[] origin, int[] shape) {
14 | if (origin.length != 2 || shape.length != 2) {
15 | throw new IllegalArgumentException("the length of origin and shape must be 2");
16 | }
17 | this.xRange = new Range(origin[0], origin[0] + shape[0]);
18 | this.yRange = new Range(origin[1], origin[1] + shape[1]);
19 | }
20 |
21 | public int[] getOrigin() {
22 | return new int[] {xRange.getStart(), yRange.getStart()};
23 | }
24 |
25 | public int[] getShape() {
26 | return new int[] {xRange.getSize(), yRange.getSize()};
27 | }
28 |
29 | public Range getxRange() {
30 | return xRange;
31 | }
32 |
33 | public void setxRange(Range xRange) {
34 | this.xRange = xRange;
35 | }
36 |
37 | public Range getyRange() {
38 | return yRange;
39 | }
40 |
41 | public void setyRange(Range yRange) {
42 | this.yRange = yRange;
43 | }
44 |
45 | @Override
46 | public boolean equals(Object o) {
47 | if (this == o) {
48 | return true;
49 | }
50 | if (o instanceof Plane) {
51 | if (xRange.equals(((Plane) o).getxRange()) && yRange.equals(((Plane) o).getyRange())) {
52 | return true;
53 | }
54 | return false;
55 | }
56 | return false;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/grid/Point.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model.grid;
2 |
3 | public class Point {
4 |
5 | private int x;
6 | private int y;
7 |
8 | public Point(int x, int y) {
9 | this.x = x;
10 | this.y = y;
11 | }
12 |
13 | public int getX() {
14 | return x;
15 | }
16 |
17 | public void setX(int x) {
18 | this.x = x;
19 | }
20 |
21 | public int getY() {
22 | return y;
23 | }
24 |
25 | public void setY(int y) {
26 | this.y = y;
27 | }
28 |
29 | @Override
30 | public boolean equals(Object o) {
31 | if (this == o) {
32 | return true;
33 | }
34 | if (o instanceof Point) {
35 | if (x == ((Point) o).x && y == ((Point) o).y) {
36 | return true;
37 | }
38 | return false;
39 | }
40 | return false;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/model/grid/Range.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.model.grid;
2 |
3 | public class Range {
4 |
5 | private int start;
6 | private int end;
7 |
8 | public Range(int end) {
9 | this.start = 0;
10 | this.end = end;
11 | }
12 |
13 | public Range(int start, int end) {
14 | this.start = start;
15 | this.end = end;
16 | }
17 |
18 | public int getStart() {
19 | return start;
20 | }
21 |
22 | public void setStart(int start) {
23 | this.start = start;
24 | }
25 |
26 | public int getEnd() {
27 | return end;
28 | }
29 |
30 | public void setEnd(int end) {
31 | this.end = end;
32 | }
33 |
34 | public int getSize() {
35 | return this.end - this.start;
36 | }
37 |
38 | @Override
39 | public boolean equals(Object o) {
40 | if (this == o) {
41 | return true;
42 | }
43 | if (o instanceof Range) {
44 | if (start == ((Range) o).start && end == ((Range) o).end) {
45 | return true;
46 | }
47 | return false;
48 | }
49 | return false;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return ("[" + start + ", " + end + ")");
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/demos/TableStore-Grid/src/main/java/com/aliyun/tablestore/grid/utils/ValueUtil.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.grid.utils;
2 |
3 | import com.alicloud.openservices.tablestore.model.ColumnValue;
4 |
5 | public class ValueUtil {
6 |
7 | public static ColumnValue toColumnValue(Object value) {
8 | if (value instanceof Long) {
9 | return ColumnValue.fromLong((Long) value);
10 | } else if (value instanceof Integer) {
11 | return ColumnValue.fromLong(((Integer) value).longValue());
12 | } else if (value instanceof Double) {
13 | return ColumnValue.fromDouble((Double) value);
14 | } else if (value instanceof String) {
15 | return ColumnValue.fromString((String) value);
16 | } else if (value instanceof Boolean) {
17 | return ColumnValue.fromBoolean((Boolean) value);
18 | } else if (value instanceof byte[]) {
19 | return ColumnValue.fromBinary((byte[]) value);
20 | } else {
21 | throw new IllegalArgumentException("unsupported type: " + value.getClass());
22 | }
23 | }
24 |
25 | public static Object toObject(ColumnValue value) {
26 | switch (value.getType()) {
27 | case INTEGER: {
28 | return value.asLong();
29 | }
30 | case STRING: {
31 | return value.asString();
32 | }
33 | case BOOLEAN: {
34 | return value.asBoolean();
35 | }
36 | case DOUBLE: {
37 | return value.asDouble();
38 | }
39 | case BINARY: {
40 | return value.asBinary();
41 | }
42 | default: {
43 | throw new RuntimeException("unexpected");
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/demos/TraceMedicine/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .idea/*
3 |
--------------------------------------------------------------------------------
/demos/TraceMedicine/Readme.md:
--------------------------------------------------------------------------------
1 | # Trace Medicine
2 |
3 | Store and Query By Timestream in Tablestore.
4 |
5 | ## SampleCode
6 | - [MedicineReadWriteExample](src/main/java/com/aliyun/tablestore/example/trace_medicine/MedicineReadWriteExample.java)
7 |
8 | ## Quote
9 | - [Timestream of Tablestore](https://www.aliyun.com/product/ots)
--------------------------------------------------------------------------------
/demos/TraceMedicine/src/main/resources/conf.json:
--------------------------------------------------------------------------------
1 | {
2 | "metaTableName":"medicine_meta",
3 | "dataTableName":"medicine_data"
4 | }
--------------------------------------------------------------------------------
/demos/WifiMonitor/README.md:
--------------------------------------------------------------------------------
1 | # WifiMonitor
2 |
3 | Manage wifi meta and data by Timestream of TableStore.
--------------------------------------------------------------------------------
/demos/WifiMonitor/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore.examples
8 | WifiMonitor
9 | 1.0-SNAPSHOT
10 |
11 |
12 | UTF-8
13 |
14 |
15 |
16 |
17 | com.aliyun.openservices
18 | tablestore
19 | 4.11.0
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.4
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | maven-compiler-plugin
33 |
34 | 1.8
35 | 1.8
36 | ${project-sourceEncoding}
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/demos/WifiMonitor/src/main/java/com/aliyun/tablestore/WifiMonitor.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore;
2 |
3 | public class WifiMonitor {
4 |
5 | public static void main(String[] args) {
6 | ManageService demo = new ManageService("timestream_monitor_meta", "timestream_monitor_data");
7 | /**
8 | * init the timestream of machine monitor;
9 | * */
10 | demo.init();
11 | // demo.deleteTable();
12 | /**
13 | /**
14 | * create meta table and data table for machine:
15 | * 1. metaTableName: which stores the mail meta such as monitor metric, region, machineId and running services;
16 | * 2. dataTableName: which stores the machine running status data;
17 | * */
18 | // demo.createTable();
19 |
20 | /**
21 | * 1. put some monitor meta info into metaTable;
22 | * 2. and some status data during a period of time, such as cpu, ram;
23 | * */
24 | // demo.writeData();
25 |
26 | /**
27 | * meta iterator:search by multi combined conditions ;
28 | * data iterator:search by meta identifier and time range;
29 | * */
30 | demo.readMetaAndData();
31 |
32 | /**
33 | * delete all the dataTables
34 | * */
35 | // demo.deleteTable();
36 |
37 | /**
38 | * shutdown the connections;
39 | * */
40 | demo.close();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/demos/WifiMonitor/src/main/java/com/aliyun/tablestore/common/Conf.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import com.google.gson.Gson;
4 | import org.apache.commons.io.IOUtils;
5 |
6 | import java.io.FileInputStream;
7 | import java.io.InputStream;
8 |
9 | public class Conf {
10 |
11 | private String endpoint;
12 | private String accessId;
13 | private String accessKey;
14 | private String instanceName;
15 |
16 | public static Conf newInstance(String path) {
17 | try {
18 | InputStream f = new FileInputStream(path);
19 | Gson gson = new Gson();
20 | return gson.fromJson(IOUtils.toString(f), Conf.class);
21 | } catch (Exception ex) {
22 | throw new RuntimeException(ex);
23 | }
24 | }
25 |
26 | public String getEndpoint() {
27 | return endpoint;
28 | }
29 |
30 | public void setEndpoint(String endpoint) {
31 | this.endpoint = endpoint;
32 | }
33 |
34 | public String getAccessId() {
35 | return accessId;
36 | }
37 |
38 | public void setAccessId(String accessId) {
39 | this.accessId = accessId;
40 | }
41 |
42 | public String getAccessKey() {
43 | return accessKey;
44 | }
45 |
46 | public void setAccessKey(String accessKey) {
47 | this.accessKey = accessKey;
48 | }
49 |
50 | public String getInstanceName() {
51 | return instanceName;
52 | }
53 |
54 | public void setInstanceName(String instanceName) {
55 | this.instanceName = instanceName;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/demos/WifiMonitor/src/main/java/com/aliyun/tablestore/common/Util.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.common;
2 |
3 | import java.util.Random;
4 |
5 | public class Util {
6 | private static Random Rand = new Random(37);
7 | public static String getWifiRandomLocation() {
8 | return String.format("%f,%f", 30. + Rand.nextDouble() * 10, 120. + Rand.nextDouble() * 10);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/demos/insurance-policy-management/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore
8 | insurance-policy-management
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | com.aliyun.openservices
14 | tablestore
15 | 4.11.0
16 |
17 |
18 | com.fasterxml.jackson.core
19 | jackson-databind
20 | 2.9.8
21 |
22 |
23 | org.apache.commons
24 | commons-lang3
25 | 3.8.1
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-compiler-plugin
34 |
35 | 8
36 | 8
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/demos/insurance-policy-management/src/main/java/com/aliyun/tablestore/example/BaseExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.aliyun.tablestore.example.utils.ClientAndConfig;
5 |
6 | /**
7 | * @author hydrogen
8 | */
9 | public abstract class BaseExample {
10 |
11 | protected final SyncClient syncClient;
12 |
13 | protected final String tableName;
14 |
15 | protected final String indexName;
16 |
17 | protected final int importDataCount;
18 |
19 | public BaseExample(ClientAndConfig clientAndConfig) {
20 | this.syncClient = clientAndConfig.getSyncClient();
21 | this.tableName = clientAndConfig.getTableName();
22 | this.indexName = clientAndConfig.getIndexName();
23 | importDataCount = clientAndConfig.getImportDataCount();
24 | }
25 |
26 | protected abstract void doMain();
27 |
28 | protected void main() {
29 | try {
30 | doMain();
31 | } finally {
32 | syncClient.shutdown();
33 | }
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/demos/insurance-policy-management/src/main/java/com/aliyun/tablestore/example/CleanExampleTableAndIndex.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.alicloud.openservices.tablestore.model.DeleteTableRequest;
4 | import com.alicloud.openservices.tablestore.model.search.DeleteSearchIndexRequest;
5 | import com.alicloud.openservices.tablestore.model.search.ListSearchIndexRequest;
6 | import com.alicloud.openservices.tablestore.model.search.ListSearchIndexResponse;
7 | import com.alicloud.openservices.tablestore.model.search.SearchIndexInfo;
8 | import com.aliyun.tablestore.example.utils.ClientAndConfig;
9 | import com.aliyun.tablestore.example.utils.Utils;
10 |
11 | /**
12 | * @author hydrogen
13 | */
14 | public class CleanExampleTableAndIndex extends BaseExample {
15 |
16 | public CleanExampleTableAndIndex(ClientAndConfig clientAndConfig) {
17 | super(clientAndConfig);
18 | }
19 |
20 | public static void main(String[] args) {
21 | new CleanExampleTableAndIndex(Utils.getClientAndConfig(args)).main();
22 | }
23 |
24 | private void deleteIndex() {
25 | ListSearchIndexRequest listRequest = new ListSearchIndexRequest();
26 | listRequest.setTableName(tableName);
27 | ListSearchIndexResponse listResponse = syncClient.listSearchIndex(listRequest);
28 | for (SearchIndexInfo searchIndexInfo : listResponse.getIndexInfos()) {
29 | System.out.println("Deleting SearchIndex " + searchIndexInfo.getIndexName());
30 | DeleteSearchIndexRequest deleteRequest = new DeleteSearchIndexRequest();
31 | deleteRequest.setTableName(tableName);
32 | deleteRequest.setIndexName(searchIndexInfo.getIndexName());
33 | syncClient.deleteSearchIndex(deleteRequest);
34 | }
35 | }
36 |
37 | private void deleteTable() {
38 | System.out.println("Deleting Table");
39 | DeleteTableRequest deleteRequest = new DeleteTableRequest(tableName);
40 | syncClient.deleteTable(deleteRequest);
41 | }
42 |
43 | @Override
44 | protected void doMain() {
45 | deleteIndex();
46 | deleteTable();
47 | System.out.println("Delete done");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/demos/insurance-policy-management/src/main/java/com/aliyun/tablestore/example/consts/ColumnConsts.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.consts;
2 |
3 | /**
4 | * @author hydrogen
5 | */
6 | public interface ColumnConsts {
7 | String POLICY_ID_MD5 = "policy_id_md5";
8 |
9 | String POLICY_ID = "policy_id";
10 | String PRODUCT_NAME = "product_name";
11 | String OPERATE_TIME = "operate_time";
12 | String EFFECTIVE_TIME = "effective_time";
13 | String EXPIRATION_TIME = "expiration_time";
14 | String APPLIER_USER_ID = "applier_user_id";
15 | String BROKER_USER_ID = "broker_user_id";
16 | String APPLIER_NAME = "applier_name";
17 | String APPLIER_ID = "applier_id";
18 | String APPLIER_GENDER = "applier_gender";
19 | String INSURED_NAME = "insured_name";
20 | String INSURED_ID = "insured_id";
21 | String INSURED_GENDER = "insured_gender";
22 |
23 | String PREMIUM = "premium";
24 | String PROFIT = "profit";
25 |
26 | String BENEFICIARY_INFO = "beneficiary_info";
27 | String NAME = "name";
28 | String ID = "id";
29 | String GENDER = "gender";
30 | String BENEFIT_PERCENTAGE = "benefit_percentage";
31 | }
32 |
--------------------------------------------------------------------------------
/demos/insurance-policy-management/src/main/java/com/aliyun/tablestore/example/utils/ClientAndConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.utils;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 |
5 | /**
6 | * @author hydrogen
7 | */
8 | public class ClientAndConfig {
9 |
10 | private final String tableName;
11 |
12 | private final String indexName;
13 |
14 | private final SyncClient syncClient;
15 |
16 | private final int importDataCount;
17 |
18 |
19 | public ClientAndConfig(String tableName, String indexName, SyncClient syncClient, int importDataCount) {
20 | this.tableName = tableName;
21 | this.indexName = indexName;
22 | this.syncClient = syncClient;
23 | this.importDataCount = importDataCount;
24 | }
25 |
26 | public String getTableName() {
27 | return tableName;
28 | }
29 |
30 | public String getIndexName() {
31 | return indexName;
32 | }
33 |
34 | public SyncClient getSyncClient() {
35 | return syncClient;
36 | }
37 |
38 | public int getImportDataCount() {
39 | return importDataCount;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/demos/insurance-policy-management/src/main/java/com/aliyun/tablestore/example/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.utils;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.alicloud.openservices.tablestore.core.utils.IOUtils;
5 | import com.fasterxml.jackson.databind.JsonNode;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 |
8 | import java.io.FileInputStream;
9 | import java.io.FileNotFoundException;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 |
13 | /**
14 | * @author hydrogen
15 | */
16 | public class Utils {
17 |
18 | public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
19 |
20 | public static ClientAndConfig getClientAndConfig(String[] args) {
21 | final String pathSeparator;
22 | String os = System.getProperty("os.name");
23 | if (os.toLowerCase().startsWith("win")) {
24 | pathSeparator = "\\";
25 | } else {
26 | pathSeparator = "/";
27 | }
28 |
29 | final InputStream inputStream;
30 | try {
31 | inputStream = new FileInputStream(System.getProperty("user.home") + pathSeparator + "tablestoreConf.json");
32 | } catch (FileNotFoundException e) {
33 | throw new RuntimeException(e);
34 | }
35 | // parse config in config file
36 | JsonNode config;
37 | try {
38 | config = OBJECT_MAPPER.readTree(inputStream);
39 | } catch (IOException e) {
40 | throw new RuntimeException(e);
41 | } finally {
42 | IOUtils.safeClose(inputStream);
43 | }
44 |
45 | SyncClient syncClient = new SyncClient(
46 | config.get("endpoint").asText(),
47 | config.get("accessId").asText(),
48 | config.get("accessKey").asText(),
49 | config.get("instanceName").asText()
50 | );
51 | return new ClientAndConfig(
52 | config.path("table").asText("insurance_policy"),
53 | config.path("index").asText("insurance_policy_index"),
54 | syncClient,
55 | config.path("importDataCount").asInt(10_000_000));
56 |
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/feature/AggregationAndGroupBy/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore
8 | aggregation-and-groupby
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | com.aliyun.openservices
14 | tablestore
15 | 5.3.0
16 |
17 |
18 | com.fasterxml.jackson.core
19 | jackson-databind
20 | 2.9.8
21 |
22 |
23 |
24 |
25 |
26 |
27 | org.apache.maven.plugins
28 | maven-compiler-plugin
29 |
30 | 8
31 | 8
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/feature/AggregationAndGroupBy/src/main/java/com/aliyun/tablestore/example/BaseExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.aliyun.tablestore.example.utils.ClientAndConfig;
5 |
6 | public abstract class BaseExample {
7 |
8 | protected final SyncClient syncClient;
9 |
10 | protected final String tableName;
11 |
12 | protected final String indexName;
13 |
14 | public BaseExample(ClientAndConfig clientAndConfig) {
15 | this.syncClient = clientAndConfig.getSyncClient();
16 | this.tableName = clientAndConfig.getTableName();
17 | this.indexName = clientAndConfig.getIndexName();
18 | }
19 |
20 | protected abstract void doMain();
21 |
22 | protected void main() {
23 | try {
24 | doMain();
25 | } finally {
26 | syncClient.shutdown();
27 | }
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/feature/AggregationAndGroupBy/src/main/java/com/aliyun/tablestore/example/CleanupEnv.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.alicloud.openservices.tablestore.model.DeleteTableRequest;
4 | import com.alicloud.openservices.tablestore.model.search.DeleteSearchIndexRequest;
5 | import com.alicloud.openservices.tablestore.model.search.ListSearchIndexRequest;
6 | import com.alicloud.openservices.tablestore.model.search.ListSearchIndexResponse;
7 | import com.alicloud.openservices.tablestore.model.search.SearchIndexInfo;
8 | import com.aliyun.tablestore.example.utils.ClientAndConfig;
9 | import com.aliyun.tablestore.example.utils.Utils;
10 |
11 | public class CleanupEnv extends BaseExample {
12 |
13 | public CleanupEnv(ClientAndConfig clientAndConfig) {
14 | super(clientAndConfig);
15 | }
16 |
17 | public static void main(String[] args) {
18 | new CleanupEnv(Utils.getClientAndConfig(args)).main();
19 | }
20 |
21 | private void deleteIndex() {
22 | ListSearchIndexRequest listRequest = new ListSearchIndexRequest();
23 | listRequest.setTableName(tableName);
24 | ListSearchIndexResponse listResponse = syncClient.listSearchIndex(listRequest);
25 | for (SearchIndexInfo searchIndexInfo : listResponse.getIndexInfos()) {
26 | System.out.println("Deleting SearchIndex " + searchIndexInfo.getIndexName());
27 | DeleteSearchIndexRequest deleteRequest = new DeleteSearchIndexRequest();
28 | deleteRequest.setTableName(tableName);
29 | deleteRequest.setIndexName(searchIndexInfo.getIndexName());
30 | syncClient.deleteSearchIndex(deleteRequest);
31 | }
32 | }
33 |
34 | private void deleteTable() {
35 | System.out.println("Deleting Table");
36 | DeleteTableRequest deleteRequest = new DeleteTableRequest(tableName);
37 | syncClient.deleteTable(deleteRequest);
38 | }
39 |
40 | @Override
41 | protected void doMain() {
42 | deleteIndex();
43 | deleteTable();
44 | System.out.println("Delete done");
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/feature/AggregationAndGroupBy/src/main/java/com/aliyun/tablestore/example/consts/ColumnConsts.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.consts;
2 |
3 | /**
4 | * @author sam
5 | */
6 | public interface ColumnConsts {
7 | // pk columns
8 | String ID = "id";
9 |
10 | // attribute columns
11 | String NAME = "name";
12 | String PRICE = "price";
13 | String BRAND = "brand";
14 | String SELLER = "seller";
15 | }
16 |
--------------------------------------------------------------------------------
/feature/AggregationAndGroupBy/src/main/java/com/aliyun/tablestore/example/utils/ClientAndConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.utils;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 |
5 | public class ClientAndConfig {
6 |
7 | private final String tableName;
8 |
9 | private final String indexName;
10 |
11 | private final SyncClient syncClient;
12 |
13 |
14 | public ClientAndConfig(String tableName, String indexName, SyncClient syncClient, int importDataCount) {
15 | this.tableName = tableName;
16 | this.indexName = indexName;
17 | this.syncClient = syncClient;
18 | }
19 |
20 | public String getTableName() {
21 | return tableName;
22 | }
23 |
24 | public String getIndexName() {
25 | return indexName;
26 | }
27 |
28 | public SyncClient getSyncClient() {
29 | return syncClient;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/feature/AggregationAndGroupBy/src/main/java/com/aliyun/tablestore/example/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.utils;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.alicloud.openservices.tablestore.core.utils.IOUtils;
5 | import com.fasterxml.jackson.databind.JsonNode;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 |
8 | import java.io.FileInputStream;
9 | import java.io.FileNotFoundException;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 |
13 | public class Utils {
14 |
15 | public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
16 |
17 | public static ClientAndConfig getClientAndConfig(String[] args) {
18 | final String pathSeparator;
19 | String os = System.getProperty("os.name");
20 | if (os.toLowerCase().startsWith("win")) {
21 | pathSeparator = "\\";
22 | } else {
23 | pathSeparator = "/";
24 | }
25 |
26 | final InputStream inputStream;
27 | try {
28 | inputStream = new FileInputStream(System.getProperty("user.home") + pathSeparator + "tablestoreConf.json");
29 | } catch (FileNotFoundException e) {
30 | throw new RuntimeException(e);
31 | }
32 | // parse config in config file
33 | JsonNode config;
34 | try {
35 | config = OBJECT_MAPPER.readTree(inputStream);
36 | } catch (IOException e) {
37 | throw new RuntimeException(e);
38 | } finally {
39 | IOUtils.safeClose(inputStream);
40 | }
41 |
42 | SyncClient syncClient = new SyncClient(
43 | config.get("endpoint").asText(),
44 | config.get("accessId").asText(),
45 | config.get("accessKey").asText(),
46 | config.get("instanceName").asText()
47 | );
48 | return new ClientAndConfig(
49 | config.path("table").asText("price_list"),
50 | config.path("index").asText("price_list_index"),
51 | syncClient,
52 | config.path("importDataCount").asInt(10_000_000));
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/feature/FuzzySearch/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.aliyun.tablestore
8 | order-fuzzy-query
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | com.aliyun.openservices
14 | tablestore
15 | 5.1.0
16 |
17 |
18 | com.fasterxml.jackson.core
19 | jackson-databind
20 | 2.9.8
21 |
22 |
23 | org.apache.commons
24 | commons-lang3
25 | 3.8.1
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-compiler-plugin
34 |
35 | 8
36 | 8
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/feature/FuzzySearch/src/main/java/com/aliyun/tablestore/example/BaseExample.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.aliyun.tablestore.example.utils.ClientAndConfig;
5 |
6 | public abstract class BaseExample {
7 |
8 | protected final SyncClient syncClient;
9 |
10 | protected final String tableName;
11 |
12 | protected final String indexName;
13 |
14 | protected final int importDataCount;
15 |
16 | public BaseExample(ClientAndConfig clientAndConfig) {
17 | this.syncClient = clientAndConfig.getSyncClient();
18 | this.tableName = clientAndConfig.getTableName();
19 | this.indexName = clientAndConfig.getIndexName();
20 | importDataCount = clientAndConfig.getImportDataCount();
21 | }
22 |
23 | protected abstract void doMain();
24 |
25 | protected void main() {
26 | try {
27 | doMain();
28 | } finally {
29 | syncClient.shutdown();
30 | }
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/feature/FuzzySearch/src/main/java/com/aliyun/tablestore/example/CleanupEnv.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example;
2 |
3 | import com.alicloud.openservices.tablestore.model.DeleteTableRequest;
4 | import com.alicloud.openservices.tablestore.model.search.DeleteSearchIndexRequest;
5 | import com.alicloud.openservices.tablestore.model.search.ListSearchIndexRequest;
6 | import com.alicloud.openservices.tablestore.model.search.ListSearchIndexResponse;
7 | import com.alicloud.openservices.tablestore.model.search.SearchIndexInfo;
8 | import com.aliyun.tablestore.example.utils.ClientAndConfig;
9 | import com.aliyun.tablestore.example.utils.Utils;
10 |
11 | public class CleanupEnv extends BaseExample {
12 |
13 | public CleanupEnv(ClientAndConfig clientAndConfig) {
14 | super(clientAndConfig);
15 | }
16 |
17 | public static void main(String[] args) {
18 | new CleanupEnv(Utils.getClientAndConfig(args)).main();
19 | }
20 |
21 | private void deleteIndex() {
22 | ListSearchIndexRequest listRequest = new ListSearchIndexRequest();
23 | listRequest.setTableName(tableName);
24 | ListSearchIndexResponse listResponse = syncClient.listSearchIndex(listRequest);
25 | for (SearchIndexInfo searchIndexInfo : listResponse.getIndexInfos()) {
26 | System.out.println("Deleting SearchIndex " + searchIndexInfo.getIndexName());
27 | DeleteSearchIndexRequest deleteRequest = new DeleteSearchIndexRequest();
28 | deleteRequest.setTableName(tableName);
29 | deleteRequest.setIndexName(searchIndexInfo.getIndexName());
30 | syncClient.deleteSearchIndex(deleteRequest);
31 | }
32 | }
33 |
34 | private void deleteTable() {
35 | System.out.println("Deleting Table");
36 | DeleteTableRequest deleteRequest = new DeleteTableRequest(tableName);
37 | syncClient.deleteTable(deleteRequest);
38 | }
39 |
40 | @Override
41 | protected void doMain() {
42 | deleteIndex();
43 | deleteTable();
44 | System.out.println("Delete done");
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/feature/FuzzySearch/src/main/java/com/aliyun/tablestore/example/consts/ColumnConsts.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.consts;
2 |
3 | /**
4 | * @author hydrogen
5 | */
6 | public interface ColumnConsts {
7 | // pk columns
8 | String ORDER_ID_MD5 = "order_id_md5";
9 | String ORDER_ID = "order_id";
10 |
11 | // attribute columns
12 | String ORDER_STATUS = "order_status";
13 |
14 | String ORDER_TIME = "order_time";
15 | String PAY_TIME = "pay_time";
16 | String DELIVER_TIME = "deliver_time";
17 | String RECEIVE_TIME = "receive_time";
18 |
19 | String PRODUCT_ID = "product_id";
20 | String PRODUCT_NAME = "product_name";
21 | String PRODUCT_TYPE = "product_type";
22 |
23 | String CONSUMER_ID = "consumer_id";
24 | String CONSUMER_NAME = "consumer_name";
25 | String CONSUMER_CELL = "consumer_cell";
26 | String CONSUMER_ADDRESS = "address";
27 | }
28 |
--------------------------------------------------------------------------------
/feature/FuzzySearch/src/main/java/com/aliyun/tablestore/example/utils/ClientAndConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.utils;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 |
5 | public class ClientAndConfig {
6 |
7 | private final String tableName;
8 |
9 | private final String indexName;
10 |
11 | private final SyncClient syncClient;
12 |
13 | private final int importDataCount;
14 |
15 |
16 | public ClientAndConfig(String tableName, String indexName, SyncClient syncClient, int importDataCount) {
17 | this.tableName = tableName;
18 | this.indexName = indexName;
19 | this.syncClient = syncClient;
20 | this.importDataCount = importDataCount;
21 | }
22 |
23 | public String getTableName() {
24 | return tableName;
25 | }
26 |
27 | public String getIndexName() {
28 | return indexName;
29 | }
30 |
31 | public SyncClient getSyncClient() {
32 | return syncClient;
33 | }
34 |
35 | public int getImportDataCount() {
36 | return importDataCount;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/feature/FuzzySearch/src/main/java/com/aliyun/tablestore/example/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.example.utils;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.alicloud.openservices.tablestore.core.utils.IOUtils;
5 | import com.fasterxml.jackson.databind.JsonNode;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 |
8 | import java.io.FileInputStream;
9 | import java.io.FileNotFoundException;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 |
13 | public class Utils {
14 |
15 | public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
16 |
17 | public static ClientAndConfig getClientAndConfig(String[] args) {
18 | final String pathSeparator;
19 | String os = System.getProperty("os.name");
20 | if (os.toLowerCase().startsWith("win")) {
21 | pathSeparator = "\\";
22 | } else {
23 | pathSeparator = "/";
24 | }
25 |
26 | final InputStream inputStream;
27 | try {
28 | inputStream = new FileInputStream(System.getProperty("user.home") + pathSeparator + "tablestoreConf.json");
29 | } catch (FileNotFoundException e) {
30 | throw new RuntimeException(e);
31 | }
32 | // parse config in config file
33 | JsonNode config;
34 | try {
35 | config = OBJECT_MAPPER.readTree(inputStream);
36 | } catch (IOException e) {
37 | throw new RuntimeException(e);
38 | } finally {
39 | IOUtils.safeClose(inputStream);
40 | }
41 |
42 | SyncClient syncClient = new SyncClient(
43 | config.get("endpoint").asText(),
44 | config.get("accessId").asText(),
45 | config.get("accessKey").asText(),
46 | config.get("instanceName").asText()
47 | );
48 | return new ClientAndConfig(
49 | config.path("table").asText("order"),
50 | config.path("index").asText("order_index"),
51 | syncClient,
52 | config.path("importDataCount").asInt(10_000_000));
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/feature/TableCopy/README.md:
--------------------------------------------------------------------------------
1 | ## TableCopy
2 | Copy TableStore table data to other table via Tunnel Service.
3 |
4 | ## SampleCode
5 | [TableCopySample](src/main/java/com/aliyun/tablestore/examples/tablecopy/TableCopySample.java)
6 |
--------------------------------------------------------------------------------
/feature/TableCopy/src/main/java/com/aliyun/tablestore/examples/tablecopy/util/OtsBaseConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.tablecopy.util;
2 |
3 | public class OtsBaseConfig {
4 | private String endpoint;
5 | private String instanceName;
6 | private String tableName;
7 | private String accessId;
8 | private String accessKey;
9 |
10 | public String getEndpoint() {
11 | return endpoint;
12 | }
13 |
14 | public String getInstanceName() {
15 | return instanceName;
16 | }
17 |
18 | public String getTableName() {
19 | return tableName;
20 | }
21 |
22 | public String getAccessId() {
23 | return accessId;
24 | }
25 |
26 | public String getAccessKey() {
27 | return accessKey;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/feature/TableCopy/src/main/java/com/aliyun/tablestore/examples/tablecopy/util/OtsReaderConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.tablecopy.util;
2 |
3 | import java.text.DateFormat;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Date;
6 |
7 | public class OtsReaderConfig extends OtsBaseConfig {
8 | private String tunnelName;
9 | private String endTime;
10 |
11 | public String getTunnelName() {
12 | return tunnelName;
13 | }
14 |
15 | public long getEndTime() {
16 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
17 | try {
18 | Date date = df.parse(endTime);
19 | return date.getTime();
20 | } catch (Exception e) {
21 | e.printStackTrace();
22 | }
23 | return 0;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/feature/TableCopy/src/main/java/com/aliyun/tablestore/examples/tablecopy/util/OtsWriterConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.tablecopy.util;
2 |
3 | public class OtsWriterConfig extends OtsBaseConfig {
4 | private int batchWriteCount;
5 |
6 | public int getBatchWriteCount() {
7 | return batchWriteCount;
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/feature/TableCopy/src/main/java/com/aliyun/tablestore/examples/tablecopy/util/TableCopyConfig.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.examples.tablecopy.util;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.InputStreamReader;
5 | import java.io.Reader;
6 |
7 | import com.google.gson.Gson;
8 | import com.google.gson.annotations.SerializedName;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | public class TableCopyConfig {
13 | private static final Logger LOG = LoggerFactory.getLogger(TableCopyConfig.class);
14 |
15 | @SerializedName("ots-reader")
16 | private OtsReaderConfig readConf;
17 |
18 | @SerializedName("ots-writer")
19 | private OtsWriterConfig writeConf;
20 |
21 | public static TableCopyConfig loadConfig(String path) {
22 | try {
23 | Reader reader = new InputStreamReader((new FileInputStream(path)));
24 | TableCopyConfig config = new Gson().fromJson(reader, TableCopyConfig.class);
25 | System.out.println(config);
26 | LOG.debug("Config: ", config);
27 | return config;
28 | } catch (Exception e) {
29 | e.printStackTrace();
30 | throw new RuntimeException("invalid config file");
31 | }
32 | }
33 |
34 | public OtsReaderConfig getReadConf() {
35 | return readConf;
36 | }
37 |
38 | public OtsWriterConfig getWriteConf() {
39 | return writeConf;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return new Gson().toJson(this);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/feature/TableCopy/src/main/resources/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "ots-reader": {
3 | "endpoint": "https://zhuoran-high.cn-hangzhou.ots.aliyuncs.com",
4 | "instanceName": "zhuoran-high",
5 | "tableName": "test_table",
6 | "accessId": "",
7 | "accessKey": "",
8 | "tunnelName": "testTunnel2",
9 | "endTime": "2019-06-19 20:22:00"
10 | },
11 | "ots-writer": {
12 | "endpoint": "https://zhuoran-search.cn-hangzhou.ots.aliyuncs.com",
13 | "instanceName": "zhuoran-search",
14 | "tableName": "testDstTable2",
15 | "accessId": "",
16 | "accessKey": "",
17 | "batchWriteCount": 100
18 | }
19 | }
--------------------------------------------------------------------------------
/feature/TableCopy/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 | %d %p %c{1.} [%t] %m%n
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/README.md:
--------------------------------------------------------------------------------
1 | # Tablestore Spark Demo
2 |
3 | ## Prepare
4 | You can just run below command, detail see at the shell script:
5 | ```shell
6 | sh install.sh
7 | ```
8 |
9 | Or, you can run the separate steps:
10 |
11 | 1.`cd TableStoreSparkDemo`
12 |
13 | 2.Install tablestore spark connector preview version: `2.2.0-SNAPSHOT`
14 | > **Attention**: Later would support in stable maven version, e.g. 2.2.0
15 |
16 | ```
17 | mvn install:install-file -Dfile=libs/emr-tablestore-2.2.0-SNAPSHOT.jar -DartifactId=emr-tablestore -DgroupId=com.aliyun.emr -Dversion=2.2.0-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
18 | ```
19 |
20 | ## Provided examples
21 | We prepared two categories: Batch and Structured streaming examples.
22 |
23 | - Batch
24 | - TableStoreBatchSample: Quick start.
25 | - TableStoreSearchIndexSample: Spark With SearchIndex.
26 | - TableStoreSinkSample: Table copy via spark.
27 |
28 | - Structured Streaming
29 | - StructuredTableStoreAggSample: Quick start with dataset functions.
30 | - StructuredTableStoreAggSQLSample: Quick start with streaming sql.
31 | - StructuredTableStoreSinkSample: An real time aggregate example, sink to Tablestore.
32 |
33 | ## Run sample
34 | Assuming the sample code has been rewritten, e.g. `com.aliyun.tablestore.spark.demo.batch.TableStoreBatchSample`.
35 |
36 | ### Run in local IDE
37 | 1. In program arguements, fill contents with ` `
38 | 2. Selected `include dependencies with "provided" scope`.
39 | 3. Run the program.
40 |
41 | 
42 |
43 | ### Run in spark cluster
44 | 1. Packaging: `mvn -U clean package`, package locate at `target/tablestore-spark-demo-1.0-SNAPSHOT-jar-with-dependencies.jar`.
45 | 2. Upload the package to driver node of spark cluster.
46 | 3. Run the program with `spark-submit`, e.g.
47 |
48 | ```
49 | spark-submit --class com.aliyun.tablestore.spark.demo.batch.TableStoreBatchSample --master yarn tablestore-spark-demo-1.0-SNAPSHOT-jar-with-dependencies.jar
50 | ```
51 |
52 | 
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/install.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | # shellcheck disable=SC2046
3 | # shellcheck disable=SC2006
4 | cd `dirname "$0"` || exit
5 |
6 | # Install tablestore spark connector preview version
7 | mvn install:install-file -Dfile=libs/emr-tablestore-2.2.0-SNAPSHOT.jar -DartifactId=emr-tablestore -DgroupId=com.aliyun.emr -Dversion=2.2.0-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
8 |
9 |
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/libs/emr-tablestore-2.2.0-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aliyun/tablestore-examples/68031b86a68a0c446ae88c4057f151b89b053dad/feature/TableStoreSparkDemo/libs/emr-tablestore-2.2.0-SNAPSHOT.jar
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/pic/batch_cluster.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aliyun/tablestore-examples/68031b86a68a0c446ae88c4057f151b89b053dad/feature/TableStoreSparkDemo/pic/batch_cluster.png
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/pic/batch_local.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aliyun/tablestore-examples/68031b86a68a0c446ae88c4057f151b89b053dad/feature/TableStoreSparkDemo/pic/batch_local.png
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/pic/stream_local.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aliyun/tablestore-examples/68031b86a68a0c446ae88c4057f151b89b053dad/feature/TableStoreSparkDemo/pic/stream_local.png
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/pic/streaming_cluster.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aliyun/tablestore-examples/68031b86a68a0c446ae88c4057f151b89b053dad/feature/TableStoreSparkDemo/pic/streaming_cluster.png
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/src/main/resources/META-INF.services/org.apache.spark.sql.sources.DataSourceRegister:
--------------------------------------------------------------------------------
1 | org.apache.spark.sql.aliyun.tablestore.TableStoreSourceProvider
--------------------------------------------------------------------------------
/feature/TableStoreSparkDemo/src/main/scala/com/aliyun/tablestore/spark/demo/batch/TableStoreSearchIndexSample.scala:
--------------------------------------------------------------------------------
1 | package com.aliyun.tablestore.spark.demo.batch
2 |
3 | import com.aliyun.openservices.tablestore.hadoop.TableStore
4 | import org.apache.spark.internal.Logging
5 | import org.apache.spark.sql.SparkSession
6 |
7 |
8 | object TableStoreSearchIndexSample extends Logging {
9 | val appName: String = this.getClass.getSimpleName.filterNot(_.equals('$'))
10 |
11 | val sparkSession: SparkSession = SparkSession.builder
12 | .appName(appName)
13 | .master("local[*]")
14 | .getOrCreate()
15 |
16 | def main(args: Array[String]): Unit = {
17 | if (args.length < 5) {
18 | System.err.println(
19 | s"Usage: $appName " +
20 | " "
21 | )
22 | }
23 |
24 | val Array(
25 | instanceName,
26 | tableName,
27 | searchIndexName,
28 | accessKeyId,
29 | accessKeySecret,
30 | endpoint
31 | ) = args
32 |
33 | sparkSession.sparkContext.setLogLevel("INFO")
34 |
35 | val df = sparkSession.read
36 | .format("tablestore")
37 | .schema("salt LONG, UserId STRING, OrderId STRING, price DOUBLE, timestamp LONG")
38 | .option("instance.name", instanceName)
39 | .option("table.name", tableName)
40 | .option("endpoint", endpoint)
41 | .option("access.key.id", accessKeyId)
42 | .option("access.key.secret", accessKeySecret)
43 | .option("search.index.name", searchIndexName) // lead to use SearchIndex
44 | .load()
45 |
46 | println("With DataFrame")
47 | df.filter("salt = 1 AND UserId = 'user_A'").show(20, truncate = false)
48 |
49 | println("With Spark SQL")
50 | df.createTempView("search_view")
51 | val searchDF = sparkSession.sql("SELECT COUNT(*) FROM search_view WHERE salt = 1 AND UserId = 'user_A'")
52 | searchDF.show()
53 |
54 | // when all finished, shutdown executors.
55 | TableStore.shutdown()
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/image/QRcode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aliyun/tablestore-examples/68031b86a68a0c446ae88c4057f151b89b053dad/image/QRcode.png
--------------------------------------------------------------------------------
/tools/Datax-MySQL2TableStore/README.md:
--------------------------------------------------------------------------------
1 | # How to export data from MySQL and load into Tablestore by DataX
2 |
3 | 1. Download source code or compressed software package
4 |
5 | After getting your git environment configured, open your terminal to get source code from:
6 |
7 | git clone https://github.com/alibaba/DataX.git
8 |
9 | Or you can download DataX software package directly by the link below:
10 |
11 | http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz
12 |
13 |
14 |
15 | 2. Compile the source code
16 |
17 | After getting source code from step 1, compile it to get executable files:
18 |
19 | mvn -U clean package assembly:assembly -Dmaven.test.skip=true
20 |
21 | Or if you download Datax software directly, just uncompress it.
22 |
23 |
24 |
25 | 3. Prepare a json file
26 |
27 | If you need to export data from MySQL and load into Tabelstore, a configuration file in json format is needed.
28 |
29 | Please refer to [mysql_to_ots.json](http://gitlab.alibaba-inc.com/ots/tablestore-examples/blob/guangtian/MySQL2TablestoreByDatax/tools/Datax-MySQL2TableStore/mysql_to_ots.json)
30 |
31 |
32 |
33 | 4. Start to export and import
34 |
35 | After get you configuration file prepared in step 3, just start via command:
36 |
37 | python datax.py -j"-Xms4g -Xmx4g" mysql_to_ots.json
38 |
39 |
--------------------------------------------------------------------------------
/tools/Datax-MySQL2TableStore/mysql_to_ots.json:
--------------------------------------------------------------------------------
1 | {
2 | "core": {
3 | "transport": {
4 | "channel": {
5 | "speed": {
6 | "record": 5000,
7 | "byte": 102400
8 | }
9 | }
10 | }
11 | },
12 |
13 |
14 | "job": {
15 | "setting": {
16 | "speed": {
17 | "record": 100000
18 | },
19 | "errorLimit": {
20 | "record": 0,
21 | "percentage": 0.02
22 | }
23 | },
24 | "content": [
25 | {
26 | "reader": {
27 | "name": "mysqlreader",
28 | "parameter": {
29 | "username": "username",
30 | "password": "password",
31 | "column": [
32 | "bucket_name",
33 | "timestamp" ,
34 | "delta" ,
35 | "cdn_in",
36 | "cdn_out" ,
37 | "total_request"
38 | ],
39 |
40 | "connection": [
41 | {
42 |
43 | "table": [
44 | "vip_quota"
45 | ],
46 | "jdbcUrl": ["jdbc:mysql://rm-tatchiji-daily.mysql.xxx.tbsite.net:3306/oss_daily"
47 | ]
48 | }
49 | ]
50 | }
51 | },
52 |
53 | "writer": {
54 | "name": "otswriter",
55 | "parameter": {
56 | "endpoint":"https://smoke-test-gov.xxx.ots.aliyuncs.com",
57 | "accessId":"accessid",
58 | "accessKey":"accesskey",
59 | "instanceName":"smoke-test-gov",
60 | "table":"vip_quota",
61 | "primaryKey":[
62 | {"name":"bucket_name", "type":"string"},
63 | {"name":"delta", "type":"int"},
64 | {"name":"timestamp", "type":"int"}
65 | ],
66 | "column":[
67 | {"name":"haha","type":"int"},
68 | {"name":"hahah","type":"int"},
69 | {"name":"kengdie","type":"int"}
70 | ],
71 | "writeMode":"UpdateRow",
72 | "batchWriteCount":100
73 | }
74 | }
75 |
76 | }
77 | ]
78 | }
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/tools/Dts-MySQL2TableStore/README.md:
--------------------------------------------------------------------------------
1 | ## 项目简单描述
2 | + 该项目主要为阿里云DTS数据订阅SDK的简单Demo演示,包含如下:
3 | + 如何使用公网Maven依赖获取指定二方jar包,详情参考pom.xml
4 | + 如何使用properties或者xml的形式配置log4j日志输出,详情参考log4j.properties/log4j.xml,其他日志框架请自行查询资料配置
5 | + 如何使用SDK编写代码获取增量消息
6 |
7 | ## 开发环境以及其他依赖
8 | + JDK 1.6+
9 | + Maven 3.2+
10 | + Eclipse / InteliJ IDEA / 其他IDE
11 | + 项目依赖的Maven: [最新版本查询](http://search.maven.org/#search%7Cga%7C1%7Ccom.aliyun.dts)
12 |
13 | ```
14 |
15 | com.aliyun.dts
16 | dts-subscribe-sdk
17 | 4.6.27.12.0
18 |
19 | ```
20 |
21 | ## 如何编译、运行、使用示例项目
22 | + 如果使用eclipse开发,建议使用如下命令将工程初始化成Eclipse项目,可直接IDE中本地调试
23 | - mvn eclipse:eclipse
24 | + 配置日志输出文件,log4j.properties和log4j.xml两种形式保留一个文件即可,将另一个文件重命名即可
25 | + 打包成可执行的jar包:
26 | - mvn clean assembly:assembly -Dmaven.test.skip=true
27 | - 或者 mvn clean package -Dmaven.test.skip=true
28 | + 运行命令:
29 | - cd target && java -jar demo-1.0-SNAPSHOT-jar-with-dependencies.jar --accessKey ${accessKey} --accessSecret ${accessSecret} --subscribeInstanceID ${subscribeInstanceID}
30 |
31 | ## dts-subscribe-cli.jar工具使用
32 | + 该工具为示例代码打包编译后的jar包,是一个独立的消费客户端,需使用accessKey/accessSecret/guid参数获取DTS增量数据
33 | + usage:java -jar dts-subscribe-cli.jar --accessKey ${accessKey} --accessSecret ${accessSecret} --subscribeInstanceID ${subscribeInstanceID}
--------------------------------------------------------------------------------
/tools/Dts-MySQL2TableStore/src/main/java/com/aliyun/dts/demo/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.dts.demo.utils;
2 |
3 | import com.alicloud.openservices.tablestore.SyncClient;
4 | import com.alicloud.openservices.tablestore.core.utils.IOUtils;
5 | import com.fasterxml.jackson.databind.JsonNode;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 |
8 | import java.io.FileInputStream;
9 | import java.io.FileNotFoundException;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 |
13 | /**
14 | * @author hydrogen
15 | */
16 | public class Utils {
17 |
18 | public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
19 |
20 | public static JsonNode getClientAndConfig() {
21 | final String pathSeparator;
22 | String os = System.getProperty("os.name");
23 | if (os.toLowerCase().startsWith("win")) {
24 | pathSeparator = "\\";
25 | } else {
26 | pathSeparator = "/";
27 | }
28 |
29 | final InputStream inputStream;
30 | try {
31 | inputStream = new FileInputStream(System.getProperty("user.home") + pathSeparator + "tablestoreConf.json");
32 | } catch (FileNotFoundException e) {
33 | throw new RuntimeException(e);
34 | }
35 | // parse config in config file
36 | JsonNode config;
37 | try {
38 | config = OBJECT_MAPPER.readTree(inputStream);
39 | } catch (IOException e) {
40 | throw new RuntimeException(e);
41 | } finally {
42 | IOUtils.safeClose(inputStream);
43 | }
44 | return config;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/tools/Dts-MySQL2TableStore/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=INFO,CONSOLE
2 |
3 | ## 日志输出到控制台
4 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
5 | log4j.appender.CONSOLE.Threshold=INFO
6 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
7 | log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5p] [%t] [%c:%L] - %m%n
8 |
9 | ## 配置SDK中com.aliyun.drc包下的日志输出到dts-subscribe.log文件
10 | log4j.logger.com.aliyun.drc=INFO,file
11 | log4j.additivity.com.aliyun.drc=true
12 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
13 | log4j.appender.file.Threshold=INFO
14 | log4j.appender.file.Append=true
15 | log4j.appender.file.File=dts-subscribe.log
16 | log4j.appender.file.layout=org.apache.log4j.PatternLayout
17 | log4j.appender.file.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5p] [%t] [%c:%L] - %m%n
--------------------------------------------------------------------------------
/tools/Dts-MySQL2TableStore/src/main/resources/log4j.xml.bak:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------