Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpaulyz committed Jun 21, 2024
1 parent c6d0ec1 commit 30af0c5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ public void showDevicesTest() throws SQLException {
}
// check order by
List<String> orderList =
Arrays.asList(
"root.ln.wf01.wt01,false,null,INF,", "root.ln.wf01.wt02,true,null,8888,");
Arrays.asList("root.ln.wf01.wt01,false,null,INF,", "root.ln.wf01.wt02,true,null,8888,");
checkWithOrder("show devices root.ln.** order by device", orderList, false);
checkWithOrder("show devices root.ln.** order by device desc", orderList, true);
}
Expand Down Expand Up @@ -886,7 +885,8 @@ public void showDeadbandInfo() throws SQLException {
}
}

private void checkWithOrder(String sql, List<String> expected, boolean reverse) throws SQLException {
private void checkWithOrder(String sql, List<String> expected, boolean reverse)
throws SQLException {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql)) {
Expand All @@ -898,7 +898,7 @@ private void checkWithOrder(String sql, List<String> expected, boolean reverse)
builder.append(resultSet.getString(i)).append(",");
}
String string = builder.toString();
String expectedString = expected.get(reverse?expected.size()-1-row:row);
String expectedString = expected.get(reverse ? expected.size() - 1 - row : row);
Assert.assertEquals(expectedString, string);
row++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Category({LocalStandaloneIT.class, ClusterIT.class})
Expand Down Expand Up @@ -197,6 +199,28 @@ public void testShowTimeSeries() {
statement,
"count timeseries root.sg.** where time=1",
new HashSet<>(Collections.singletonList("3,")));
// Check order by
List<String> expectedOrder =
Arrays.asList(
"root.sg.d0.s0,null,root.sg,INT32,TS_2DIFF,LZ4,null,null,null,null,BASE,",
"root.sg.d0.s1,null,root.sg,INT32,PLAIN,LZ4,null,null,SDT,{compdev=2},BASE,",
"root.sg.d0.s2,null,root.sg,INT32,PLAIN,LZ4,null,null,SDT,{compdev=0.01, compmintime=2, compmaxtime=15},BASE,",
"root.sg.d1.s1,alias1,root.sg,INT32,TS_2DIFF,LZ4,{\"tag1\":\"v1\",\"tag2\":\"v2\"},null,null,null,BASE,",
"root.sg.d1.s2,null,root.sg,DOUBLE,GORILLA,LZ4,null,{\"attr3\":\"v3\"},null,null,BASE,",
"root.sg.d2.s1,null,root.sg,INT64,RLE,SNAPPY,null,null,null,null,BASE,",
"root.sg.d2.s2,null,root.sg,INT32,TS_2DIFF,LZ4,null,null,null,null,BASE,",
"root.sg.d3.s1,null,root.sg,INT64,RLE,SNAPPY,null,null,null,null,BASE,",
"root.sg.d3.s2,null,root.sg,INT32,TS_2DIFF,LZ4,null,null,null,null,BASE,");
checkResultSetWithOrder(
statement,
"show timeseries root.sg.** where time>0 order by timeseries",
expectedOrder,
false);
checkResultSetWithOrder(
statement,
"show timeseries root.sg.** where time>0 order by timeseries desc",
expectedOrder,
true);
// 3. Check non-root user
statement.execute("CREATE USER user1 'password'");
statement.execute("GRANT READ_SCHEMA ON root.sg.d0.s1 TO USER user1");
Expand Down Expand Up @@ -307,6 +331,20 @@ public void testShowDevices() {
statement,
"count devices root.sg.* where time=1",
new HashSet<>(Collections.singletonList("1,")));
// Check order by
List<String> expectedOrder =
Arrays.asList(
"root.sg.d0,false,null,INF,",
"root.sg.d1,true,null,INF,",
"root.sg.d2,false,t1,INF,",
"root.sg.d3,true,t2,60000,");
checkResultSetWithOrder(
statement, "show devices root.sg.* where time>0 order by device", expectedOrder, false);
checkResultSetWithOrder(
statement,
"show devices root.sg.* where time>0 order by device desc",
expectedOrder,
true);
// 3. Check non-root user
statement.execute("CREATE USER user1 'password'");
statement.execute("GRANT READ_SCHEMA ON root.sg.d0.s1 TO USER user1");
Expand Down Expand Up @@ -360,4 +398,22 @@ private void checkResultSet(Statement statement, String sql, Set<String> expecte
}
Assert.assertTrue(expected.isEmpty());
}

private void checkResultSetWithOrder(
Statement statement, String sql, List<String> expected, boolean reverse) throws SQLException {
try (ResultSet resultSet = statement.executeQuery(sql)) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int row = 0;
while (resultSet.next()) {
StringBuilder builder = new StringBuilder();
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
builder.append(resultSet.getString(i)).append(",");
}
String string = builder.toString();
String expectedString = expected.get(reverse ? expected.size() - 1 - row : row);
Assert.assertEquals(expectedString, string);
row++;
}
}
}
}

0 comments on commit 30af0c5

Please sign in to comment.