-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#6493] feat(CLI): Support table format output for Schema and Table command #6495
[#6493] feat(CLI): Support table format output for Schema and Table command #6495
Conversation
…able command Support table format output for Schema and Table command
…able command fix some bugs.
…able command fix some bugs.
@justinmclean @tengqm could you please review this PR when you have time? I’d really appreciate your feedback. |
clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java
Outdated
Show resolved
Hide resolved
clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java
Show resolved
Hide resolved
clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java
Show resolved
Hide resolved
clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java
Show resolved
Hide resolved
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public String getOutput(Schema schema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual logic that gets overridden is the process of building a list of Columns.
So is it possible to refactor this function into a protected function getColumns
, and then we invoke the public getOutput
function from the parent class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetching the output and fetching the columns represent two different levels of activity, but they're actually doing the same thing in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can invoke the function from the parent class, which is more generic, then you don't have to create a specialized class to invoke the getOutput
method.
I mean this:
class Animal {
public describe() {
legs = getLegs()
wings = getWings()
return "legs:" + legs + 'wings:' + wings
}
protected getLegs() {
return 0
}
protected getWings() {
}
}
class Dog extends Animal {
protected getLegs() {
return 4
}
}
class Duck extends Animal {
protected getWings() {
return 2
}
}
When invoking this method in future, I'll do:
// I don't need to care what kind of an animal it is.
animal.describe()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can invoke the function from the parent class, which is more generic, then you don't have to create a specialized class to invoke the
getOutput
method.I mean this:
class Animal { public describe() { legs = getLegs() wings = getWings() return "legs:" + legs + 'wings:' + wings } protected getLegs() { return 0 } protected getWings() { } } class Dog extends Animal { protected getLegs() { return 4 } } class Duck extends Animal { protected getWings() { return 2 } }
When invoking this method in future, I'll do:
// I don't need to care what kind of an animal it is. animal.describe()
@tengqm In this case, the template pattern is used, BaseOutputFormat#output
is responsible for output, it fix the logic of output method, and the getOutput
method is implemented by subclasses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The merit is that you don't need to instantiate the subclasses, you will save a lot of complicated if...else if...else if...
calls when invoking this method.
The subclasses provide the materials (columns), the superclass does the main logic.
…able command fix some bugs.
…able command fix some bugs.
clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java
Outdated
Show resolved
Hide resolved
clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java
Outdated
Show resolved
Hide resolved
…able command fix some bugs.
@justinmclean I’ve finished updating the code. Please take a look at the PR again when you have time. |
I'm a little concerned that we are calling loadTable/loadSchema when we probably don't need to. If the only reason is for an exact object type, why not create one? |
Or come up with another way i.e. pass an array of strings with the first value being the title and the rest the values in the first column. It seems we are trying to force this code to fit when there are other probably better ways of doing it? |
…able command fix some bugs.
Hi @justinmclean There is no need for load, and since the |
That looks a lot better thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, all looks good
Sad thing is that we are merging this prematurely. |
What changes were proposed in this pull request?
Support table format output for Schema and Table command.
Why are the changes needed?
Fix: #6493
Does this PR introduce any user-facing change?
No.
How was this patch tested?
local test.