-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add FROM-first query syntax support #17410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JackieTien97
merged 3 commits into
apache:master
from
Abdelrahman-358:f_from_first_syntax
Apr 8, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
...test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBFromFirstQueryIT.java
This file contains hidden or 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,126 @@ | ||
| /* | ||
| * 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.relational.it.query.recent; | ||
|
|
||
| import org.apache.iotdb.it.env.EnvFactory; | ||
| import org.apache.iotdb.it.framework.IoTDBTestRunner; | ||
| import org.apache.iotdb.itbase.category.TableClusterIT; | ||
| import org.apache.iotdb.itbase.category.TableLocalStandaloneIT; | ||
|
|
||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData; | ||
| import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest; | ||
|
|
||
| @RunWith(IoTDBTestRunner.class) | ||
| @Category({TableLocalStandaloneIT.class, TableClusterIT.class}) | ||
| public class IoTDBFromFirstQueryIT { | ||
| private static final String DATABASE_NAME = "test"; | ||
|
|
||
| private static final String[] createSqls = | ||
| new String[] { | ||
| "CREATE DATABASE " + DATABASE_NAME, | ||
| "USE " + DATABASE_NAME, | ||
| "CREATE TABLE table1(device STRING TAG, region STRING TAG, temperature FLOAT FIELD, humidity DOUBLE FIELD)", | ||
| "CREATE TABLE table2(device STRING TAG, location STRING TAG, pressure FLOAT FIELD)", | ||
| "INSERT INTO table1(time,device,region,temperature,humidity) values(1,'d1','north',25.5,60.3)", | ||
| "INSERT INTO table1(time,device,region,temperature,humidity) values(2,'d1','north',26.1,59.8)", | ||
| "INSERT INTO table1(time,device,region,temperature,humidity) values(3,'d2','south',24.8,65.2)", | ||
| "INSERT INTO table2(time,device,location,pressure) values(1,'d1','room1',1013.25)", | ||
| "INSERT INTO table2(time,device,location,pressure) values(2,'d2','room2',1012.5)", | ||
| "FLUSH" | ||
| }; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() throws Exception { | ||
| EnvFactory.getEnv().initClusterEnvironment(); | ||
| prepareTableData(createSqls); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() throws Exception { | ||
| EnvFactory.getEnv().cleanClusterEnvironment(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBasicFromFirstQuery() { | ||
| String[] expectedHeader = new String[] {"time", "device", "region", "temperature", "humidity"}; | ||
| String[] retArray = | ||
| new String[] { | ||
| "1970-01-01T00:00:00.001Z,d1,north,25.5,60.3,", | ||
| "1970-01-01T00:00:00.002Z,d1,north,26.1,59.8,", | ||
| "1970-01-01T00:00:00.003Z,d2,south,24.8,65.2," | ||
| }; | ||
|
|
||
| tableResultSetEqualTest( | ||
| "FROM table1 SELECT * order by time", expectedHeader, retArray, DATABASE_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFromFirstWithImplicitSelect() { | ||
| String[] expectedHeader = new String[] {"time", "device", "region", "temperature", "humidity"}; | ||
| String[] retArray = | ||
| new String[] { | ||
| "1970-01-01T00:00:00.001Z,d1,north,25.5,60.3,", | ||
| "1970-01-01T00:00:00.002Z,d1,north,26.1,59.8,", | ||
| "1970-01-01T00:00:00.003Z,d2,south,24.8,65.2," | ||
| }; | ||
|
|
||
| tableResultSetEqualTest("FROM table1 order by time", expectedHeader, retArray, DATABASE_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFromFirstWithSimpleJoin() { | ||
| String[] expectedHeader = | ||
| new String[] { | ||
| "time", "device", "region", "temperature", "humidity", "location", "pressure" | ||
| }; | ||
| String[] retArray = | ||
| new String[] { | ||
| "1970-01-01T00:00:00.001Z,d1,north,25.5,60.3,room1,1013.25,", | ||
| "1970-01-01T00:00:00.002Z,d1,north,26.1,59.8,null,null,", | ||
| "1970-01-01T00:00:00.003Z,d2,south,24.8,65.2,null,null," | ||
| }; | ||
|
|
||
| tableResultSetEqualTest( | ||
| "FROM table1 t1 LEFT JOIN table2 t2 ON t1.device = t2.device AND t1.time = t2.time " | ||
| + "SELECT t1.time, t1.device, t1.region, t1.temperature, t1.humidity, t2.location, t2.pressure " | ||
| + "ORDER BY t1.time", | ||
| expectedHeader, | ||
| retArray, | ||
| DATABASE_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFromFirstWithWhereAndAggregate() { | ||
| String[] expectedHeader = new String[] {"device", "avg_temp", "count_rows"}; | ||
| String[] retArray = new String[] {"d1,25.8,2,", "d2,24.8,1,"}; | ||
|
|
||
| tableResultSetEqualTest( | ||
| "FROM table1 SELECT device, ROUND(AVG(temperature), 1) as avg_temp, COUNT(*) as count_rows WHERE temperature > 24.0 GROUP BY device order by device", | ||
| expectedHeader, | ||
| retArray, | ||
| DATABASE_NAME); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.