-
Notifications
You must be signed in to change notification settings - Fork 61
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
12 changed files
with
254 additions
and
73 deletions.
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
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,56 @@ | ||
# 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 os | ||
|
||
import pytest | ||
|
||
from tsfile import TsFileWriter, TimeseriesSchema, DeviceSchema | ||
from tsfile import Tablet, RowRecord, Field | ||
from tsfile import TSDataType | ||
|
||
def test_row_record_write(): | ||
writer = TsFileWriter("record_write.tsfile") | ||
timeseries = TimeseriesSchema("level1", TSDataType.INT64) | ||
writer.register_timeseries("root.device1", timeseries) | ||
|
||
record = RowRecord("root.device1", 10,[Field("level1", TSDataType.INT64, 10)]) | ||
writer.write_row_record(record) | ||
if os.path.exists("record_write.tsfile"): | ||
os.remove("record_write.tsfile") | ||
|
||
def test_tablet_write(): | ||
if os.path.exists("tablet_write.tsfile"): | ||
os.remove("tablet_write.tsfile") | ||
writer = TsFileWriter("tablet_write.tsfile") | ||
timeseries1 = TimeseriesSchema("level1", TSDataType.INT64) | ||
timeseries2 = TimeseriesSchema("level2", TSDataType.DOUBLE) | ||
device = DeviceSchema("root.device1", [timeseries1, timeseries2]) | ||
writer.register_device(device) | ||
|
||
tablet = Tablet("root.device1", ["level1", "level2"], [TSDataType.INT64, TSDataType.DOUBLE]) | ||
for i in range(100): | ||
tablet.add_timestamp(i, i) | ||
tablet.add_value_by_index(0, i, i + 1) | ||
tablet.add_value_by_name("level2", i, i * 0.1) | ||
|
||
writer.write_tablet(tablet) | ||
if os.path.exists("tablet_write.tsfile"): | ||
os.remove("tablet_write.tsfile") | ||
|
||
|
||
|
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,90 @@ | ||
# 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 pytest | ||
|
||
import os | ||
|
||
from tsfile import TsFileWriter, TsFileReader | ||
from tsfile import TimeseriesSchema, DeviceSchema | ||
from tsfile import TSDataType | ||
from tsfile import Tablet, RowRecord, Field | ||
|
||
def test_row_record_write_and_read(): | ||
writer = TsFileWriter("record_write_and_read.tsfile") | ||
timeseries = TimeseriesSchema("level1", TSDataType.INT64) | ||
writer.register_timeseries("root.device1", timeseries) | ||
writer.register_timeseries("root.device1", TimeseriesSchema("level2", TSDataType.DOUBLE)) | ||
writer.register_timeseries("root.device1", TimeseriesSchema("level3", TSDataType.INT32)) | ||
|
||
max_row_num = 1000 | ||
for i in range(max_row_num): | ||
row = RowRecord("root.device1", i, | ||
[Field("level1", TSDataType.INT64, i), | ||
Field("level2", TSDataType.DOUBLE, i*1.1), | ||
Field("level3", TSDataType.INT32, i*2)]) | ||
writer.write_row_record(row) | ||
|
||
writer.close() | ||
|
||
reader = TsFileReader("record_write_and_read.tsfile") | ||
result = reader.query_timeseries("root.device1", ["level1","level2"], 10, 100) | ||
i = 10 | ||
while result.has_next(): | ||
assert result.get_value_by_index(0) == i | ||
assert result.get_value_by_name("level2") == i * 1.1 | ||
i = i + 1 | ||
reader.close() | ||
if os.path.exists("record_write_and_read.tsfile"): | ||
os.remove("record_write_and_read.tsfile") | ||
|
||
def test_tablet_write_and_read(): | ||
writer = TsFileWriter("tablet_write_and_read.tsfile") | ||
measurement_num = 30 | ||
for i in range(measurement_num): | ||
writer.register_timeseries("root.device1", TimeseriesSchema('level' + str(i), TSDataType.INT64)) | ||
|
||
max_row_num = 10000 | ||
tablet_row_num = 1000 | ||
tablet_num = 0 | ||
for i in range(max_row_num // tablet_row_num): | ||
tablet = Tablet("root.device1",[f'level{j}' for j in range(measurement_num)],[TSDataType.INT64 for _ in range(measurement_num)], tablet_row_num) | ||
for row in range(tablet_row_num): | ||
tablet.add_timestamp(row, row + tablet_num * tablet_row_num) | ||
for col in range(measurement_num): | ||
tablet.add_value_by_index(col, row, row + tablet_num * tablet_row_num) | ||
writer.write_tablet(tablet) | ||
tablet_num += 1 | ||
|
||
writer.close() | ||
|
||
reader = TsFileReader("tablet_write_and_read.tsfile") | ||
result = reader.query_timeseries("root.device1", ["level0"], 0, 1000000) | ||
row_num = 0 | ||
while result.has_next(): | ||
assert result.is_null_by_index(0) == False | ||
assert result.get_value_by_name("level0") == row_num | ||
row_num = row_num + 1 | ||
|
||
assert row_num == max_row_num | ||
reader.close() | ||
|
||
if os.path.exists("tablet_write_and_read.tsfile"): | ||
os.remove("tablet_write_and_read.tsfile") | ||
|
||
|
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
Oops, something went wrong.