Skip to content

Commit 163515e

Browse files
Resolved changes
1 parent 686a9f3 commit 163515e

17 files changed

+111
-131
lines changed

clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogAudit.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,15 @@ public void handle() {
5353
result = client.loadCatalog(this.catalog);
5454
} catch (NoSuchMetalakeException err) {
5555
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
56-
return; // Stop execution after handling error
5756
} catch (NoSuchCatalogException err) {
5857
exitWithError(ErrorMessages.UNKNOWN_CATALOG);
59-
return; // Stop execution after handling error
6058
} catch (Exception exp) {
6159
exitWithError(exp.getMessage());
62-
return; // Stop execution after handling error
6360
}
6461

65-
// **Null check before accessing auditInfo()**
66-
if (result != null && result.auditInfo() != null) {
62+
// Only check if result is null
63+
if (result != null) {
6764
displayAuditInfo(result.auditInfo());
68-
} else {
69-
exitWithError("Audit information is not available for this catalog.");
7065
}
7166
}
72-
}
67+
}

clients/cli/src/main/java/org/apache/gravitino/cli/commands/FilesetDetails.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class FilesetDetails extends Command {
4343
* @param context The command context.
4444
* @param metalake The name of the metalake.
4545
* @param catalog The name of the catalog.
46-
* @param schema The name of the schenma.
46+
* @param schema The name of the schema.
4747
* @param fileset The name of the fileset.
4848
*/
4949
public FilesetDetails(

clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java

+6-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.apache.gravitino.cli.commands;
2121

22-
import java.util.Map;
2322
import org.apache.gravitino.Catalog;
2423
import org.apache.gravitino.cli.CommandContext;
2524
import org.apache.gravitino.cli.ErrorMessages;
@@ -49,31 +48,19 @@ public ListCatalogProperties(CommandContext context, String metalake, String cat
4948
/** List the properties of a catalog. */
5049
@Override
5150
public void handle() {
52-
Catalog gCatalog = null;
51+
try {
52+
GravitinoClient client = buildClient(metalake);
53+
Catalog gCatalog = client.loadCatalog(catalog);
5354

54-
try (GravitinoClient client = buildClient(metalake)) { // Ensures client is closed
55-
gCatalog = client.loadCatalog(catalog);
55+
if (gCatalog != null) {
56+
printProperties(gCatalog.properties());
57+
}
5658
} catch (NoSuchMetalakeException err) {
5759
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
58-
return;
5960
} catch (NoSuchCatalogException err) {
6061
exitWithError(ErrorMessages.UNKNOWN_CATALOG);
61-
return;
6262
} catch (Exception exp) {
6363
exitWithError(exp.getMessage());
64-
return;
6564
}
66-
67-
if (gCatalog == null) { // Null check before accessing properties
68-
exitWithError("Failed to load catalog.");
69-
return;
70-
}
71-
72-
Map<String, String> properties = gCatalog.properties();
73-
if (properties == null || properties.isEmpty()) {
74-
exitWithError("No properties found for the catalog.");
75-
return;
76-
}
77-
printProperties(properties);
7865
}
7966
}

clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java

+47-44
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package org.apache.gravitino.cli.commands;
2120

22-
import com.google.common.base.Joiner;
2321
import org.apache.gravitino.NameIdentifier;
2422
import org.apache.gravitino.cli.CommandContext;
2523
import org.apache.gravitino.cli.ErrorMessages;
2624
import org.apache.gravitino.exceptions.NoSuchTableException;
2725
import org.apache.gravitino.rel.Column;
26+
import com.google.common.base.Joiner;
2827

2928
/** Displays the details of a table's columns. */
3029
public class ListColumns extends TableCommand {
@@ -48,53 +47,57 @@ public ListColumns(
4847
this.table = table;
4948
}
5049

51-
/** Displays the details of a table's columns. */
52-
@Override
53-
public void handle() {
54-
Column[] columns = null;
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();
5556

56-
try {
57-
NameIdentifier name = NameIdentifier.of(schema, table);
58-
columns = tableCatalog().loadTable(name).columns();
59-
} catch (NoSuchTableException noSuchTableException) {
60-
exitWithError(
61-
ErrorMessages.UNKNOWN_TABLE + Joiner.on(".").join(metalake, catalog, schema, table));
62-
return;
63-
} catch (Exception exp) {
64-
exitWithError(exp.getMessage());
65-
return;
66-
}
57+
if (columns != null && columns.length > 0) {
58+
StringBuilder all = new StringBuilder();
59+
boolean hasAutoIncrement = false;
6760

68-
// Null / empty check before processing columns
69-
if (columns == null || columns.length == 0) {
70-
exitWithError("No columns found for table: " + table);
71-
return;
72-
}
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+
}
7368

74-
StringBuilder all = new StringBuilder();
75-
all.append("name,datatype,comment,nullable,auto_increment").append(System.lineSeparator());
69+
all.append("name,datatype,comment,nullable");
70+
if (hasAutoIncrement) {
71+
all.append(",auto_increment");
72+
}
73+
all.append(System.lineSeparator());
7674

77-
for (Column column : columns) {
78-
if (column == null) continue; // Skip any unexpected null columns
75+
for (Column column : columns) {
76+
if (column == null) {
77+
continue;
78+
}
7979

80-
String name = column.name();
81-
String dataType = column.dataType() != null ? column.dataType().simpleString() : "UNKNOWN";
82-
String comment = column.comment() != null ? column.comment() : "N/A";
83-
String nullable = column.nullable() ? "true" : "false";
84-
String autoIncrement = column.autoIncrement() ? "true" : "false";
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");
8585

86-
all.append(name)
87-
.append(",")
88-
.append(dataType)
89-
.append(",")
90-
.append(comment)
91-
.append(",")
92-
.append(nullable)
93-
.append(",")
94-
.append(autoIncrement)
95-
.append(System.lineSeparator());
96-
}
86+
if (hasAutoIncrement) {
87+
columnDetails.append(",").append(column.autoIncrement() ? "true" : "");
88+
}
9789

98-
printResults(all.toString());
99-
}
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());
101+
}
102+
}
100103
}

clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java

+19-23
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package org.apache.gravitino.cli.commands;
2121

2222
import java.util.Collections;
23-
import java.util.Map;
23+
2424
import org.apache.gravitino.NameIdentifier;
2525
import org.apache.gravitino.cli.CommandContext;
2626
import org.apache.gravitino.cli.ErrorMessages;
@@ -60,27 +60,28 @@ public ListFilesetProperties(
6060
@Override
6161
public void handle() {
6262
Fileset gFileset = null;
63-
NameIdentifier name = null;
63+
6464
try {
65-
name = NameIdentifier.of(schema, fileset);
66-
} catch (Exception exp) {
67-
exitWithError("Invalid schema or fileset name: " + exp.getMessage());
68-
return;
69-
}
70-
try (GravitinoClient client = buildClient(metalake)) {
71-
gFileset = client.loadCatalog(catalog).asFilesetCatalog().loadFileset(name);
65+
NameIdentifier name = NameIdentifier.of(schema, fileset);
66+
67+
try (GravitinoClient client = buildClient(metalake)) {
68+
gFileset = client.loadCatalog(catalog).asFilesetCatalog().loadFileset(name);
69+
}
70+
} catch (IllegalArgumentException exp) {
71+
exitWithError("Invalid schema or fileset name: " + exp.getMessage());
72+
return;
7273
} catch (NoSuchMetalakeException err) {
73-
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
74-
return;
74+
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
75+
return;
7576
} catch (NoSuchCatalogException err) {
76-
exitWithError(ErrorMessages.UNKNOWN_CATALOG);
77-
return;
77+
exitWithError(ErrorMessages.UNKNOWN_CATALOG);
78+
return;
7879
} catch (NoSuchSchemaException err) {
79-
exitWithError(ErrorMessages.UNKNOWN_SCHEMA);
80-
return;
80+
exitWithError(ErrorMessages.UNKNOWN_SCHEMA);
81+
return;
8182
} catch (Exception exp) {
82-
exitWithError(exp.getMessage());
83-
return;
83+
exitWithError(exp.getMessage());
84+
return;
8485
}
8586

8687
// Null check for gFileset before accessing its properties
@@ -89,11 +90,6 @@ public void handle() {
8990
return;
9091
}
9192

92-
Map<String, String> properties = gFileset.properties();
93-
// Use an empty map if properties is null to avoid NPE later on
94-
if (properties == null) {
95-
properties = Collections.emptyMap();
96-
}
97-
printProperties(properties);
93+
printProperties(gFileset.properties() != null ? gFileset.properties() : Collections.emptyMap());
9894
}
9995
}

clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.gravitino.cli.commands;
2121

2222
import java.util.Map;
23+
2324
import org.apache.gravitino.Metalake;
2425
import org.apache.gravitino.cli.CommandContext;
2526
import org.apache.gravitino.cli.ErrorMessages;
@@ -45,20 +46,23 @@ public ListMetalakeProperties(CommandContext context, String metalake) {
4546
/** List the properties of a metalake. */
4647
@Override
4748
public void handle() {
49+
Metalake gMetalake = null;
50+
4851
try (GravitinoAdminClient client = buildAdminClient()) { // Ensure resource cleanup
49-
Metalake gMetalake = client.loadMetalake(metalake);
52+
gMetalake = client.loadMetalake(metalake);
5053

5154
if (gMetalake == null) {
5255
exitWithError("Metalake not found: " + metalake);
5356
return;
5457
}
5558

56-
Map<String, String> properties = gMetalake.properties();
57-
printProperties(properties);
5859
} catch (NoSuchMetalakeException err) {
5960
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
6061
} catch (Exception exp) {
6162
exitWithError(exp.getMessage());
6263
}
64+
65+
Map<String, String> properties = gMetalake.properties();
66+
printProperties(properties);
6367
}
6468
}

clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.gravitino.cli.commands;
2121

2222
import java.util.Map;
23+
2324
import org.apache.gravitino.Schema;
2425
import org.apache.gravitino.cli.CommandContext;
2526
import org.apache.gravitino.cli.ErrorMessages;
@@ -54,16 +55,10 @@ public ListSchemaProperties(
5455
/** List the properties of a schema. */
5556
@Override
5657
public void handle() {
57-
try (GravitinoClient client = buildClient(metalake)) { // Ensure resource cleanup
58-
Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema);
59-
60-
if (gSchema == null) {
61-
exitWithError("Schema not found: " + schema);
62-
return;
63-
}
58+
Schema gSchema = null;
6459

65-
Map<String, String> properties = gSchema.properties();
66-
printProperties(properties);
60+
try (GravitinoClient client = buildClient(metalake)) { // Ensure resource cleanup
61+
gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema);
6762
} catch (NoSuchMetalakeException err) {
6863
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
6964
} catch (NoSuchCatalogException err) {
@@ -73,5 +68,13 @@ public void handle() {
7368
} catch (Exception exp) {
7469
exitWithError(exp.getMessage());
7570
}
71+
72+
if (gSchema == null) {
73+
exitWithError("Schema not found: " + schema);
74+
return;
75+
}
76+
77+
Map<String, String> properties = gSchema.properties();
78+
printProperties(properties);
7679
}
7780
}

clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ListTables extends TableCommand {
3737
* @param context The command context.
3838
* @param metalake The name of the metalake.
3939
* @param catalog The name of the catalog.
40-
* @param schema The name of the schenma.
40+
* @param schema The name of the schema.
4141
*/
4242
public ListTables(CommandContext context, String metalake, String catalog, String schema) {
4343
super(context, metalake, catalog);

clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,14 @@ public void handle() {
7474

7575
} catch (NoSuchMetalakeException err) {
7676
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
77-
return;
7877
} catch (NoSuchCatalogException err) {
7978
exitWithError(ErrorMessages.UNKNOWN_CATALOG);
80-
return;
8179
} catch (NoSuchSchemaException err) {
8280
exitWithError(ErrorMessages.UNKNOWN_SCHEMA);
83-
return;
8481
} catch (NoSuchTopicException err) {
8582
exitWithError(ErrorMessages.UNKNOWN_TOPIC);
86-
return;
8783
} catch (Exception exp) {
88-
exitWithError("An unexpected error occurred: " + exp.getMessage());
89-
return;
84+
exitWithError(exp.getMessage());
9085
}
9186

9287
Map<String, String> properties = gTopic.properties();

clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaAudit.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class SchemaAudit extends AuditCommand {
4040
* @param context The command context.
4141
* @param metalake The name of the metalake.
4242
* @param catalog The name of the catalog.
43-
* @param schema The name of the schenma.
43+
* @param schema The name of the schema.
4444
*/
4545
public SchemaAudit(CommandContext context, String metalake, String catalog, String schema) {
4646
super(context);

clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class SchemaDetails extends Command {
4040
* @param context The command context.
4141
* @param metalake The name of the metalake.
4242
* @param catalog The name of the catalog.
43-
* @param schema The name of the schenma.
43+
* @param schema The name of the schema.
4444
*/
4545
public SchemaDetails(CommandContext context, String metalake, String catalog, String schema) {
4646
super(context);

0 commit comments

Comments
 (0)