|
47 | 47 | import java.util.Objects;
|
48 | 48 | import org.apache.gravitino.Catalog;
|
49 | 49 | import org.apache.gravitino.Metalake;
|
| 50 | +import org.apache.gravitino.Schema; |
50 | 51 | import org.apache.gravitino.cli.CommandContext;
|
| 52 | +import org.apache.gravitino.rel.Table; |
51 | 53 |
|
52 | 54 | /**
|
53 | 55 | * Abstract base class for formatting entity information into ASCII-art tables. Provides
|
@@ -75,6 +77,14 @@ public static void output(Object entity, CommandContext context) {
|
75 | 77 | new CatalogTableFormat(context).output((Catalog) entity);
|
76 | 78 | } else if (entity instanceof Catalog[]) {
|
77 | 79 | new CatalogListTableFormat(context).output((Catalog[]) entity);
|
| 80 | + } else if (entity instanceof Schema) { |
| 81 | + new SchemaTableFormat(context).output((Schema) entity); |
| 82 | + } else if (entity instanceof Schema[]) { |
| 83 | + new SchemaListTableFormat(context).output((Schema[]) entity); |
| 84 | + } else if (entity instanceof Table) { |
| 85 | + new TableDetailsTableFormat(context).output((Table) entity); |
| 86 | + } else if (entity instanceof Table[]) { |
| 87 | + new TableListTableFormat(context).output((Table[]) entity); |
78 | 88 | } else {
|
79 | 89 | throw new IllegalArgumentException("Unsupported object type");
|
80 | 90 | }
|
@@ -540,4 +550,97 @@ public String getOutput(Catalog[] catalogs) {
|
540 | 550 | return getTableFormat(columnName);
|
541 | 551 | }
|
542 | 552 | }
|
| 553 | + |
| 554 | + /** |
| 555 | + * Formats a single {@link Schema} instance into a two-column table display. Displays catalog |
| 556 | + * details including name and comment information. |
| 557 | + */ |
| 558 | + static final class SchemaTableFormat extends TableFormat<Schema> { |
| 559 | + public SchemaTableFormat(CommandContext context) { |
| 560 | + super(context); |
| 561 | + } |
| 562 | + |
| 563 | + /** {@inheritDoc} */ |
| 564 | + @Override |
| 565 | + public String getOutput(Schema schema) { |
| 566 | + Column columnName = new Column(context, "schema"); |
| 567 | + Column columnComment = new Column(context, "comment"); |
| 568 | + |
| 569 | + columnName.addCell(schema.name()); |
| 570 | + columnComment.addCell(schema.comment()); |
| 571 | + |
| 572 | + return getTableFormat(columnName, columnComment); |
| 573 | + } |
| 574 | + } |
| 575 | + |
| 576 | + /** |
| 577 | + * Formats an array of Schemas into a single-column table display. Lists all schema names in a |
| 578 | + * vertical format. |
| 579 | + */ |
| 580 | + static final class SchemaListTableFormat extends TableFormat<Schema[]> { |
| 581 | + public SchemaListTableFormat(CommandContext context) { |
| 582 | + super(context); |
| 583 | + } |
| 584 | + |
| 585 | + /** {@inheritDoc} */ |
| 586 | + @Override |
| 587 | + public String getOutput(Schema[] schemas) { |
| 588 | + Column column = new Column(context, "schema"); |
| 589 | + Arrays.stream(schemas).forEach(schema -> column.addCell(schema.name())); |
| 590 | + |
| 591 | + return getTableFormat(column); |
| 592 | + } |
| 593 | + } |
| 594 | + |
| 595 | + /** |
| 596 | + * Formats a single {@link Table} instance into a two-column table display. Displays table details |
| 597 | + * including name and comment information. |
| 598 | + */ |
| 599 | + static final class TableDetailsTableFormat extends TableFormat<Table> { |
| 600 | + public TableDetailsTableFormat(CommandContext context) { |
| 601 | + super(context); |
| 602 | + } |
| 603 | + |
| 604 | + /** {@inheritDoc} */ |
| 605 | + @Override |
| 606 | + public String getOutput(Table table) { |
| 607 | + Column columnName = new Column(context, "name"); |
| 608 | + Column columnType = new Column(context, "type"); |
| 609 | + Column columnAutoIncrement = new Column(context, "AutoIncrement"); |
| 610 | + Column columnNullable = new Column(context, "nullable"); |
| 611 | + Column columnComment = new Column(context, "comment"); |
| 612 | + |
| 613 | + org.apache.gravitino.rel.Column[] columns = table.columns(); |
| 614 | + for (org.apache.gravitino.rel.Column column : columns) { |
| 615 | + columnName.addCell(column.name()); |
| 616 | + columnType.addCell(column.dataType().simpleString()); |
| 617 | + columnAutoIncrement.addCell(column.autoIncrement()); |
| 618 | + columnNullable.addCell(column.nullable()); |
| 619 | + columnComment.addCell( |
| 620 | + column.comment() == null || column.comment().isEmpty() ? "N/A" : column.comment()); |
| 621 | + } |
| 622 | + |
| 623 | + return getTableFormat( |
| 624 | + columnName, columnType, columnAutoIncrement, columnNullable, columnComment); |
| 625 | + } |
| 626 | + } |
| 627 | + |
| 628 | + /** |
| 629 | + * Formats an array of {@link Table} into a single-column table display. Lists all table names in |
| 630 | + * a vertical format. |
| 631 | + */ |
| 632 | + static final class TableListTableFormat extends TableFormat<Table[]> { |
| 633 | + public TableListTableFormat(CommandContext context) { |
| 634 | + super(context); |
| 635 | + } |
| 636 | + |
| 637 | + /** {@inheritDoc} */ |
| 638 | + @Override |
| 639 | + public String getOutput(Table[] tables) { |
| 640 | + Column column = new Column(context, "table"); |
| 641 | + Arrays.stream(tables).forEach(table -> column.addCell(table.name())); |
| 642 | + |
| 643 | + return getTableFormat(column); |
| 644 | + } |
| 645 | + } |
543 | 646 | }
|
0 commit comments