Fly-Style commented on code in PR #18805:
URL: https://github.com/apache/druid/pull/18805#discussion_r2586174244


##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/query/SystemTableQueryTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.druid.testing.embedded.query;
+
+
+import org.apache.druid.common.utils.IdUtils;
+import org.apache.druid.indexing.common.task.IndexTask;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.testing.embedded.EmbeddedClusterApis;
+import org.apache.druid.testing.embedded.indexing.MoreResources;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SystemTableQueryTest extends QueryTestBase
+{
+  private final String tableName1 = 
EmbeddedClusterApis.createTestDatasourceName();
+  private final String tableName2 = 
EmbeddedClusterApis.createTestDatasourceName();
+
+  @Override
+  public void beforeAll()
+  {
+    final String taskId1 = IdUtils.getRandomId();
+    final String taskId2 = IdUtils.getRandomId();
+    final IndexTask task1 = 
MoreResources.Task.BASIC_INDEX.get().dataSource(tableName1).withId(taskId1);
+    final IndexTask task2 = 
MoreResources.Task.BASIC_INDEX.get().dataSource(tableName2).withId(taskId2);
+    cluster.callApi().onLeaderOverlord(o -> o.runTask(taskId1, task1));
+    cluster.callApi().onLeaderOverlord(o -> o.runTask(taskId2, task2));
+
+    cluster.callApi().waitForTaskToSucceed(taskId1, overlord);
+    cluster.callApi().waitForTaskToSucceed(taskId2, overlord);
+
+    cluster.callApi().waitForAllSegmentsToBeAvailable(tableName1, coordinator, 
broker);
+    cluster.callApi().waitForAllSegmentsToBeAvailable(tableName2, coordinator, 
broker);
+  }
+
+  @Test
+  public void testSystemTableQueries_segmentsCount()
+  {
+    String query = StringUtils.format(
+        "SELECT datasource, count(*) \n"
+        + "FROM sys.segments \n"
+        + "WHERE datasource='%s' \n"
+        + "OR    datasource='%s' \n"
+        + "GROUP BY 1", tableName1, tableName2

Review Comment:
   
https://github.com/apache/druid/pull/18805/commits/0a64c9bc05d01424463e0897a8f069027e12c7a2



##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/query/SystemTableQueryTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.druid.testing.embedded.query;
+
+
+import org.apache.druid.common.utils.IdUtils;
+import org.apache.druid.indexing.common.task.IndexTask;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.testing.embedded.EmbeddedClusterApis;
+import org.apache.druid.testing.embedded.indexing.MoreResources;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SystemTableQueryTest extends QueryTestBase
+{
+  private final String tableName1 = 
EmbeddedClusterApis.createTestDatasourceName();
+  private final String tableName2 = 
EmbeddedClusterApis.createTestDatasourceName();
+
+  @Override
+  public void beforeAll()
+  {
+    final String taskId1 = IdUtils.getRandomId();
+    final String taskId2 = IdUtils.getRandomId();
+    final IndexTask task1 = 
MoreResources.Task.BASIC_INDEX.get().dataSource(tableName1).withId(taskId1);
+    final IndexTask task2 = 
MoreResources.Task.BASIC_INDEX.get().dataSource(tableName2).withId(taskId2);
+    cluster.callApi().onLeaderOverlord(o -> o.runTask(taskId1, task1));
+    cluster.callApi().onLeaderOverlord(o -> o.runTask(taskId2, task2));
+
+    cluster.callApi().waitForTaskToSucceed(taskId1, overlord);
+    cluster.callApi().waitForTaskToSucceed(taskId2, overlord);
+
+    cluster.callApi().waitForAllSegmentsToBeAvailable(tableName1, coordinator, 
broker);
+    cluster.callApi().waitForAllSegmentsToBeAvailable(tableName2, coordinator, 
broker);

Review Comment:
   
https://github.com/apache/druid/pull/18805/commits/0a64c9bc05d01424463e0897a8f069027e12c7a2



##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/query/JdbcQueryTest.java:
##########
@@ -145,84 +124,91 @@ public void testJdbcMetadata()
           druidTables.add(table);
         }
         LOG.info("'druid' schema tables %s", druidTables);
-        // maybe more tables than this, but at least should have these
-        Assert.assertTrue(
-            druidTables.containsAll(ImmutableList.of("twitterstream", 
"wikipedia", WIKIPEDIA_DATA_SOURCE))
+        // maybe more tables than this, but at least should have @tableName
+        Assertions.assertTrue(
+            druidTables.containsAll(ImmutableList.of(tableName))
         );
 
         Set<String> wikiColumns = new HashSet<>();
-        ResultSet columnsMetadata = metadata.getColumns("druid", "druid", 
WIKIPEDIA_DATA_SOURCE, null);
+        ResultSet columnsMetadata = metadata.getColumns("druid", "druid", 
tableName, null);
         while (columnsMetadata.next()) {
           final String column = columnsMetadata.getString(4);
           wikiColumns.add(column);
         }
-        LOG.info("'%s' columns %s", WIKIPEDIA_DATA_SOURCE, wikiColumns);
+        LOG.info("'%s' columns %s", tableName, wikiColumns);
         // a lot more columns than this, but at least should have these
-        Assert.assertTrue(
-            wikiColumns.containsAll(ImmutableList.of("added", "city", "delta", 
"language"))
+        Assertions.assertTrue(
+            wikiColumns.containsAll(ImmutableList.of("__time", "item", 
"value"))
         );
       }
       catch (SQLException throwables) {
-        Assert.fail(throwables.getMessage());
+        Assertions.fail(throwables.getMessage());
       }
     }
   }
 
   @Test
   public void testJdbcStatementQuery()
   {
+    String query = StringUtils.format(QUERY_TEMPLATE, tableName, "1000");
     for (String url : connections) {
       try (Connection connection = DriverManager.getConnection(url, 
connectionProperties)) {
         try (Statement statement = connection.createStatement()) {
-          final ResultSet resultSet = statement.executeQuery(QUERY);
+          final ResultSet resultSet = statement.executeQuery(query);
           int resultRowCount = 0;
           while (resultSet.next()) {
             resultRowCount++;
             LOG.info("%s,%s,%s", resultSet.getString(1), resultSet.getLong(2), 
resultSet.getLong(3));
           }
-          Assert.assertEquals(resultRowCount, 10);
+          Assertions.assertEquals(7, resultRowCount);
           resultSet.close();
         }
       }
       catch (SQLException throwables) {
-        Assert.fail(throwables.getMessage());
+        Assertions.fail(throwables.getMessage());
       }
     }
   }
 
   @Test
   public void testJdbcPrepareStatementQuery()
   {
+    String query = StringUtils.format(QUERY_TEMPLATE, tableName, "?");
     for (String url : connections) {
       try (Connection connection = DriverManager.getConnection(url, 
connectionProperties)) {
-        try (PreparedStatement statement = 
connection.prepareStatement(QUERY_PARAMETERIZED)) {
-          statement.setString(1, "en");
+        try (PreparedStatement statement = connection.prepareStatement(query)) 
{
+          statement.setLong(1, 1000);
           final ResultSet resultSet = statement.executeQuery();
           int resultRowCount = 0;
           while (resultSet.next()) {
             resultRowCount++;
             LOG.info("%s,%s,%s", resultSet.getString(1), resultSet.getLong(2), 
resultSet.getLong(3));
           }
-          Assert.assertEquals(resultRowCount, 10);
+          Assertions.assertEquals(7, resultRowCount);
           resultSet.close();
         }
       }
       catch (SQLException throwables) {
-        Assert.fail(throwables.getMessage());
+        Assertions.fail(throwables.getMessage());
       }
     }
   }
 
-  @Test(expectedExceptions = AvaticaSqlException.class, 
expectedExceptionsMessageRegExp = ".* No value bound for parameter \\(position 
\\[1]\\)")
-  public void testJdbcPrepareStatementQueryMissingParameters() throws 
SQLException
+  @Test
+  public void testJdbcPrepareStatementQueryMissingParameters()
   {
+    String query = StringUtils.format(QUERY_TEMPLATE, tableName, "?");
     for (String url : connections) {
       try (Connection connection = DriverManager.getConnection(url, 
connectionProperties);
-           PreparedStatement statement = 
connection.prepareStatement(QUERY_PARAMETERIZED);
+           PreparedStatement statement = connection.prepareStatement(query);
            ResultSet resultSet = statement.executeQuery()) {
         // This won't actually run as we expect the exception to be thrown 
before it gets here
         throw new IllegalStateException(resultSet.toString());

Review Comment:
   
https://github.com/apache/druid/pull/18805/commits/0a64c9bc05d01424463e0897a8f069027e12c7a2



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to