Skip to content

Commit

Permalink
Merge pull request #62 from timeplus-io/feature/api-updates
Browse files Browse the repository at this point in the history
Feature/api updates
  • Loading branch information
gangtao authored Feb 14, 2023
2 parents 144f032 + 4472580 commit fbd30bd
Show file tree
Hide file tree
Showing 47 changed files with 1,031 additions and 159 deletions.
1 change: 0 additions & 1 deletion examples/1.0+/helloworld/ingest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import traceback
import json
import datetime
from pprint import pprint

Expand Down
2 changes: 0 additions & 2 deletions examples/1.0+/helloworld/ingest_json_stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import traceback
import json
import datetime
from pprint import pprint

from timeplus import Stream, Environment
Expand Down
2 changes: 0 additions & 2 deletions examples/1.0+/helloworld/ingest_lines.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import traceback
import json
import datetime
from pprint import pprint

from timeplus import Stream, Environment
Expand Down
2 changes: 0 additions & 2 deletions examples/1.0+/helloworld/ingest_raw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import traceback
import json
import datetime
from pprint import pprint

from timeplus import Stream, Environment
Expand Down
42 changes: 42 additions & 0 deletions examples/1.0+/helloworld/kv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import traceback
from pprint import pprint

from timeplus import Stream, Environment

api_key = os.environ.get("TIMEPLUS_API_KEY")
api_address = os.environ.get("TIMEPLUS_ADDRESS")

# Configure API key and address
env = Environment().address(api_address).apikey(api_key)
name = "testkv"

try:
# list all streams
stream_list = Stream(env=env).list()
pprint(f"there are {len(stream_list)} streams ")

# create a new stream
stream = (
Stream(env=env)
.name(name)
.column("id", "string")
.column("data", "string")
.mode("versioned_kv")
.primary_key("id")
.create()
)

stream_list = Stream(env=env).list()
pprint(f"there are {len(stream_list)} streams after create")
pprint(f"created stream is {stream.metadata()}; type is {type(stream.metadata())}")

a_stream = Stream(env=env).name(name).get()
pprint(f"get stream is {a_stream.metadata()} ; type is {type(a_stream.metadata())}")

# stream.delete()
stream_list = Stream(env=env).list()
pprint(f"there are {len(stream_list)} streams after delete")
except Exception as e:
pprint(e)
traceback.print_exc()
8 changes: 6 additions & 2 deletions examples/1.0+/helloworld/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
pprint(f"there are {len(query_list)} queries ")

# create a new query
query = Query(env=env).sql(query="SELECT * FROM iot").create()
query = (
Query(env=env).sql(query="SELECT * FROM iot")
# .batching_pilicy(1000, 1000)
.create()
)
query_id = query.metadata()["id"]
pprint(f"created a query with id {query_id}")

Expand All @@ -27,7 +31,7 @@
pprint(f"get a query with id {metadata['id']}")

# iterate query result
limit = 3
limit = 10
count = 0
for event in query.result():
print(event.event)
Expand Down
1 change: 0 additions & 1 deletion examples/1.0+/helloworld/stream.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import traceback
import json
from pprint import pprint

from timeplus import Stream, Environment
Expand Down
14 changes: 14 additions & 0 deletions python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM jupyter/base-notebook:python-3.9.10

ARG VERSION

WORKDIR /timeplus
ADD ./requirements.txt /timeplus
ADD ./dist/ /timeplus/
RUN pip3 install -r requirements.txt
RUN pip3 install /timeplus/timeplus-$VERSION.tar.gz

RUN rm /timeplus/requirements.txt
RUN rm /timeplus/timeplus-$VERSION*

EXPOSE 8888
2 changes: 1 addition & 1 deletion python/docs/APIKeysV1beta1Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swagger_client.APIKeysV1beta1Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
10 changes: 10 additions & 0 deletions python/docs/BatchingPolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# BatchingPolicy

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**count** | **int** | The max result count per batch | [optional]
**time_ms** | **int** | The max interval per batch in milliseconds | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

3 changes: 2 additions & 1 deletion python/docs/CreateQueryRequestV1Beta2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**batching_policy** | [**BatchingPolicy**](BatchingPolicy.md) | | [optional]
**description** | **str** | | [optional]
**name** | **str** | | [optional]
**sql** | **str** | | [optional]
**sql** | **str** | |
**tags** | **list[str]** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
2 changes: 1 addition & 1 deletion python/docs/DashboardsV1beta2Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swagger_client.DashboardsV1beta2Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
34 changes: 15 additions & 19 deletions python/docs/MetricsV1beta2Api.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# swagger_client.MetricsV1beta2Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
[**v1beta2_global_metrics_post**](MetricsV1beta2Api.md#v1beta2_global_metrics_post) | **POST** /v1beta2/global_metrics | query global metrics.
[**v1beta2_resource_metrics_post**](MetricsV1beta2Api.md#v1beta2_resource_metrics_post) | **POST** /v1beta2/resource_metrics | query resource metrics.
[**v1beta2_global_metrics_get**](MetricsV1beta2Api.md#v1beta2_global_metrics_get) | **GET** /v1beta2/global-metrics | query global metrics.
[**v1beta2_resource_metrics_get**](MetricsV1beta2Api.md#v1beta2_resource_metrics_get) | **GET** /v1beta2/resource-metrics | query resource metrics.

# **v1beta2_global_metrics_post**
> GlobalMetricsResult v1beta2_global_metrics_post(body)
# **v1beta2_global_metrics_get**
> GlobalMetricsResult v1beta2_global_metrics_get()
query global metrics.

Expand All @@ -30,21 +30,17 @@ configuration.api_key['X-Api-Key'] = 'YOUR_API_KEY'

# create an instance of the API class
api_instance = swagger_client.MetricsV1beta2Api(swagger_client.ApiClient(configuration))
body = swagger_client.InternalHttpHandlerV1beta2GlobalMetricsRequest() # InternalHttpHandlerV1beta2GlobalMetricsRequest | metrics query request parameters

try:
# query global metrics.
api_response = api_instance.v1beta2_global_metrics_post(body)
api_response = api_instance.v1beta2_global_metrics_get()
pprint(api_response)
except ApiException as e:
print("Exception when calling MetricsV1beta2Api->v1beta2_global_metrics_post: %s\n" % e)
print("Exception when calling MetricsV1beta2Api->v1beta2_global_metrics_get: %s\n" % e)
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**InternalHttpHandlerV1beta2GlobalMetricsRequest**](InternalHttpHandlerV1beta2GlobalMetricsRequest.md)| metrics query request parameters |
This endpoint does not need any parameter.

### Return type

Expand All @@ -56,13 +52,13 @@ Name | Type | Description | Notes

### HTTP request headers

- **Content-Type**: application/json
- **Content-Type**: Not defined
- **Accept**: application/json

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **v1beta2_resource_metrics_post**
> ResourceMetricsResult v1beta2_resource_metrics_post(body)
# **v1beta2_resource_metrics_get**
> ResourceMetricsResult v1beta2_resource_metrics_get(body)
query resource metrics.

Expand All @@ -84,21 +80,21 @@ configuration.api_key['X-Api-Key'] = 'YOUR_API_KEY'

# create an instance of the API class
api_instance = swagger_client.MetricsV1beta2Api(swagger_client.ApiClient(configuration))
body = swagger_client.InternalHttpHandlerV1beta2GlobalMetricsRequest() # InternalHttpHandlerV1beta2GlobalMetricsRequest | metrics query request parameters
body = swagger_client.ResourceMetricsRequest() # ResourceMetricsRequest | metrics query request parameters

try:
# query resource metrics.
api_response = api_instance.v1beta2_resource_metrics_post(body)
api_response = api_instance.v1beta2_resource_metrics_get(body)
pprint(api_response)
except ApiException as e:
print("Exception when calling MetricsV1beta2Api->v1beta2_resource_metrics_post: %s\n" % e)
print("Exception when calling MetricsV1beta2Api->v1beta2_resource_metrics_get: %s\n" % e)
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**InternalHttpHandlerV1beta2GlobalMetricsRequest**](InternalHttpHandlerV1beta2GlobalMetricsRequest.md)| metrics query request parameters |
**body** | [**ResourceMetricsRequest**](ResourceMetricsRequest.md)| metrics query request parameters |

### Return type

Expand Down
2 changes: 1 addition & 1 deletion python/docs/QueriesV1beta1Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swagger_client.QueriesV1beta1Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
19 changes: 10 additions & 9 deletions python/docs/QueriesV1beta2Api.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# swagger_client.QueriesV1beta2Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
[**v1beta2_queries_post**](QueriesV1beta2Api.md#v1beta2_queries_post) | **POST** /v1beta2/queries | execute a query.
[**v1beta2_queries_post**](QueriesV1beta2Api.md#v1beta2_queries_post) | **POST** /v1beta2/queries | execute a query and return the results.

# **v1beta2_queries_post**
> v1beta2_queries_post(body)
> Query v1beta2_queries_post(body)
execute a query.
execute a query and return the results.

execute a query.
Execute a query and return the results. * If the request fails, the response content type will be `application/json`. Please refer to the failure codes in Responses section below. * If the query is executed successfully, the response content type will be `text/event-stream`. **For SSE** There are 3 types of data that will be sent to SSE channel 1. Query (type `query`): The first event of the result will ALWAYS be this type. 2. Metrics (type `metrics`): The query metrics in JSON. They will be sent every 1 seconds. 3. Data (the type is empty): The query result.

### Example
```python
Expand All @@ -32,8 +32,9 @@ api_instance = swagger_client.QueriesV1beta2Api(swagger_client.ApiClient(configu
body = swagger_client.CreateQueryRequestV1Beta2() # CreateQueryRequestV1Beta2 | query request parameters

try:
# execute a query.
api_instance.v1beta2_queries_post(body)
# execute a query and return the results.
api_response = api_instance.v1beta2_queries_post(body)
pprint(api_response)
except ApiException as e:
print("Exception when calling QueriesV1beta2Api->v1beta2_queries_post: %s\n" % e)
```
Expand All @@ -46,7 +47,7 @@ Name | Type | Description | Notes

### Return type

void (empty response body)
[**Query**](Query.md)

### Authorization

Expand All @@ -55,7 +56,7 @@ void (empty response body)
### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json
- **Accept**: application/json, text/event-stream

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

12 changes: 12 additions & 0 deletions python/docs/ResourceMetricsRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ResourceMetricsRequest

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**metrics_names** | **list[str]** | | [optional]
**metrics_types** | **list[str]** | | [optional]
**resource_ids** | **list[str]** | | [optional]
**time_range** | **int** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

2 changes: 1 addition & 1 deletion python/docs/SinksV1beta1Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swagger_client.SinksV1beta1Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
2 changes: 1 addition & 1 deletion python/docs/SourcesV1beta1Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swagger_client.SourcesV1beta1Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
4 changes: 3 additions & 1 deletion python/docs/StreamDef.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ Name | Type | Description | Notes
**event_time_timezone** | **str** | | [optional]
**logstore_retention_bytes** | **int** | | [optional]
**logstore_retention_ms** | **int** | | [optional]
**name** | **str** | |
**mode** | **str** | | [optional]
**name** | **str** | Stream name should only contain a maximum of 64 letters, numbers, or _, and start with a letter |
**order_by_expression** | **str** | | [optional]
**order_by_granularity** | **str** | | [optional]
**partition_by_granularity** | **str** | | [optional]
**primary_key** | **str** | | [optional]
**replication_factor** | **int** | | [optional]
**shards** | **int** | | [optional]
**ttl_expression** | **str** | | [optional]
Expand Down
2 changes: 1 addition & 1 deletion python/docs/StreamsV1beta1Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swagger_client.StreamsV1beta1Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
1 change: 0 additions & 1 deletion python/docs/TimeColumns.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**event_time** | **int** | |
**index_time** | **int** | |
**window_end** | **int** | |
**window_start** | **int** | |

Expand Down
2 changes: 1 addition & 1 deletion python/docs/TopologyV1beta2Api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swagger_client.TopologyV1beta2Api

All URIs are relative to *//beta.timeplus.cloud/{workspace-id}/api*
All URIs are relative to *//us.timeplus.cloud/{workspace-id}/api*

Method | HTTP request | Description
------------- | ------------- | -------------
Expand Down
8 changes: 5 additions & 3 deletions python/docs/UDF.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**arguments** | [**list[UDFArgument]**](UDFArgument.md) | | [optional]
**arguments** | [**list[UDFArgument]**](UDFArgument.md) | The input argument of the UDF * For UDA: the number and type of arguments should be consistent with the main function of UDA. the type should be the data types of proton not javascript types. It only supports int8/16/32/64, uint8/16/32/64, | [optional]
**auth_context** | [**UDFAuthContext**](UDFAuthContext.md) | | [optional]
**auth_method** | **str** | | [optional]
**created_at** | **str** | | [optional]
**created_by** | [**Owner**](Owner.md) | | [optional]
**description** | **str** | | [optional]
**is_aggregation** | **bool** | Whether it is an aggregation function. Only valid when type is 'javascript' | [optional]
**last_updated_at** | **str** | | [optional]
**last_updated_by** | [**Owner**](Owner.md) | | [optional]
**name** | **str** | | [optional]
**return_type** | **str** | | [optional]
**type** | **str** | | [optional]
**return_type** | **str** | The erturn type of the UDF * For UDA: if it returns a single value, the return type is the corresponding data type of Timeplus. It supports the same types of input arguments, except for datetime, it only supports DateTime64(3). | [optional]
**source** | **str** | The source code of the UDA. There are functions to be defined: * main function: with the same name as UDA. Timeplus calls this function for each input row. The main function can return two types of result: object or simple data type - If it returns an object, the object is like {“emit”: true, “result”: …}. ‘Emit’ (boolean) property tells Timeplus whether or not the result should emit. ‘result’ is the current aggregate result, if ‘emit’ is false, the result will be ignored by Timeplus. Timeplus will convert the ‘result’ property of v8 to the data types defined when creating UDA. - If it returns a simple data type, Timeplus considers the return data as the result to be emitted immediately. It converts the return data to the corresponding data type and Timeplus emits the aggregating result. - Once UDA tells Timeplus to emit the data, UDA takes the full responsibility to clear the internal state, prepare and restart a new aggregating window, et al. * state function: which returns the serialized state of all internal states of UDA in string. The UDA takes the responsibility therefore Timeplus can choose to persist the internal state of UDA for query recovery. * init function: the input of this function is the string of serialized state of the internal states UDA. Timeplus calls this function when it wants to recover the aggregation function with the persisted internal state. | [optional]
**type** | **str** | Either `javascript` or `remote` | [optional]
**url** | **str** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Loading

0 comments on commit fbd30bd

Please sign in to comment.