OtsClient

Struct OtsClient 

Source
pub struct OtsClient { /* private fields */ }
Expand description

客户端

Implementations§

Source§

impl OtsClient

Source

pub fn from_env() -> Self

Build an OtsClient from env values. The following env vars are required:

  • ALIYUN_OTS_AK_ID: The access key id.
  • ALIYUN_OTS_AK_SEC: The access key secret
  • ALIYUN_OTS_ENDPOINT: The tablestore instance endpoint. e.g. https://${instance-name}.cn-beijing.ots.aliyuncs.com
Source

pub fn new( ak_id: impl AsRef<str>, ak_sec: impl AsRef<str>, endpoint: impl AsRef<str>, ) -> Self

使用 AK_ID、AK_SEC 和网络访问地址构建实例

§Arguments
  • ak_id: Access key id
  • ak_sec: Access key secret
  • endpoint: 服务地址
Source

pub fn builder( ak_id: impl AsRef<str>, ak_sec: impl AsRef<str>, ) -> OtsClientBuilder

客户端构建器

§Arguments
  • ak_id: Access key id
  • ak_sec: Access key secret
Source

pub async fn send(&self, req: OtsRequest) -> OtsResult<Response>

发送请求

Source

pub fn list_table(&self) -> ListTableOperation

列出实例下的宽表

Source

pub fn create_table(&self, request: CreateTableRequest) -> CreateTableOperation

创建一个宽表

§Examples
let req = CreateTableRequest::new("users")
    .primary_key_string("user_id_part")
    .primary_key_string("user_id")
    .column_string("full_name")
    .column_string("phone_number")
    .column_string("pwd_hash")
    .column_string("badge_no")
    .column_string("gender")
    .column_integer("registered_at_ms")
    .column_bool("deleted")
    .column_integer("deleted_at_ms")
    .column_double("score")
    .column_blob("avatar")
    .index(
        IndexMetaBuilder::new("idx_phone_no")
            .primary_key("user_id_part")
            .defined_column("phone_number")
            .index_type(IndexType::ItGlobalIndex)
            .build(),
    );
let response = client.create_table(req).send().await;
Source

pub fn update_table(&self, request: UpdateTableRequest) -> UpdateTableOperation

更新宽表定义

Source

pub fn describe_table(&self, table_name: &str) -> DescribeTableOperation

获取宽表定义

Source

pub fn delete_table(&self, table_name: &str) -> DeleteTableOperation

删除宽表

Source

pub fn compute_split_points_by_size( &self, request: ComputeSplitPointsBySizeRequest, ) -> ComputeSplitPointsBySizeOperation

计算宽表分裂点

Source

pub fn add_defined_column( &self, request: AddDefinedColumnRequest, ) -> AddDefinedColumnOperation

添加预定义列

§Examples
let response = client
    .add_defined_column(
        AddDefinedColumnRequest::new("ccs")
            .column_integer("created_at")
            .column_string("cover_url")
            .column_double("avg_score"),
    )
    .send()
    .await;
Source

pub fn delete_defined_column( &self, request: DeleteDefinedColumnRequest, ) -> DeleteDefinedColumnOperation

删除预定义列

§Example
let response = client
    .delete_defined_column(DeleteDefinedColumnRequest::new("ccs").column("created_at"))
    .send()
    .await;
Source

pub fn get_row(&self, request: GetRowRequest) -> GetRowOperation

根据主键获取单行数据

§Examples
let response = client
    .get_row(
        GetRowRequest::new("schools")
            .primary_key_string("school_id", "00020FFB-BB14-CCAD-0181-A929E71C7312")
            .primary_key_integer("id", 1742203524276000)
            .max_versions(1),
    )
    .send()
    .await;
Source

pub fn get_range(&self, request: GetRangeRequest) -> GetRangeOperation

根据主键获取范围数据

§Examples
§依次设置开始主键和结束主键
let response = client.get_range(
    GetRangeRequest::new("table_name")
        .start_primary_key_string("id", "string_id_value")
        .start_primary_key_inf_min("long_id")
        .end_primary_key_string("id", "string_id_value")
        .end_primary_key_inf_max("long_id")
        .direction(Direction::Forward)
).send().await;
§依次设置每个主键的开始和结束值
let response = client.get_range(
    GetRangeRequest::new("table_name").primary_key_range(
        "id",
        PrimaryKeyValue::String("string_id_value".to_string()),
        PrimaryKeyValue::String("string_id_value".to_string())
    ).primary_key_range(
        "long_id",
        PrimaryKeyValue::Integer(12345678),
        PrimaryKeyValue::InfMax
    ).direction(Direction::Forward)
).send().await;
Source

pub fn put_row(&self, request: PutRowRequest) -> PutRowOperation

插入一行数据

§Examples
let row = Row::default()
    .primary_key_string("school_id", &school_id)
    .primary_key_auto_increment("id")
    .column_string("name", Name(ZH_CN).fake::<String>())
    .column_string("province", Name(ZH_CN).fake::<String>());

let response = client
    .put_row(
        PutRowRequest::new("schools").row(row).return_type(ReturnType::RtPk)
    ).send().await.unwrap();
Source

pub fn update_row(&self, request: UpdateRowRequest) -> UpdateRowOperation

更新一行数据

§Examples
let response = client
    .update_row(
        UpdateRowRequest::new(table_name)
            .row(
                Row::new()
                    .primary_key_string("str_id", &id)
                    .column_string("str_col", "b")
                    .column_to_increse("int_col", 1)
                    .column_bool("bool_col", true)
                    .column_to_delete_all_versions("blob_col"),
            )
            .return_type(ReturnType::RtPk),
    )
    .send()
    .await;
Source

pub fn delete_row(&self, request: DeleteRowRequest) -> DeleteRowOperation

根据主键删除数据行

§Examples
client.delete_row(
    DeleteRowRequest::new(table_name).primary_key_string("str_id", &id)
).send().await;
Source

pub fn batch_get_row(&self, request: BatchGetRowRequest) -> BatchGetRowOperation

批量读取一个表或多个表中的若干行数据

§Examples
let client = OtsClient::from_env();

let t1 = TableInBatchGetRowRequest::new("data_types")
    .primary_key(
        PrimaryKey::new().column_string("str_id", "1")
    ).primary_key(
        PrimaryKey::new().column_string("str_id", "02421870-56d8-4429-a548-27e0e1f42894")
    );

let t2 = TableInBatchGetRowRequest::new("schools").primary_key(
    PrimaryKey::new().column_string("school_id", "00020FFB-BB14-CCAD-0181-A929E71C7312")
        .column_integer("id", 1742203524276000)
);

let request = BatchGetRowRequest::new().tables(
    vec![t1, t2]
);

let res = client.batch_get_row(request).send().await;
Source

pub fn batch_write_row( &self, request: BatchWriteRowRequest, ) -> BatchWriteRowOperation

接口批量插入、修改或删除一个或多个表中的若干行数据。

§Examples
let client = OtsClient::from_env();

let uuid: String = UUIDv4.fake();

let t1 = TableInBatchWriteRowRequest::new("data_types").rows(vec![
    RowInBatchWriteRowRequest::put_row(
        Row::new()
            .primary_key_column_string("str_id", &uuid)
            .column_string("str_col", "column is generated from batch writing"),
    ),
    RowInBatchWriteRowRequest::delete_row(Row::new().primary_key_column_string("str_id", "266e79aa-eb74-47d8-9658-e17d52fc012d")),
    RowInBatchWriteRowRequest::update_row(
        Row::new()
            .primary_key_column_string("str_id", "975e9e17-f969-4387-9cef-a6ae9849a10d")
            .column_double("double_col", 11.234),
    ),
]);

let t2 = TableInBatchWriteRowRequest::new("schools").rows(vec![RowInBatchWriteRowRequest::update_row(
    Row::new()
        .primary_key_column_string("school_id", "2")
        .primary_key_column_integer("id", 1742378007415000)
        .column_string("name", "School-AAAA"),
)]);

let req = BatchWriteRowRequest::new().table(t1).table(t2);

let res = client.batch_write_row(req).send().await;
Source

pub fn bulk_import(&self, request: BulkImportRequest) -> BulkImportOperation

批量写入数据。写入数据时支持插入一行数据、修改行数据以及删除行数据。最多一次 200 行

§Examples
let client = OtsClient::from_env();
let mut req = BulkImportRequest::new("data_types");
for i in 0..200 {
    let id: String = UUIDv4.fake();
    let mut blob_val = [0u8; 16];
    rand::fill(&mut blob_val);
    let bool_val = i % 2 == 0;
    let double_val = rand::random_range::<f64, _>(0.0f64..99.99f64);
    let int_val = rand::random_range::<i64, _>(0..10000);
    let str_val: String = Name(ZH_CN).fake();
    let row = Row::new()
        .primary_key_column_string("str_id", &id)
        .column_blob("blob_col", blob_val)
        .column_bool("bool_col", bool_val)
        .column_double("double_col", double_val)
        .column_integer("int_col", int_val)
        .column_string("str_col", &str_val);
    req = req.put_row(row);
}
let res = client.bulk_import(req).send().await;
Source

pub fn bulk_export(&self, request: BulkExportRequest) -> BulkExportOperation

接口批量导出数据。

§Examples
let request = BulkExportRequest::new("data_types")
    .end_primary_key_column_inf_min("str_id")
    .end_primary_key_column_inf_max("str_id")
    .columns_to_get(["str_id", "str_col", "int_col", "double_col", "blob_col", "bool_col"]);

let res = client.bulk_export(request).send().await;
let res = res.unwrap();
total_rows += res.rows.len();

res.rows.iter().for_each(|r| {
    log::debug!("row: {:?}", r.get_primary_key_value("str_id").unwrap());
});
Source

pub fn create_index(&self, request: CreateIndexRequest) -> CreateIndexOperation

创建二级索引

Source

pub fn drop_index(&self, table_name: &str, idx_name: &str) -> DropIndexOperation

删除二级索引

Source

pub fn list_search_index( &self, table_name: Option<&str>, ) -> ListSearchIndexOperation

列出多元索引

Source

pub fn create_search_index( &self, request: CreateSearchIndexRequest, ) -> CreateSearchIndexOperation

创建多元索引

Source

pub fn describe_search_index( &self, table_name: &str, index_name: &str, ) -> DescribeSearchIndexOperation

查询多元索引描述信息

Source

pub fn update_search_index( &self, request: UpdateSearchIndexRequest, ) -> UpdateSearchIndexOperation

修改多元索引

Source

pub fn delete_search_index( &self, table_name: &str, index_name: &str, ) -> DeleteSearchIndexOperation

删除多元索引

Source

pub fn search(&self, request: SearchRequest) -> SearchOperation

通过多元索引查询数据

Source

pub fn compute_splits( &self, table_name: &str, index_name: &str, ) -> ComputeSplitsOperation

计算多元索引的并发度

Source

pub fn parallel_scan( &self, request: ParallelScanRequest, ) -> ParallelScanOperation

并行扫描

Source

pub fn get_timeseries_data( &self, request: GetTimeseriesDataRequest, ) -> GetTimeseriesDataOperation

时序表 - 查询数据

Source

pub fn put_timeseries_data( &self, request: PutTimeseriesDataRequest, ) -> PutTimeseriesDataOperation

时序表 - 写入数据

§Examples
let client = OtsClient::from_env();

let ts_us = (current_time_ms() * 1000) as u64;

let request = PutTimeseriesDataRequest::new("timeseries_demo_with_data")
    .row(
        TimeseriesRow::new()
            .measurement_name("measure_11")
            .datasource("data_11")
            .tag("cluster", "cluster_11")
            .tag("region", "region_11")
            .timestamp_us(ts_us)
            .field_integer("temp", 123),
    )
    .row(
        TimeseriesRow::new()
            .measurement_name("measure_11")
            .datasource("data_11")
            .tag("cluster", "cluster_11")
            .tag("region", "region_11")
            .timestamp_us(ts_us + 1000)
            .field_double("temp", 543.21),
    );

let resp = client.put_timeseries_data(request).send().await;
Source

pub fn create_timeseries_table( &self, request: CreateTimeseriesTableRequest, ) -> CreateTimeseriesTableOperation

时序表 - 创建时序表

Source

pub fn describe_timeseries_table( &self, table_name: &str, ) -> DescribeTimeseriesTableOperation

时序表 - 查询时序表信息

Source

pub fn list_timeseries_table(&self) -> ListTimeseriesTableOperation

时序表 - 列出时序表

Source

pub fn update_timeseries_table( &self, request: UpdateTimeseriesTableRequest, ) -> UpdateTimeseriesTableOperation

时序表 - 更新表配置

Source

pub fn delete_timeseries_table( &self, table_name: &str, ) -> DeleteTimeseriesTableOperation

时序表 - 删除时序表

Source

pub fn create_timeseries_lastpoint_index( &self, request: CreateTimeseriesLastpointIndexRequest, ) -> CreateTimeseriesLastpointIndexOperation

时序表 - 创建 lastpoint 索引

Source

pub fn delete_timeseries_lastpoint_index( &self, table_name: &str, index_name: &str, ) -> DeleteTimeseriesLastpointIndexOperation

时序表 - 删除 lastpoint 索引

Source

pub fn create_timeseries_analytical_store( &self, request: CreateTimeseriesAnalyticalStoreRequest, ) -> CreateTimeseriesAnalyticalStoreOperation

时序表 - 创建分析存储

Source

pub fn update_timeseries_analytical_store( &self, request: UpdateTimeseriesAnalyticalStoreRequest, ) -> UpdateTimeseriesAnalyticalStoreOperation

时序表 - 更新分析存储

Source

pub fn delete_timeseries_analytical_store( &self, request: DeleteTimeseriesAnalyticalStoreRequest, ) -> DeleteTimeseriesAnalyticalStoreOperation

时序表 - 删除分析存储

Source

pub fn describe_timeseries_analytical_store( &self, table_name: &str, store_name: &str, ) -> DescribeTimeseriesAnalyticalStoreOperation

时序表 - 查询分析存储的信息

Source

pub fn query_timeseries_meta( &self, request: QueryTimeseriesMetaRequest, ) -> QueryTimeseriesMetaOperation

时序表 - 查询元数据

Source

pub fn update_timeseries_meta( &self, request: UpdateTimeseriesMetaRequest, ) -> UpdateTimeseriesMetaOperation

时序表 - 更新时间线元数据

Source

pub fn delete_timeseries_meta( &self, request: DeleteTimeseriesMetaRequest, ) -> DeleteTimeseriesMetaOperation

时序表 - 删除时间线元数据

Source

pub fn split_timeseries_scan_task( &self, request: SplitTimeseriesScanTaskRequest, ) -> SplitTimeseriesScanTaskOperation

时序表 - 切分全量导出任务

Source

pub fn scan_timeseries_data( &self, request: ScanTimeseriesDataRequest, ) -> ScanTimeseriesDataOperation

时序表 - 扫描数据

Source

pub fn sql_query(&self, request: SqlQueryRequest) -> SqlQueryOperation

SQL 查询。注意:返回的行中,主键值和普通列的值都放到普通列 columns 或者 fields 中了。

§Examples
let client = OtsClient::from_env();
let req = SqlQueryRequest::new("select * from timeseries_demo_with_data where _m_name = 'measure_11'");
let resp = client.sql_query(req).send::<TimeseriesRow>().await;
log::debug!("timeseries table: {:?}", resp)

Trait Implementations§

Source§

impl Clone for OtsClient

Source§

fn clone(&self) -> OtsClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OtsClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T