#### This library enables you to interact with DAL service to save and load your data

#### publish:

```shell
python setup.py sdist bdist_wheel
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

```

#### install: `pip install apeman-dal-client==0.1.0`

#### How to use

```shell
export apeman_dal_server_addr='localhost:9090'
```

##### Create Datafeed

```python
from apeman.dal.tsdb.enum import DataAmount
from apeman.dal.tsdb.enum import DataType
from apeman.dal.tsdb.tsdb_client import ApemanDalTsdbClient
from apeman.dal.tsdb.proto_builder import ColumnDefinitionBuilder, CreateDatafeedRequestBuilder, \
    DataAmountBuilder, DataTypeBuilder, UniqueKeyBuilder

# build create datafeed request
tag = ColumnDefinitionBuilder() \
            .set_name(name='tag_nae') \
            .set_non_null(non_null=True) \
            .set_type(data_type=DataTypeBuilder().set_type(DataType.TEXT).build()) \
            .set_limit(limit=100).build()

field = ColumnDefinitionBuilder() \
            .set_name(name='field_name') \
            .set_non_null(non_null=True) \
            .set_type(data_type=DataTypeBuilder().set_type(DataType.TEXT).build()) \
            .set_limit(limit=100).build()

unique_key = UniqueKeyBuilder().set_name('tag_name').build()
unique_key_2 = UniqueKeyBuilder().set_name('field_name').build()

data_amount = DataAmountBuilder().set_data_amount(DataAmount.BIG).build()

create_datafeed_request = CreateDatafeedRequestBuilder() \
            .set_name(name='test') \
            .add_tag(tag=tag) \
            .add_field(field=field) \
            .add_unique_key(unique_key=unique_key) \
            .add_unique_key(unique_key=unique_key_2) \
            .set_data_amount(data_amount=data_amount) \
            .build()

client = ApemanDalTsdbClient()
# create datafeed
client.create_datafeed(request=create_datafeed_request)

#

```
##### Delete Datafeed

```python
from apeman.dal.tsdb.tsdb_client import ApemanDalTsdbClient

client = ApemanDalTsdbClient()
# delete datafeed
client.delete_datafeed(datafeed='test')
```

##### Get Datafeed

```python
from apeman.dal.tsdb.tsdb_client import ApemanDalTsdbClient

client = ApemanDalTsdbClient()
# delete datafeed
client.get_datafeed(datafeed='test')
```

##### List Datafeed

```python
from apeman.dal.tsdb.tsdb_client import ApemanDalTsdbClient

client = ApemanDalTsdbClient()
# delete datafeed
client.list_datafeed(query_filter='')
```

##### Put Data

```python
from apeman.dal.tsdb.tsdb_client import ApemanDalTsdbClient
from apeman.dal.tsdb.enum import DataType
from apeman.dal.tsdb.proto_builder import TabularDataBuilder, ColumnMetaBuilder, DataTypeBuilder, TupleBuilder, ValBuilder

client = ApemanDalTsdbClient()

column_a = ColumnMetaBuilder()  \
                .set_name(name='column_a') \
                .set_data_type(DataTypeBuilder() \
                .set_type(DataType.TEXT).build()) \
                .build()
column_b = ColumnMetaBuilder()  \
                .set_name(name='column_b')  \
                .set_data_type(DataTypeBuilder() \
                .set_type(DataType.TEXT).build()) \
                .build()

tuple_a = TupleBuilder() \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .build()

tuple_b = TupleBuilder() \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .add_val(val = ValBuilder().set_i32(1000).build()) \
                .build()

data = TabularDataBuilder()  \
                .add_column(column_a) \
                .add_column(column_b) \ 
                .add_tuple(tuple=tuple_a) \
                .add_tuple(tuple=tuple_b) \
                .build()

client.put_data(datafeed='test', data=data)
```

##### Get Data

```python
from apeman.dal.tsdb.tsdb_client import ApemanDalTsdbClient
from apeman.dal.tsdb.enum import DataType
from apeman.dal.tsdb.proto_builder import TabularDataBuilder, ColumnMetaBuilder,  \
      DataTypeBuilder, GetDataRequestBuilder

client = ApemanDalTsdbClient()

column_a = ColumnMetaBuilder()  \
                .set_name(name='column_a')  \
                .set_data_type(
                    DataTypeBuilder() \
                        .set_type(DataType.TEXT).build()
                 ) \
                .build()
column_b = ColumnMetaBuilder()  \
                .set_name(name='column_b') \
                .set_data_type(
                    DataTypeBuilder() \
                        .set_type(DataType.TEXT).build()
                )  \
                .build()

request = GetDataRequestBuilder()  \
                .add_column(column=column_a)  \
                .add_column(column_b)  \
                .set_datafeed(datafeed='test')  \
                .set_where(where='')  \
                .set_group_by(group_by='')  \
                .set_having(having='')  \
                .set_order_by(order_by='')  \
                .set_offset(offset=0)  \
                .set_limit(limit=100)  \
                .build()

data = TabularDataBuilder()  \
                .add_column(column_a)  \
                .add_column(column_b).build()

client.get_data(request=request)
```
