本文介绍如何使用TableStore数据源进行数据分析或者交互式开发。

建表语法

CREATE TABLE tbName
USING tablestore
OPTIONS(propertyName=propertyValue[,propertyName=propertyValue]*);

Table Schema

创建TableStore表时,无需显式定义表的字段信息,示例如下。
CREATE DATABASE IF NOT EXISTS default;
USE default;
DROP TABLE IF EXISTS ots_table_test;
CREATE TABLE ots_table_test
USING tablestore
OPTIONS(
        endpoint="http://xxx.cn-hangzhou.vpc.ots.aliyuncs.com",
        access.key.id="yHiu*******BG2s",
        access.key.secret="ABctuw0M***************iKKljZy",
        table.name="test",
        instance.name="myInstance",
        batch.update.size="100",
        catalog='{"columns":{"pk":{"col":"pk","type":"string"},"data":{"col":"data","type":"string"}}}');

DESC ots_table_test;
pk  string  NULL
data  string  NULL
Time taken: 0.501 seconds, Fetched 2 row(s)

配置参数说明

参数 描述
access.key.id 阿里云AccessKey ID。
access.key.secret 阿里云AccessKey Secret。
endpoint TableStore API Endpoint。
table.name TableStore的表名。
instance.name TableStore的实例名。
batch.update.size 表示每次向TableStore批量更新的数据条数,默认为0表示逐条更新。

仅向数据库写入数据时生效。

catalog TableStore表字段说明,JSON格式。
本示例定义了一个TableStore表table1的Schema,Catalog配置示例如下所示。
{"columns":{
  "col0":{"cf":"cf0", "col":"col0", "type":"string"},
  "col1":{"cf":"cf1", "col":"col1", "type":"boolean"},
  "col2":{"cf":"cf2", "col":"col2", "type":"double"},
  "col3":{"cf":"cf3", "col":"col3", "type":"float"},
  "col4":{"cf":"cf4", "col":"col4", "type":"int"},
  "col5":{"cf":"cf5", "col":"col5", "type":"bigint"},
  "col6":{"cf":"cf6", "col":"col6", "type":"smallint"},
  "col7":{"cf":"cf7", "col":"col7", "type":"string"},
  "col8":{"cf":"cf8", "col":"col8", "type":"tinyint"}
}