Skip to content

Commit 90d4c07

Browse files
committed
hive增加view的查看。
1 parent c5c0d00 commit 90d4c07

File tree

1 file changed

+26
-0
lines changed
  • chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive

1 file changed

+26
-0
lines changed

chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/HiveMetaData.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,31 @@ private static Map<String, String> getDescTableModule() {
262262
public static String format(String name) {
263263
return "`" + name + "`";
264264
}
265+
266+
private static String VIEW_SQL
267+
= "SHOW CREATE TABLE `%s`.`%s`";
268+
269+
@Override
270+
public Table view(Connection connection, String databaseName, String schemaName, String viewName) {
271+
String sql = String.format(VIEW_SQL, databaseName, viewName);
272+
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
273+
Table table = new Table();
274+
table.setDatabaseName(databaseName);
275+
table.setSchemaName(schemaName);
276+
table.setName(viewName);
277+
StringBuilder sb = new StringBuilder();
278+
while (resultSet.next()) {
279+
// 拼接建表语句
280+
sb.append(resultSet.getString("createtab_stmt"));
281+
sb.append("\r\n");
282+
}
283+
if (sb.length() > 0) {
284+
sb = sb.delete(sb.length() - 2, sb.length());
285+
sb.append(";");
286+
table.setDdl(sb.toString());
287+
}
288+
return table;
289+
});
290+
}
265291
}
266292

0 commit comments

Comments
 (0)