-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# TsFile Python Document | ||
|
||
<pre> | ||
___________ ___________.__.__ | ||
\__ ___/____\_ _____/|__| | ____ | ||
| | / ___/| __) | | | _/ __ \ | ||
| | \___ \ | \ | | |_\ ___/ | ||
|____|/____ >\___ / |__|____/\___ > version 1.0.0 | ||
\/ \/ \/ | ||
</pre> | ||
|
||
|
||
## Introduction | ||
|
||
This directory contians the Python implementation of TsFile. The Python version of TsFile is implemented based on the CPP version. It utilizes the Cython package to integrate the read and write capabilities of TsFile CPP into the Python environment. Users can read and write TsFile just like they use read_csv and write_csv in Pandas. | ||
|
||
The source code can be found in the `./tsfile` directory. Files ending with `.pyx` and `.pyd` are wrapper code written in Cython. The `tsfile/tsfile.py` defines some user interfaces. You can find some examples of reading and writing in the `.examples/examples.py`. | ||
|
||
|
||
## How to make contributions | ||
|
||
Using pylint to check Python code is recommended. However, there is no suitable style checking tool for Cython code, and this part of the code should be consistent with the Python style required by pylint. | ||
|
||
**Feature List** | ||
- [ ] In pywrapper, invoke the batch reading interface implemented in tsfile_CPP. | ||
|
||
|
||
|
||
## Build | ||
|
||
You can build tsfile_python by mvn or shell command. | ||
|
||
Before constructing tsfile_python, it is necessary to build [tsfile_cpp](../cpp/README.md) first, because tsfile_python relies on the shared library files provided by tsfile_cpp. | ||
|
||
Build by mvn in this directory: | ||
|
||
```sh | ||
mvn initialize compile test | ||
``` | ||
|
||
Build by mvn in tsfile root directory: | ||
|
||
```sh | ||
mvn clean package -P with-python | ||
``` | ||
|
||
Build by python command: | ||
```sh | ||
python3 setup.py build_ext --inplace | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import os | ||
|
||
import tsfile as ts | ||
|
||
|
||
# test writing data | ||
data_dir = os.path.join(os.path.dirname(__file__), "test.tsfile") | ||
TABLE_NAME = "test_table" | ||
|
||
# 1000 rows data | ||
time = np.arange(1, 1001, dtype=np.int64) | ||
level = np.linspace(2000, 3000, num=1000, dtype=np.float32) | ||
num = np.arange(10000, 11000, dtype=np.int64) | ||
df = pd.DataFrame({"Time": time, "level": level, "num": num}) | ||
|
||
if os.path.exists(data_dir): | ||
os.remove(data_dir) | ||
ts.write_tsfile(data_dir, TABLE_NAME, df) | ||
|
||
|
||
# read data we already wrote | ||
# with 20 chunksize | ||
tsfile_ret = ts.read_tsfile(data_dir, TABLE_NAME, ["level", "num"], chunksize=20) | ||
print(tsfile_ret.shape) | ||
|
||
# # with 100 chunksize | ||
tsfile_ret = ts.read_tsfile(data_dir, TABLE_NAME, ["level", "num"], chunksize = 100) | ||
print(tsfile_ret.shape) | ||
|
||
# # get all data | ||
tsfile_ret = ts.read_tsfile(data_dir, TABLE_NAME, ["level", "num"]) | ||
print(tsfile_ret.shape) | ||
|
||
# # with iterator | ||
with ts.read_tsfile(data_dir, TABLE_NAME, ["level", "num"], iterator=True, chunksize=100) as reader: | ||
for chunk in reader: | ||
print(chunk.shape) | ||
|
||
# # with time scale and chunksize | ||
tsfile_ret = ts.read_tsfile(data_dir, TABLE_NAME, | ||
["level"], start_time=50, end_time=100, chunksize=10) | ||
print(tsfile_ret.shape) | ||
|
||
# with time scale | ||
tsfile_ret = ts.read_tsfile(data_dir, TABLE_NAME, ["num"], start_time=50, end_time=100) | ||
print(tsfile_ret.shape) | ||
|
||
|
||
with ts.read_tsfile( | ||
data_dir, | ||
TABLE_NAME, | ||
["level", "num"], | ||
iterator=True, | ||
start_time=100, | ||
end_time=500, | ||
chunksize=100, | ||
) as reader: | ||
for chunk in reader: | ||
print(chunk.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.tsfile</groupId> | ||
<artifactId>tsfile-parent</artifactId> | ||
<version>1.0.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>tsfile-python</artifactId> | ||
<packaging>pom</packaging> | ||
<name>TsFile: Python</name> | ||
<properties> | ||
<unity.version>2.6.0</unity.version> | ||
<groovy.version>4.0.21</groovy.version> | ||
<!-- Tell Sonar where to find the sources --> | ||
<sonar.sources>tsfile</sonar.sources> | ||
<sonar.cfamily.build-wrapper-output>${project.build.directory}/build-wrapper-output</sonar.cfamily.build-wrapper-output> | ||
</properties> | ||
<build> | ||
<sourceDirectory>${project.basedir}</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<executions> | ||
<!-- Create python virtual environment --> | ||
<execution> | ||
<id>python-venv</id> | ||
<phase>initialize</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>${python.exe.bin}</executable> | ||
<arguments> | ||
<argument>-m</argument> | ||
<argument>venv</argument> | ||
<argument>${project.basedir}/venv</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>python-upgrade-pip</id> | ||
<phase>initialize</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>${python.venv.bin}${python.exe.bin}</executable> | ||
<arguments> | ||
<argument>-m</argument> | ||
<argument>pip</argument> | ||
<argument>install</argument> | ||
<argument>--upgrade</argument> | ||
<argument>pip</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>python-install-requirements</id> | ||
<phase>initialize</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>${python.venv.bin}${python.exe.bin}</executable> | ||
<arguments> | ||
<argument>-m</argument> | ||
<argument>pip</argument> | ||
<argument>install</argument> | ||
<argument>-r</argument> | ||
<argument>${project.basedir}/requirements.txt</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<id>compile-python-code</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>python3</executable> | ||
<arguments> | ||
<argument>setup.py</argument> | ||
<argument>build_ext</argument> | ||
<argument>--inplace</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>run-python-tests</id> | ||
<phase>test</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>${python.venv.bin}${python.exe.bin}</executable> | ||
<arguments> | ||
<argument>${project.basedir}/test.py</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.