Skip to content

Commit 7c14eac

Browse files
dracooooooLeslieKid
authored andcommitted
feat: support INSERT INTO SELECT (apache#1536)
## Rationale Close apache#557. ## Detailed Changes When generating the insert logical plan, alse generate the select logical plan and store it in the insert plan. Then execute the select logical plan in the insert interpreter, convert the result records into RowGroup and then insert it. ## Test Plan CI
1 parent ebc9f12 commit 7c14eac

File tree

7 files changed

+487
-158
lines changed

7 files changed

+487
-158
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--
2+
-- Licensed to the Apache Software Foundation (ASF) under one
3+
-- or more contributor license agreements. See the NOTICE file
4+
-- distributed with this work for additional information
5+
-- regarding copyright ownership. The ASF licenses this file
6+
-- to you under the Apache License, Version 2.0 (the
7+
-- "License"); you may not use this file except in compliance
8+
-- with the License. You may obtain a copy of the License at
9+
--
10+
-- http://www.apache.org/licenses/LICENSE-2.0
11+
--
12+
-- Unless required by applicable law or agreed to in writing,
13+
-- software distributed under the License is distributed on an
14+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
-- KIND, either express or implied. See the License for the
16+
-- specific language governing permissions and limitations
17+
-- under the License.
18+
--
19+
DROP TABLE IF EXISTS `insert_into_select_table1`;
20+
21+
affected_rows: 0
22+
23+
CREATE TABLE `insert_into_select_table1` (
24+
`timestamp` timestamp NOT NULL,
25+
`value` int,
26+
`name` string,
27+
timestamp KEY (timestamp)) ENGINE=Analytic
28+
WITH(
29+
enable_ttl='false'
30+
);
31+
32+
affected_rows: 0
33+
34+
INSERT INTO `insert_into_select_table1` (`timestamp`, `value`, `name`)
35+
VALUES
36+
(1, 100, "s1"),
37+
(2, 200, "s2"),
38+
(3, 300, "s3");
39+
40+
affected_rows: 3
41+
42+
DROP TABLE IF EXISTS `insert_into_select_table2`;
43+
44+
affected_rows: 0
45+
46+
CREATE TABLE `insert_into_select_table2` (
47+
`timestamp` timestamp NOT NULL,
48+
`value` int,
49+
`name` string NULL,
50+
timestamp KEY (timestamp)) ENGINE=Analytic
51+
WITH(
52+
enable_ttl='false'
53+
);
54+
55+
affected_rows: 0
56+
57+
INSERT INTO `insert_into_select_table2` (`timestamp`, `value`)
58+
SELECT `timestamp`, `value`
59+
FROM `insert_into_select_table1`;
60+
61+
affected_rows: 3
62+
63+
SELECT `timestamp`, `value`, `name`
64+
FROM `insert_into_select_table2`;
65+
66+
timestamp,value,name,
67+
Timestamp(1),Int32(100),String(""),
68+
Timestamp(2),Int32(200),String(""),
69+
Timestamp(3),Int32(300),String(""),
70+
71+
72+
DROP TABLE `insert_into_select_table1`;
73+
74+
affected_rows: 0
75+
76+
DROP TABLE `insert_into_select_table2`;
77+
78+
affected_rows: 0
79+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--
2+
-- Licensed to the Apache Software Foundation (ASF) under one
3+
-- or more contributor license agreements. See the NOTICE file
4+
-- distributed with this work for additional information
5+
-- regarding copyright ownership. The ASF licenses this file
6+
-- to you under the Apache License, Version 2.0 (the
7+
-- "License"); you may not use this file except in compliance
8+
-- with the License. You may obtain a copy of the License at
9+
--
10+
-- http://www.apache.org/licenses/LICENSE-2.0
11+
--
12+
-- Unless required by applicable law or agreed to in writing,
13+
-- software distributed under the License is distributed on an
14+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
-- KIND, either express or implied. See the License for the
16+
-- specific language governing permissions and limitations
17+
-- under the License.
18+
--
19+
20+
DROP TABLE IF EXISTS `insert_into_select_table1`;
21+
22+
CREATE TABLE `insert_into_select_table1` (
23+
`timestamp` timestamp NOT NULL,
24+
`value` int,
25+
`name` string,
26+
timestamp KEY (timestamp)) ENGINE=Analytic
27+
WITH(
28+
enable_ttl='false'
29+
);
30+
31+
INSERT INTO `insert_into_select_table1` (`timestamp`, `value`, `name`)
32+
VALUES
33+
(1, 100, "s1"),
34+
(2, 200, "s2"),
35+
(3, 300, "s3");
36+
37+
DROP TABLE IF EXISTS `insert_into_select_table2`;
38+
39+
CREATE TABLE `insert_into_select_table2` (
40+
`timestamp` timestamp NOT NULL,
41+
`value` int,
42+
`name` string NULL,
43+
timestamp KEY (timestamp)) ENGINE=Analytic
44+
WITH(
45+
enable_ttl='false'
46+
);
47+
48+
INSERT INTO `insert_into_select_table2` (`timestamp`, `value`)
49+
SELECT `timestamp`, `value`
50+
FROM `insert_into_select_table1`;
51+
52+
SELECT `timestamp`, `value`, `name`
53+
FROM `insert_into_select_table2`;
54+
55+
DROP TABLE `insert_into_select_table1`;
56+
57+
DROP TABLE `insert_into_select_table2`;

src/interpreters/src/factory.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ impl Factory {
8282
self.physical_planner,
8383
self.query_runtime,
8484
),
85-
Plan::Insert(p) => InsertInterpreter::create(ctx, p),
85+
Plan::Insert(p) => {
86+
InsertInterpreter::create(ctx, p, self.query_executor, self.physical_planner)
87+
}
8688
Plan::Create(p) => {
8789
CreateInterpreter::create(ctx, p, self.table_engine, self.table_manipulator)
8890
}

0 commit comments

Comments
 (0)