@@ -48,7 +48,9 @@ public List<Schema> schemas(Connection connection, String databaseName) {
4848 @ Override
4949 public String tableDDL (Connection connection , @ NotEmpty String databaseName , String schemaName ,
5050 @ NotEmpty String tableName ) {
51- String sql = "SHOW CREATE TABLE " + format (databaseName ) + "."
51+ // In Hive, schema and database are the same concept. Fall back to schemaName when databaseName is absent.
52+ String effectiveDb = StringUtils .isNotBlank (databaseName ) ? databaseName : schemaName ;
53+ String sql = "SHOW CREATE TABLE " + format (effectiveDb ) + "."
5254 + format (tableName );
5355 return SQLExecutor .getInstance ().execute (connection , sql , resultSet -> {
5456 StringBuilder sb = new StringBuilder ();
@@ -97,7 +99,9 @@ public SqlBuilder getSqlBuilder() {
9799 // TODO 待完善
98100 @ Override
99101 public List <TableColumn > columns (Connection connection , String databaseName , String schemaName , String tableName ) {
100- String sql = String .format (SELECT_TAB_COLS , databaseName , tableName );
102+ // In Hive, schema and database are the same concept. Fall back to schemaName when databaseName is absent.
103+ String effectiveDb = StringUtils .isNotBlank (databaseName ) ? databaseName : schemaName ;
104+ String sql = String .format (SELECT_TAB_COLS , effectiveDb , tableName );
101105 return SQLExecutor .getInstance ().execute (connection , sql , resultSet -> {
102106 List <TableColumn > tableColumns = new ArrayList <>();
103107 Map <String , String > detailTableInfo = new HashMap <>();
@@ -268,7 +272,9 @@ public static String format(String name) {
268272
269273 @ Override
270274 public Table view (Connection connection , String databaseName , String schemaName , String viewName ) {
271- String sql = String .format (VIEW_SQL , databaseName , viewName );
275+ // In Hive, schema and database are the same concept. Fall back to schemaName when databaseName is absent.
276+ String effectiveDb = StringUtils .isNotBlank (databaseName ) ? databaseName : schemaName ;
277+ String sql = String .format (VIEW_SQL , effectiveDb , viewName );
272278 return SQLExecutor .getInstance ().execute (connection , sql , resultSet -> {
273279 Table table = new Table ();
274280 table .setDatabaseName (databaseName );
0 commit comments