mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-25 16:04:02 +08:00
- 新增 ExportFileOptions 统一承载导出格式、进度任务和 XLSX sheet 行数上限 - 查询导出改为流式写入文件,避免一次性缓存整批结果导致高内存占用 - 增加值数组快速路径并复用扫描与写入缓冲,减少逐行 map 分配开销 - 为 ClickHouse、自定义驱动、达梦、SQLServer 和 TDengine 补齐 StreamQuery 支持 - 导出时间字符串仅在形似时间时再解析,避免普通文本被误判改写 - 补充 XLSX 分 sheet、流式导出和基准测试覆盖
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package app
|
|
|
|
import "strings"
|
|
|
|
const (
|
|
maxXLSXRowsPerSheet = 1048575
|
|
defaultXLSXRowsPerSheet = maxXLSXRowsPerSheet
|
|
)
|
|
|
|
type ExportFileOptions struct {
|
|
Format string `json:"format"`
|
|
XLSXMaxRowsPerSheet int `json:"xlsxMaxRowsPerSheet,omitempty"`
|
|
JobID string `json:"jobId,omitempty"`
|
|
TotalRowsHint int64 `json:"totalRowsHint,omitempty"`
|
|
TotalRowsKnown bool `json:"totalRowsKnown,omitempty"`
|
|
}
|
|
|
|
func normalizeExportFileOptions(format string, options ExportFileOptions) ExportFileOptions {
|
|
resolvedFormat := strings.ToLower(strings.TrimSpace(format))
|
|
if explicitFormat := strings.ToLower(strings.TrimSpace(options.Format)); explicitFormat != "" {
|
|
resolvedFormat = explicitFormat
|
|
}
|
|
return ExportFileOptions{
|
|
Format: resolvedFormat,
|
|
XLSXMaxRowsPerSheet: normalizeXLSXRowsPerSheet(options.XLSXMaxRowsPerSheet),
|
|
JobID: strings.TrimSpace(options.JobID),
|
|
TotalRowsHint: normalizeExportTotalRowsHint(options.TotalRowsHint, options.TotalRowsKnown),
|
|
TotalRowsKnown: options.TotalRowsKnown,
|
|
}
|
|
}
|
|
|
|
func normalizeXLSXRowsPerSheet(value int) int {
|
|
if value <= 0 {
|
|
return defaultXLSXRowsPerSheet
|
|
}
|
|
if value > maxXLSXRowsPerSheet {
|
|
return maxXLSXRowsPerSheet
|
|
}
|
|
return value
|
|
}
|
|
|
|
func normalizeExportTotalRowsHint(value int64, known bool) int64 {
|
|
if !known {
|
|
return 0
|
|
}
|
|
if value < 0 {
|
|
return 0
|
|
}
|
|
return value
|
|
}
|