Skip to content

Go:cli move _order _columns sort group - #16615

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
myf-bee:maoyifeng-go-cli-ky-3
Jul 3, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
myf-bee:maoyifeng-go-cli-ky-3

Conversation

@myf-bee

@myf-bee myf-bee commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  1. Move common functions to format.go
  2. modify show name spaces to _
  3. move _order _columns column sort group;
  4. add dao empty enterprise file

2.modify show name spaces to _

3.remove _order _columns column sort group;

4.add dao empty enterprise file
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR removes ordered CLI table rendering helpers, updates response printers to use raw map output, adds common byte/number/time formatting helpers, and adds three empty DAO package scaffold files.

Changes

CLI Table Output Simplification

Layer / File(s) Summary
Remove ordered table printer and column extractor
internal/cli/table.go
PrintTableSimpleByFormatWithOrder and ExtractColumnsAndCleanData are removed.
Update response printers to use raw map output
internal/cli/response.go
CommonDataResponse, UserIndexResponse, UserStorageResponse, UserQuotaResponse, OrderedCommonResponse, OrderedCommonDataResponse, and QuotaSummaryResponse stop building ordered rows/columns and instead append raw maps, printing via PrintTableSimpleByFormat.

Common Formatting Helpers

Layer / File(s) Summary
Add byte/number/time formatting and parsing helpers
internal/common/format.go
New exported functions FormatBytes, FormatNumber, ParseBytesString, and FormatTime are added, with strconv and time imports.

Enterprise DAO Scaffold Files

Layer / File(s) Summary
Add empty enterprise DAO package files
internal/dao/enterprise_data.go, internal/dao/enterprise_tasks.go, internal/dao/enterprise_user.go
Three new files each contain only the license header and package dao declaration.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#16263: Introduced the ordered table and metric rendering that this PR removes.
  • infiniflow/ragflow#16347: Introduced ordered response wrapping with ExtractColumnsAndCleanData and PrintTableSimpleByFormatWithOrder, which this PR replaces.
  • infiniflow/ragflow#16454: Introduced ordered QuotaSummaryResponse.PrintOut rendering that this PR refactors to raw-map printing.

Suggested reviewers: yuzhichang

Poem

A rabbit hopped through columns tall,
Then let the simple tables fall. 🐇
Bytes and time now print with ease,
New burrows dug for DAO trees.
The CLI sings a lighter tune,
Under the bright formatting moon.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is related to the main CLI ordering and column-formatting changes, though it is a bit noisy.
Description check ✅ Passed The description matches the required Summary section and covers the main changes, but it lacks background context.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/cli/response.go (1)

1197-1232: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Section titles no longer printed for quota summary.

The sections list dropped the "title" field entirely (previously key/title/columns), and the loop only prints a blank-line separator between sections — no header identifying whether a table is for "storage", "apps", or "api". In table/plain format, users can no longer tell which section a given table belongs to, especially since "No data" messages are now also unlabeled.

🔧 Suggested fix: restore section headers
-	sections := []string{"storage", "apps", "api"}
+	sections := []string{"storage", "apps", "api"}
+	titles := map[string]string{
+		"storage": "Storage",
+		"apps":    "Apps",
+		"api":     "API",
+	}

 	for i, key := range sections {
 		if i > 0 {
 			fmt.Println()
 		}
+		fmt.Printf("%s:\n", titles[key])

 		rowsRaw, ok := r.Data[key]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/response.go` around lines 1197 - 1232, The quota summary output
in QuotaSummaryResponse.PrintOut no longer labels each section, so users cannot
tell whether a table or “No data” message belongs to storage, apps, or api.
Restore a section header per entry in the sections loop (for example by
iterating over title/key metadata instead of just keys) and print it before each
section’s content, including the empty-data path, while keeping the existing
table rendering with PrintTableSimpleByFormat.
🧹 Nitpick comments (1)
internal/common/format.go (1)

157-162: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

FormatTime uses local timezone implicitly.

time.UnixMilli(*t).Format(...) renders in the server's local timezone. If callers (or display consumers) expect UTC or a consistent timezone across environments, this can produce inconsistent output depending on where the CLI runs.

Consider being explicit, e.g. time.UnixMilli(*t).UTC().Format(...) if consistency across environments is desired.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/common/format.go` around lines 157 - 162, FormatTime currently
formats Unix milliseconds in the server’s local timezone, which can vary across
environments. Update FormatTime to be explicit about the timezone by converting
the time value in the time.UnixMilli path to UTC before formatting, so callers
get consistent output regardless of where the CLI runs. Use the FormatTime
function in internal/common/format.go as the place to apply this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cli/response.go`:
- Around line 129-138: The metric rows are built from direct map iteration in
orderedMetricTable, which makes UserIndexResponse, UserStorageResponse, and
OrderedCommonDataResponse output unstable. Update orderedMetricTable in
CommonDataResponse to collect the keys from r.Data, sort them, and then append
the "Metric"/"Value" entries in that sorted order so the output is deterministic
and the helper name remains accurate.

In `@internal/common/format.go`:
- Around line 112-123: FormatNumber currently groups the minus sign with digits
for negative values, which produces malformed output like "-,100". Update
FormatNumber to handle the sign separately from the digit grouping logic, using
the existing FormatNumber function as the target, so the loop only formats the
absolute digits and then reattaches the sign for negative inputs.

---

Outside diff comments:
In `@internal/cli/response.go`:
- Around line 1197-1232: The quota summary output in
QuotaSummaryResponse.PrintOut no longer labels each section, so users cannot
tell whether a table or “No data” message belongs to storage, apps, or api.
Restore a section header per entry in the sections loop (for example by
iterating over title/key metadata instead of just keys) and print it before each
section’s content, including the empty-data path, while keeping the existing
table rendering with PrintTableSimpleByFormat.

---

Nitpick comments:
In `@internal/common/format.go`:
- Around line 157-162: FormatTime currently formats Unix milliseconds in the
server’s local timezone, which can vary across environments. Update FormatTime
to be explicit about the timezone by converting the time value in the
time.UnixMilli path to UTC before formatting, so callers get consistent output
regardless of where the CLI runs. Use the FormatTime function in
internal/common/format.go as the place to apply this change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 84078c61-d725-42a1-9851-e2cda413c108

📥 Commits

Reviewing files that changed from the base of the PR and between ffc4d29 and 40e20ee.

📒 Files selected for processing (6)
  • internal/cli/response.go
  • internal/cli/table.go
  • internal/common/format.go
  • internal/dao/enterprise_data.go
  • internal/dao/enterprise_tasks.go
  • internal/dao/enterprise_user.go
💤 Files with no reviewable changes (1)
  • internal/cli/table.go

Comment thread internal/cli/response.go
Comment on lines 129 to 138
func (r *CommonDataResponse) orderedMetricTable() []map[string]interface{} {
table := make([]map[string]interface{}, 0)
if orderRaw, ok := r.Data["_order"]; ok {
if orderSlice, ok := orderRaw.([]interface{}); ok {
for _, keyRaw := range orderSlice {
key := fmt.Sprintf("%v", keyRaw)
if value, exists := r.Data[key]; exists {
table = append(table, map[string]interface{}{
"Metric": key,
"Value": value,
})
}
}
}
for key, value := range r.Data {
table = append(table, map[string]interface{}{
"Metric": key,
"Value": value,
})
}
return table
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Non-deterministic metric ordering from raw map iteration.

orderedMetricTable() now iterates r.Data (a map[string]interface{}) directly without sorting keys. Go's for range over a map has randomized iteration order, so the "Metric"/"Value" rows built here — and consumed by UserIndexResponse (Line 1010), UserStorageResponse (Line 1069), and OrderedCommonDataResponse (Line 1171) — will print in a different order on every invocation, including in JSON output. This also makes the function name misleading, since it no longer orders anything.

🔧 Suggested fix: sort keys for stable output
+import "sort"
+
 func (r *CommonDataResponse) orderedMetricTable() []map[string]interface{} {
 	table := make([]map[string]interface{}, 0)
-	for key, value := range r.Data {
-		table = append(table, map[string]interface{}{
-			"Metric": key,
-			"Value":  value,
-		})
-	}
+	keys := make([]string, 0, len(r.Data))
+	for key := range r.Data {
+		keys = append(keys, key)
+	}
+	sort.Strings(keys)
+	for _, key := range keys {
+		table = append(table, map[string]interface{}{
+			"Metric": key,
+			"Value":  r.Data[key],
+		})
+	}
 	return table
 }

Also applies to: 1010-1010, 1069-1069, 1171-1171

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/response.go` around lines 129 - 138, The metric rows are built
from direct map iteration in orderedMetricTable, which makes UserIndexResponse,
UserStorageResponse, and OrderedCommonDataResponse output unstable. Update
orderedMetricTable in CommonDataResponse to collect the keys from r.Data, sort
them, and then append the "Metric"/"Value" entries in that sorted order so the
output is deterministic and the helper name remains accurate.

Comment thread internal/common/format.go
Comment on lines +112 to +123
func FormatNumber(n int64) string {
s := fmt.Sprintf("%d", n)
parts := []string{}
for i := len(s); i > 0; i -= 3 {
start := i - 3
if start < 0 {
start = 0
}
parts = append([]string{s[start:i]}, parts...)
}
return strings.Join(parts, ",")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

FormatNumber mis-groups the sign for negative numbers.

The digit-grouping loop treats the leading - sign as part of a 3-character group, producing incorrect output whenever the digit count isn't a multiple of 3. E.g. FormatNumber(-100) returns "-,100" instead of "-100".

🐛 Proposed fix to handle the sign separately
 func FormatNumber(n int64) string {
-	s := fmt.Sprintf("%d", n)
+	sign := ""
+	if n < 0 {
+		sign = "-"
+		n = -n
+	}
+	s := fmt.Sprintf("%d", n)
 	parts := []string{}
 	for i := len(s); i > 0; i -= 3 {
 		start := i - 3
 		if start < 0 {
 			start = 0
 		}
 		parts = append([]string{s[start:i]}, parts...)
 	}
-	return strings.Join(parts, ",")
+	return sign + strings.Join(parts, ",")
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/common/format.go` around lines 112 - 123, FormatNumber currently
groups the minus sign with digits for negative values, which produces malformed
output like "-,100". Update FormatNumber to handle the sign separately from the
digit grouping logic, using the existing FormatNumber function as the target, so
the loop only formats the absolute digits and then reattaches the sign for
negative inputs.

@myf-bee myf-bee added the ci Continue Integration label Jul 3, 2026
@JinHai-CN
JinHai-CN merged commit 0f4f213 into infiniflow:main Jul 3, 2026
6 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
### Summary
1. Move common functions to format.go
2. modify show name spaces to _
3. move _order _columns column sort group;
4. add dao empty enterprise file
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
### Summary
1. Move common functions to format.go
2. modify show name spaces to _
3. move _order _columns column sort group;
4. add dao empty enterprise file
@myf-bee
myf-bee deleted the maoyifeng-go-cli-ky-3 branch August 5, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants