Skip to content

Commit

Permalink
Merge branch 'main' into dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryshao authored Feb 25, 2025
2 parents e2112bc + 4996d0c commit e1f68e6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,10 @@ public void handle() {}
* @param audit from a class that implements the Auditable interface.
*/
public void displayAuditInfo(Audit audit) {
String auditInfo =
"creator,create_time,modified,modified_time"
+ System.lineSeparator()
+ audit.creator()
+ ","
+ audit.createTime()
+ ","
+ audit.lastModifier()
+ ","
+ audit.lastModifiedTime();
if (audit == null) {
return;
}

printResults(auditInfo);
printResults(audit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public void handle() {
exitWithError(exp.getMessage());
}

if (result != null) {
displayAuditInfo(result.auditInfo());
}
displayAuditInfo(result.auditInfo());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public void handle() {
exitWithError(exp.getMessage());
}

if (result != null) {
displayAuditInfo(result.auditInfo());
}
displayAuditInfo(result.auditInfo());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.apache.gravitino.Audit;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Metalake;
import org.apache.gravitino.Schema;
Expand Down Expand Up @@ -85,6 +86,8 @@ public static void output(Object entity, CommandContext context) {
new TableDetailsTableFormat(context).output((Table) entity);
} else if (entity instanceof Table[]) {
new TableListTableFormat(context).output((Table[]) entity);
} else if (entity instanceof Audit) {
new AuditTableFormat(context).output((Audit) entity);
} else {
throw new IllegalArgumentException("Unsupported object type");
}
Expand Down Expand Up @@ -643,4 +646,31 @@ public String getOutput(Table[] tables) {
return getTableFormat(column);
}
}

/**
* Formats a single {@link Audit} instance into a four-column table display. Displays audit
* details, including creator, create time, modified, and modify time.
*/
static final class AuditTableFormat extends TableFormat<Audit> {
public AuditTableFormat(CommandContext context) {
super(context);
}

/** {@inheritDoc} */
@Override
public String getOutput(Audit audit) {
Column columnCreator = new Column(context, "creator");
Column columnCreateTime = new Column(context, "creation at");
Column columnModified = new Column(context, "modifier");
Column columnModifyTime = new Column(context, "modified at");

columnCreator.addCell(audit.creator());
columnCreateTime.addCell(audit.createTime() == null ? "N/A" : audit.createTime().toString());
columnModified.addCell(audit.lastModifier() == null ? "N/A" : audit.lastModifier());
columnModifyTime.addCell(
audit.lastModifiedTime() == null ? "N/A" : audit.lastModifiedTime().toString());

return getTableFormat(columnCreator, columnCreateTime, columnModified, columnModifyTime);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import org.apache.gravitino.Audit;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Metalake;
import org.apache.gravitino.Schema;
Expand Down Expand Up @@ -373,6 +375,48 @@ void testListTableWithTableFormat() {
output);
}

@Test
void testAuditWithTableFormat() {
CommandContext mockContext = getMockContext();
Audit mockAudit = mock(Audit.class);
when(mockAudit.creator()).thenReturn("demo_user");
when(mockAudit.createTime()).thenReturn(Instant.ofEpochMilli(1611111111111L));
when(mockAudit.lastModifier()).thenReturn("demo_user");
when(mockAudit.lastModifiedTime()).thenReturn(Instant.ofEpochMilli(1611111111111L));

TableFormat.output(mockAudit, mockContext);

String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim();
Assertions.assertEquals(
"+-----------+--------------------------+-----------+--------------------------+\n"
+ "| Creator | Creation at | Modifier | Modified at |\n"
+ "+-----------+--------------------------+-----------+--------------------------+\n"
+ "| demo_user | 2021-01-20T02:51:51.111Z | demo_user | 2021-01-20T02:51:51.111Z |\n"
+ "+-----------+--------------------------+-----------+--------------------------+",
output);
}

@Test
void testAuditWithTableFormatWithNullValues() {
CommandContext mockContext = getMockContext();
Audit mockAudit = mock(Audit.class);
when(mockAudit.creator()).thenReturn("demo_user");
when(mockAudit.createTime()).thenReturn(null);
when(mockAudit.lastModifier()).thenReturn(null);
when(mockAudit.lastModifiedTime()).thenReturn(null);

TableFormat.output(mockAudit, mockContext);

String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim();
Assertions.assertEquals(
"+-----------+-------------+----------+-------------+\n"
+ "| Creator | Creation at | Modifier | Modified at |\n"
+ "+-----------+-------------+----------+-------------+\n"
+ "| demo_user | N/A | N/A | N/A |\n"
+ "+-----------+-------------+----------+-------------+",
output);
}

@Test
void testOutputWithUnsupportType() {
CommandContext mockContext = getMockContext();
Expand Down
2 changes: 1 addition & 1 deletion clients/filesystem-fuse/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ check-cargo-sort: install-cargo-sort
cargo sort -c

install-cargo-machete:
cargo install cargo-machete
cargo install cargo-machete@0.7.0

cargo-machete: install-cargo-machete
cargo machete
Expand Down

0 comments on commit e1f68e6

Please sign in to comment.