ahmedabu98 commented on code in PR #36509:
URL: https://github.com/apache/beam/pull/36509#discussion_r2599852601


##########
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlCliDatabaseTest.java:
##########
@@ -209,4 +211,110 @@ public void testCreateInsertDropTableUsingOtherDatabase() 
{
     cli.execute("DROP TABLE db_1.person");
     
assertNull(catalogManager.currentCatalog().metaStore("db_1").getTable("person"));
   }
+
+  @Test
+  public void testShowCurrentDatabase() {
+    cli.execute("CREATE DATABASE should_not_show_up");
+    cli.execute("CREATE CATALOG my_catalog TYPE 'local'");
+    cli.execute("USE CATALOG my_catalog");
+    cli.execute("CREATE DATABASE my_db");
+    cli.execute("CREATE DATABASE my_other_db");
+    cli.execute("CREATE DATABASE my_database_that_has_a_very_long_name");
+    cli.execute("USE DATABASE my_other_db");
+    ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
+    System.setOut(new PrintStream(outputStreamCaptor));
+    cli.execute("SHOW CURRENT database");
+    @SuppressWarnings("DefaultCharset")
+    String printOutput = outputStreamCaptor.toString().trim();
+
+    assertEquals("my_other_db", printOutput);
+  }
+
+  @Test
+  public void testShowCurrentDatabaseWithNoneSet() {
+    cli.execute("CREATE DATABASE should_not_show_up");
+    cli.execute("CREATE CATALOG my_catalog TYPE 'local'");
+    cli.execute("USE CATALOG my_catalog");
+    cli.execute("DROP DATABASE `default`");
+    ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
+    System.setOut(new PrintStream(outputStreamCaptor));
+    cli.execute("SHOW CURRENT DATABASE");
+    @SuppressWarnings("DefaultCharset")
+    String printOutput = outputStreamCaptor.toString().trim();
+
+    assertEquals("No database is currently set", printOutput);
+  }
+
+  @Test
+  public void testShowDatabases() {
+    cli.execute("CREATE DATABASE should_not_show_up");
+    cli.execute("CREATE CATALOG my_catalog TYPE 'local'");
+    cli.execute("USE CATALOG my_catalog");
+    cli.execute("CREATE DATABASE my_db");
+    cli.execute("CREATE DATABASE my_other_db");
+    cli.execute("CREATE DATABASE my_database_that_has_a_very_long_name");
+    ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
+    System.setOut(new PrintStream(outputStreamCaptor));
+    cli.execute("SHOW DATABASES");
+    @SuppressWarnings("DefaultCharset")
+    String printOutput = outputStreamCaptor.toString().trim();
+
+    assertEquals(
+        "+-----------------------------------------+\n"

Review Comment:
   Made the appropriate refactor to return rows to sqlLine



-- 
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]

Reply via email to