Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Iotdb
提交
76d66ed5
I
Iotdb
项目概览
apache
/
Iotdb
9 个月 前同步成功
通知
25
Star
3344
Fork
916
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iotdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
76d66ed5
编写于
7月 28, 2023
作者:
C
CloudWise-Lukemiao
提交者:
GitHub
7月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add sorting based on timestamps to the insertTable method in the rest API v1/v2 (#10660)
Co-authored-by:
N
Cloudwise_Luke
<
282583553@qq.com
>
上级
7b02fea4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
91 addition
and
0 deletion
+91
-0
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java
...tdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java
+69
-0
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
...he/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
+11
-0
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
...he/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
+11
-0
未找到文件。
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java
0 → 100644
浏览文件 @
76d66ed5
/*
* 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.
*/
package
org.apache.iotdb.db.protocol.rest.utils
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
public
class
InsertTabletSortDataUtils
{
public
static
boolean
checkSorted
(
List
<
Long
>
times
)
{
for
(
int
i
=
1
;
i
<
times
.
size
();
i
++)
{
if
(
times
.
get
(
i
)
<
times
.
get
(
i
-
1
))
{
return
false
;
}
}
return
true
;
}
public
static
int
[]
sortTimeStampList
(
List
<
Long
>
list
)
{
int
n
=
list
.
size
();
long
[]
arr
=
new
long
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
arr
[
i
]
=
list
.
get
(
i
);
}
Arrays
.
sort
(
arr
);
int
[]
indices
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
indices
[
i
]
=
list
.
indexOf
(
arr
[
i
]);
}
return
indices
;
}
public
static
<
T
>
List
<
List
<
T
>>
sortList
(
List
<
List
<
T
>>
values
,
int
[]
index
,
int
num
)
{
List
<
List
<
T
>>
sortedValues
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
num
;
i
++)
{
sortedValues
.
add
(
sortValueList
(
values
.
get
(
i
),
index
));
}
return
sortedValues
;
}
/**
* Sort the input source list.
*
* <p>e.g. source:[1,0,3,2,4], index: [1,2,3,4,5], return : [2,1,4,3,5]
*
* @param source Input list
* @param index return order
* @param <T> Input type
* @return ordered list
*/
private
static
<
T
>
List
<
T
>
sortValueList
(
List
<
T
>
source
,
int
[]
index
)
{
return
Arrays
.
stream
(
index
).
mapToObj
(
source:
:
get
).
collect
(
Collectors
.
toList
());
}
}
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
浏览文件 @
76d66ed5
...
...
@@ -21,6 +21,7 @@ import org.apache.iotdb.db.conf.IoTDBConfig;
import
org.apache.iotdb.db.conf.IoTDBDescriptor
;
import
org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor
;
import
org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler
;
import
org.apache.iotdb.db.protocol.rest.utils.InsertTabletSortDataUtils
;
import
org.apache.iotdb.db.protocol.rest.v1.RestApiService
;
import
org.apache.iotdb.db.protocol.rest.v1.handler.ExceptionHandler
;
import
org.apache.iotdb.db.protocol.rest.v1.handler.ExecuteStatementHandler
;
...
...
@@ -191,6 +192,16 @@ public class RestApiServiceImpl extends RestApiService {
try
{
RequestValidationHandler
.
validateInsertTabletRequest
(
insertTabletRequest
);
if
(!
InsertTabletSortDataUtils
.
checkSorted
(
insertTabletRequest
.
getTimestamps
()))
{
int
[]
index
=
InsertTabletSortDataUtils
.
sortTimeStampList
(
insertTabletRequest
.
getTimestamps
());
insertTabletRequest
.
getTimestamps
().
sort
(
Long:
:
compareTo
);
insertTabletRequest
.
setValues
(
InsertTabletSortDataUtils
.
sortList
(
insertTabletRequest
.
getValues
(),
index
,
insertTabletRequest
.
getDataTypes
().
size
()));
}
InsertTabletStatement
insertTabletStatement
=
StatementConstructionHandler
.
constructInsertTabletStatement
(
insertTabletRequest
);
...
...
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
浏览文件 @
76d66ed5
...
...
@@ -21,6 +21,7 @@ import org.apache.iotdb.db.conf.IoTDBConfig;
import
org.apache.iotdb.db.conf.IoTDBDescriptor
;
import
org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor
;
import
org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler
;
import
org.apache.iotdb.db.protocol.rest.utils.InsertTabletSortDataUtils
;
import
org.apache.iotdb.db.protocol.rest.v2.RestApiService
;
import
org.apache.iotdb.db.protocol.rest.v2.handler.ExceptionHandler
;
import
org.apache.iotdb.db.protocol.rest.v2.handler.ExecuteStatementHandler
;
...
...
@@ -191,6 +192,16 @@ public class RestApiServiceImpl extends RestApiService {
try
{
RequestValidationHandler
.
validateInsertTabletRequest
(
insertTabletRequest
);
if
(!
InsertTabletSortDataUtils
.
checkSorted
(
insertTabletRequest
.
getTimestamps
()))
{
int
[]
index
=
InsertTabletSortDataUtils
.
sortTimeStampList
(
insertTabletRequest
.
getTimestamps
());
insertTabletRequest
.
getTimestamps
().
sort
(
Long:
:
compareTo
);
insertTabletRequest
.
setValues
(
InsertTabletSortDataUtils
.
sortList
(
insertTabletRequest
.
getValues
(),
index
,
insertTabletRequest
.
getDataTypes
().
size
()));
}
InsertTabletStatement
insertTabletStatement
=
StatementConstructionHandler
.
constructInsertTabletStatement
(
insertTabletRequest
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录