Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,118 @@ public void cacheHitTest() {
selectSomeAlignedLastWithTimeFilterTest();
selectSomeAlignedAndNonAlignedLastWithTimeFilterTest();
}

@Test
public void testLastAlias() {
String[] sqls =
new String[] {
"create aligned timeseries root.ln_1.tb_6141(fengjituichu_BOOLEAN BOOLEAN encoding=RLE,`chushuiNH4-N_DOUBLE` DOUBLE encoding=GORILLA,mochanshuizhuangtai_BOOLEAN BOOLEAN encoding=RLE,11_TEXT TEXT encoding=PLAIN,chanshuijianxieyunxingshijianshezhi_DOUBLE DOUBLE encoding=GORILLA,wenben_TEXT TEXT encoding=PLAIN, fengjitouru_BOOLEAN BOOLEAN encoding=RLE,meiju_INT32 INT32 encoding=RLE,chushuiTP_DOUBLE DOUBLE encoding=GORILLA,shuiguanliusu_DOUBLE DOUBLE encoding=GORILLA,CO2_DOUBLE DOUBLE encoding=GORILLA,`kaiguanliang-yunxing_BOOLEAN` BOOLEAN encoding=RLE,gongnengma_DOUBLE DOUBLE encoding=GORILLA);",
"alter timeseries root.ln_1.tb_6141.fengjituichu_BOOLEAN upsert alias=fengjituichu;",
"alter timeseries root.ln_1.tb_6141.shuiguanliusu_DOUBLE upsert alias=shuiguanliusu;",
"alter timeseries root.ln_1.tb_6141.CO2_DOUBLE upsert alias=CO2;",
"alter timeseries root.ln_1.tb_6141.fengjitouru_BOOLEAN upsert alias=fengjitouru;",
"alter timeseries root.ln_1.tb_6141.chanshuijianxieyunxingshijianshezhi_DOUBLE upsert alias=chanshuijianxieyunxingshijianshezhi;",
"alter timeseries root.ln_1.tb_6141.mochanshuizhuangtai_BOOLEAN upsert alias=mochanshuizhuangtai;",
"alter timeseries root.ln_1.tb_6141.meiju_INT32 upsert alias=meiju;",
"alter timeseries root.ln_1.tb_6141.chushuiTP_DOUBLE upsert alias=chushuiTP;",
"alter timeseries root.ln_1.tb_6141.wenben_TEXT upsert alias=wenben;",
"alter timeseries root.ln_1.tb_6141.`chushuiNH4-N_DOUBLE` upsert alias=`chushuiNH4-N`;",
"alter timeseries root.ln_1.tb_6141.gongnengma_DOUBLE upsert alias=gongnengma;",
"alter timeseries root.ln_1.tb_6141.11_TEXT upsert alias=`11`;",
"alter timeseries root.ln_1.tb_6141.`kaiguanliang-yunxing_BOOLEAN` upsert alias=`kaiguanliang-yunxing`;",
"insert into root.ln_1.tb_6141(time,chanshuijianxieyunxingshijianshezhi_DOUBLE) aligned values(1679365910000,10.0);",
"insert into root.ln_1.tb_6141(time,chushuiTP_DOUBLE) aligned values(1679365910000,15.0);",
"insert into root.ln_1.tb_6141(time,gongnengma_DOUBLE) aligned values(1679477545000,2.0);",
"insert into root.ln_1.tb_6141(time,wenben_TEXT) aligned values(1675995566000,52);",
"insert into root.ln_1.tb_6141(time,meiju_INT32) aligned values(1675995566000,2);",
"insert into root.ln_1.tb_6141(time,shuiguanliusu_DOUBLE) aligned values(1679365910000,15.0);",
"insert into root.ln_1.tb_6141(time,mochanshuizhuangtai_BOOLEAN) aligned values(1677033625000,true);",
"insert into root.ln_1.tb_6141(time,fengjitouru_BOOLEAN) aligned values(1675995566000,true);",
"insert into root.ln_1.tb_6141(time,fengjituichu_BOOLEAN) aligned values(1675995566000,false);",
"insert into root.ln_1.tb_6141(time,11_TEXT) aligned values(1679365910000,13);",
"insert into root.ln_1.tb_6141(time,CO2_DOUBLE) aligned values(1679365910000,12.0);",
"insert into root.ln_1.tb_6141(time,`chushuiNH4-N_DOUBLE`) aligned values(1679365910000,12.0);",
"insert into root.ln_1.tb_6141(time,`kaiguanliang-yunxing_BOOLEAN`) aligned values(1675995566000,false);",
};

try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {

// create aligned and non-aligned time series
for (String sql : sqls) {
statement.addBatch(sql);
}
statement.executeBatch();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}

Set<String> retSet =
new HashSet<>(
Arrays.asList(
"1679477545000,root.ln_1.tb_6141.gongnengma,2.0,DOUBLE",
"1675995566000,root.ln_1.tb_6141.wenben,52,TEXT"));

try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {

try (ResultSet resultSet =
statement.executeQuery(
"select last gongnengma,wenben from root.ln_1.tb_6141 order by timeseries asc;")) {
int cnt = 0;
while (resultSet.next()) {
String ans =
resultSet.getString(TIMESTAMP_STR)
+ ","
+ resultSet.getString(TIMESERIES_STR)
+ ","
+ resultSet.getString(VALUE_STR)
+ ","
+ resultSet.getString(DATA_TYPE_STR);
assertTrue(ans, retSet.contains(ans));
cnt++;
}
assertEquals(retSet.size(), cnt);
}

} catch (SQLException e) {
e.printStackTrace();
fail(e.getMessage());
}

retSet =
new HashSet<>(
Arrays.asList(
"1679477545000,root.ln_1.tb_6141.gongnengma,2.0,DOUBLE",
"1677033625000,root.ln_1.tb_6141.mochanshuizhuangtai,true,BOOLEAN",
"1675995566000,root.ln_1.tb_6141.wenben,52,TEXT"));

try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {

try (ResultSet resultSet =
statement.executeQuery(
"select last gongnengma,mochanshuizhuangtai,wenben from root.ln_1.tb_6141 order by timeseries asc;")) {
int cnt = 0;
while (resultSet.next()) {
String ans =
resultSet.getString(TIMESTAMP_STR)
+ ","
+ resultSet.getString(TIMESERIES_STR)
+ ","
+ resultSet.getString(VALUE_STR)
+ ","
+ resultSet.getString(DATA_TYPE_STR);
assertTrue(ans, retSet.contains(ans));
cnt++;
}
assertEquals(retSet.size(), cnt);
}

} catch (SQLException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.it.last;

import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import static org.apache.iotdb.db.it.utils.TestUtils.prepareData;
import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class})
public class IoTDBLastQueryAlias2IT extends IoTDBLastQueryAliasIT {
@BeforeClass
public static void setUp() throws Exception {
// with lastCache
EnvFactory.getEnv().getConfig().getCommonConfig().setEnableLastCache(true);
EnvFactory.getEnv().initClusterEnvironment();
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
prepareData(SQLs);
} catch (SQLException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* 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.it.last;

import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import static org.apache.iotdb.db.it.utils.TestUtils.prepareData;
import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
import static org.apache.iotdb.itbase.constant.TestConstant.DATA_TYPE_STR;
import static org.apache.iotdb.itbase.constant.TestConstant.TIMESERIES_STR;
import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR;
import static org.apache.iotdb.itbase.constant.TestConstant.VALUE_STR;
import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class})
public class IoTDBLastQueryAliasIT {
protected static final String[] SQLs =
new String[] {
"create timeseries root.test.d1.s1(alias3) with dataType= int32",
"create timeseries root.test.d1.s2(alias2) with dataType= int32",
"create timeseries root.test.d1.s3(alias1) with dataType= int32",
"insert into root.test.d1(timestamp,s1,s2,s3) values(1,1,2,3)",
"create aligned timeseries root.test.d2 (s1 (alias3) int32,s2 (alias2) int32,s3 (alias1) int32)",
"insert into root.test.d2(timestamp,s1,s2,s3) values(2,2,3,4)",
};

@BeforeClass
public static void setUp() throws Exception {
// without lastCache
EnvFactory.getEnv().getConfig().getCommonConfig().setEnableLastCache(false);
EnvFactory.getEnv().initClusterEnvironment();
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
prepareData(SQLs);
} catch (SQLException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void nonAlignedTest() {
String[] expectedHeader =
new String[] {TIMESTAMP_STR, TIMESERIES_STR, VALUE_STR, DATA_TYPE_STR};

String[] retArray =
new String[] {
"1,root.test.d1.alias3,1,INT32,",
};
resultSetEqualTest("select last alias3 from root.test.d1", expectedHeader, retArray);

retArray =
new String[] {
"1,root.test.d1.alias3,1,INT32,",
"1,root.test.d1.alias2,2,INT32,",
"1,root.test.d1.alias1,3,INT32,",
};
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d1", expectedHeader, retArray);
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d1", expectedHeader, retArray);

retArray =
new String[] {
"1,root.test.d1.alias1,3,INT32,",
"1,root.test.d1.alias2,2,INT32,",
"1,root.test.d1.alias3,1,INT32,",
};
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d1 order by timeseries",
expectedHeader,
retArray);
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d1 order by timeseries",
expectedHeader,
retArray);
}

@Test
public void alignedTest() {
String[] expectedHeader =
new String[] {TIMESTAMP_STR, TIMESERIES_STR, VALUE_STR, DATA_TYPE_STR};
String[] retArray =
new String[] {
"2,root.test.d2.alias3,2,INT32,",
"2,root.test.d2.alias2,3,INT32,",
"2,root.test.d2.alias1,4,INT32,",
};
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d2", expectedHeader, retArray);
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d2", expectedHeader, retArray);

retArray =
new String[] {
"2,root.test.d2.alias1,4,INT32,",
"2,root.test.d2.alias2,3,INT32,",
"2,root.test.d2.alias3,2,INT32,",
};
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d2 order by timeseries",
expectedHeader,
retArray);
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.d2 order by timeseries",
expectedHeader,
retArray);
}

@Test
public void mixedTest() {
String[] expectedHeader =
new String[] {TIMESTAMP_STR, TIMESERIES_STR, VALUE_STR, DATA_TYPE_STR};
String[] retArray =
new String[] {
"1,root.test.d1.alias1,3,INT32,",
"1,root.test.d1.alias2,2,INT32,",
"1,root.test.d1.alias3,1,INT32,",
"2,root.test.d2.alias1,4,INT32,",
"2,root.test.d2.alias2,3,INT32,",
"2,root.test.d2.alias3,2,INT32,",
};
resultSetEqualTest(
"select last alias3,alias2,alias1 from root.test.* order by timeseries",
expectedHeader,
retArray);
}
}
Loading
Loading