Skip to content

Commit

Permalink
support view for table list
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmikechen committed Aug 25, 2024
1 parent f2c3dd3 commit 3b9bee1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -889,6 +886,20 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
buildFilters(sql, filters);
sql.append("\nORDER BY table_type, table_catalog, table_schema, table_name");

if (types == null || types.length == 0 || Arrays.stream(types).allMatch(t -> t.equalsIgnoreCase("VIEW"))) {
// add view
sql.append("\n union all ");
sql.append("\nselect database TABLE_CAT, database TABLE_SCHEM, name TABLE_NAME, 'VIEW' TABLE_TYPE, null REMARKS, ");
sql.append("'' as TYPE_CAT, engine as TYPE_SCHEM, engine as TYPE_NAME, '' as SELF_REFERENCING_COL_NAME, '' as REF_GENERATION ");
sql.append("from system.views ");
filters = new ArrayList<>();
emptyStringEqualsFilter(filters, "database", catalog);
emptyStringLikeFilter(filters, "database", schemaPattern);
optionalStringLikeFilter(filters, "name", tableNamePattern);
buildFilters(sql, filters);
sql.append("\nORDER BY TABLE_CAT, TABLE_NAME, TABLE_TYPE");
}

return select(sql.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void testSelectWithPreparement()
}
}

@Test(groups = {"IT", "FLAKY"})
@Test(groups = {"IT"})
public void testSelectGeometry() throws SQLException, ParseException {
// skip due to failed cluster tests

Expand All @@ -344,7 +344,7 @@ public void testSelectGeometry() throws SQLException, ParseException {
connection.createStatement().execute("INSERT INTO cities (id, name, location) VALUES (1, 'New York', 'POINT (-73.935242 40.73061))');");
connection.createStatement().execute("INSERT INTO cities (id, name, location) VALUES (2, 'Null', null);");
Statement statement = connection.createStatement();
try (ResultSet r = statement.executeQuery("select location from cities")) {
try (ResultSet r = statement.executeQuery("select location from cities order by id")) {
r.next();
Assert.assertEquals("{\"type\": \"Point\", \"coordinates\": [-73.935242,40.73061]}", r.getObject(1));
r.next();
Expand All @@ -353,7 +353,7 @@ public void testSelectGeometry() throws SQLException, ParseException {

// set geometry_output_format to wkb
connection.createStatement().execute("set geometry_output_format='WKB'");
try (ResultSet r = statement.executeQuery("select location from cities")) {
try (ResultSet r = statement.executeQuery("select location from cities order by id")) {
r.next();
byte[] wkb = r.getBytes(1);
WKBReader wkbReader = new WKBReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ public void setUp()
c.createStatement().execute("drop table if exists test_column_meta");
c.createStatement().execute("drop table if exists decimal_test");
c.createStatement().execute("drop table if exists test_comment");
c.createStatement().execute("drop view if exists v_test_comment");
c.createStatement().execute("create table test_column_meta (nu1 uint8 null, u1 uint8, u2 uint16, u3 uint32, u4 uint64, i1 int8, i2 int16, i3 int32, i4 int64, f1 float32, f2 float64, s1 string,d1 date, d2 datetime, v1 variant, a1 array(int64), t1 Tuple(x Int64, y Int64 NULL)) engine = fuse");
c.createStatement().execute("create table decimal_test (a decimal(4,2))");
c.createStatement().execute("create table test_comment (a int comment 'test comment')");
c.createStatement().execute("create view v_test_comment as select * from test_comment");
// json data
}

Expand Down Expand Up @@ -121,6 +123,15 @@ public void testGetTables() throws Exception {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet rs = connection.getMetaData().getTables(null, null, null, null)) {
assertTableMetadata(rs);
// test for view
boolean foundView = false;
while (rs.next()) {
if ("v_test_comment".equals(rs.getString(3))) {
foundView = true;
break;
}
}
Assert.assertTrue(foundView, "can not found view [v_test_comment]");
}
}
}
Expand Down

0 comments on commit 3b9bee1

Please sign in to comment.