18
18
*/
19
19
package org .apache .gravitino .cli .commands ;
20
20
21
+ import com .google .common .base .Joiner ;
21
22
import org .apache .gravitino .NameIdentifier ;
22
23
import org .apache .gravitino .cli .CommandContext ;
23
24
import org .apache .gravitino .cli .ErrorMessages ;
24
25
import org .apache .gravitino .exceptions .NoSuchTableException ;
25
26
import org .apache .gravitino .rel .Column ;
26
- import com .google .common .base .Joiner ;
27
27
28
28
/** Displays the details of a table's columns. */
29
29
public class ListColumns extends TableCommand {
@@ -47,57 +47,45 @@ public ListColumns(
47
47
this .table = table ;
48
48
}
49
49
50
- /** Displays the details of a table's columns. */
51
- @ Override
52
- public void handle () {
53
- try {
54
- NameIdentifier name = NameIdentifier .of (schema , table );
55
- Column [] columns = tableCatalog ().loadTable (name ).columns ();
56
-
57
- if (columns != null && columns .length > 0 ) {
58
- StringBuilder all = new StringBuilder ();
59
- boolean hasAutoIncrement = false ;
60
-
61
- // Check if any column supports auto-increment
62
- for (Column column : columns ) {
63
- if (column != null && column .autoIncrement ()) {
64
- hasAutoIncrement = true ;
65
- break ;
66
- }
67
- }
50
+ /** Displays the details of a table's columns. */
51
+ @ Override
52
+ public void handle () {
53
+ try {
54
+ NameIdentifier name = NameIdentifier .of (schema , table );
55
+ Column [] columns = tableCatalog ().loadTable (name ).columns ();
68
56
69
- all .append ("name,datatype,comment,nullable" );
70
- if (hasAutoIncrement ) {
71
- all .append (",auto_increment" );
72
- }
73
- all .append (System .lineSeparator ());
57
+ if (columns != null && columns .length > 0 ) {
58
+ StringBuilder all = new StringBuilder ();
59
+ all .append ("name,datatype,comment,nullable,auto_increment" ).append (System .lineSeparator ());
74
60
75
- for (Column column : columns ) {
76
- if (column == null ) {
77
- continue ;
78
- }
61
+ for (Column column : columns ) {
62
+ if (column == null ) {
63
+ continue ;
64
+ }
79
65
80
- StringBuilder columnDetails = new StringBuilder ();
81
- columnDetails .append (column .name ()).append ("," );
82
- columnDetails .append (column .dataType () != null ? column .dataType ().simpleString () : "UNKNOWN" ).append ("," );
83
- columnDetails .append (column .comment () != null ? column .comment () : "N/A" ).append ("," );
84
- columnDetails .append (column .nullable () ? "true" : "false" );
66
+ StringBuilder columnDetails = new StringBuilder ();
67
+ columnDetails .append (column .name ()).append ("," );
68
+ columnDetails
69
+ .append (column .dataType () != null ? column .dataType ().simpleString () : "UNKNOWN" )
70
+ .append ("," );
71
+ columnDetails .append (column .comment () != null ? column .comment () : "N/A" ).append ("," );
72
+ columnDetails .append (column .nullable () ? "true" : "false" ).append ("," );
73
+ columnDetails .append (column .autoIncrement () ? "true" : "false" );
85
74
86
- if (hasAutoIncrement ) {
87
- columnDetails .append ("," ).append (column .autoIncrement () ? "true" : "" );
88
- }
89
-
90
- all .append (columnDetails ).append (System .lineSeparator ());
91
- }
92
-
93
- printResults (all .toString ());
94
- } else {
95
- exitWithError ("No columns found for the specified table." );
96
- }
97
- } catch (NoSuchTableException noSuchTableException ) {
98
- exitWithError (ErrorMessages .UNKNOWN_TABLE + " " + Joiner .on ("." ).join (metalake , catalog , schema , table ));
99
- } catch (Exception exp ) {
100
- exitWithError ("An error occurred while retrieving column details: " + exp .getMessage ());
75
+ all .append (columnDetails ).append (System .lineSeparator ());
101
76
}
77
+
78
+ printResults (all .toString ());
79
+ } else {
80
+ exitWithError ("No columns found for the specified table." );
81
+ }
82
+ } catch (NoSuchTableException noSuchTableException ) {
83
+ exitWithError (
84
+ ErrorMessages .UNKNOWN_TABLE
85
+ + " "
86
+ + Joiner .on ("." ).join (metalake , catalog , schema , table ));
87
+ } catch (Exception exp ) {
88
+ exitWithError ("An error occurred while retrieving column details: " + exp .getMessage ());
102
89
}
90
+ }
103
91
}
0 commit comments