mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
query: take MIN and MAX of _ts from the files' recorded time range
MIN and MAX of _ts without column statistics were computed from file names, which are only the start second of a file's first source log: MIN rounded down to that second and MAX was the start of the latest file rather than its last row. Each file's stats already carry ts_min and ts_max as MinTimestampNs and MaxTimestampNs, so those are used when set, and names only for files that record no range. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
54a6c0dce1
commit
be7b803379
2 files changed
+41
-6
No files matched your search
@@ -84,12 +84,14 @@ func (e *SQLEngine) getSystemColumnGlobalMin(columnName string, allFileStats map
|
||||
switch lowerName {
|
||||
case SW_COLUMN_NAME_TIMESTAMP:
|
||||
// For timestamps, find the earliest timestamp across all files
|
||||
// This should match what's in the Extended[mq.ExtendedAttrTimestampMin] metadata
|
||||
var minTimestamp *int64
|
||||
for _, fileStats := range allFileStats {
|
||||
for _, fileStat := range fileStats {
|
||||
// Extract timestamp from filename (format: YYYY-MM-DD-HH-MM-SS.parquet)
|
||||
timestamp := e.extractTimestampFromFilename(fileStat.FileName)
|
||||
// a name is only the start second of the file's first source log
|
||||
timestamp := fileStat.MinTimestampNs
|
||||
if timestamp == 0 {
|
||||
timestamp = e.extractTimestampFromFilename(fileStat.FileName)
|
||||
}
|
||||
if timestamp != 0 {
|
||||
if minTimestamp == nil || timestamp < *minTimestamp {
|
||||
minTimestamp = ×tamp
|
||||
@@ -121,12 +123,13 @@ func (e *SQLEngine) getSystemColumnGlobalMax(columnName string, allFileStats map
|
||||
switch lowerName {
|
||||
case SW_COLUMN_NAME_TIMESTAMP:
|
||||
// For timestamps, find the latest timestamp across all files
|
||||
// This should match what's in the Extended[mq.ExtendedAttrTimestampMax] metadata
|
||||
var maxTimestamp *int64
|
||||
for _, fileStats := range allFileStats {
|
||||
for _, fileStat := range fileStats {
|
||||
// Extract timestamp from filename (format: YYYY-MM-DD-HH-MM-SS.parquet)
|
||||
timestamp := e.extractTimestampFromFilename(fileStat.FileName)
|
||||
timestamp := fileStat.MaxTimestampNs
|
||||
if timestamp == 0 {
|
||||
timestamp = e.extractTimestampFromFilename(fileStat.FileName)
|
||||
}
|
||||
if timestamp != 0 {
|
||||
if maxTimestamp == nil || timestamp > *maxTimestamp {
|
||||
maxTimestamp = ×tamp
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
||||
)
|
||||
|
||||
// A file's name is the start second of its first source log; MIN and MAX of _ts
|
||||
// come from the timestamp range the file records, and from names only without one.
|
||||
func TestSystemColumnTimestampRangePrefersFileStats(t *testing.T) {
|
||||
base := time.Date(2026, 11, 30, 10, 0, 0, 0, time.UTC)
|
||||
stats := map[string][]*ParquetFileStats{
|
||||
"p0": {
|
||||
{FileName: topic.LogFileName(base, 0) + ".parquet", MinTimestampNs: base.Add(500 * time.Millisecond).UnixNano(), MaxTimestampNs: base.Add(9 * time.Second).UnixNano()},
|
||||
{FileName: topic.LogFileName(base.Add(5*time.Second), 4) + ".parquet"},
|
||||
},
|
||||
}
|
||||
e := &SQLEngine{}
|
||||
if got, want := e.getSystemColumnGlobalMin(SW_COLUMN_NAME_TIMESTAMP, stats), base.Add(500*time.Millisecond).UnixNano(); got != want {
|
||||
t.Errorf("min %v, want %v", got, want)
|
||||
}
|
||||
if got, want := e.getSystemColumnGlobalMax(SW_COLUMN_NAME_TIMESTAMP, stats), base.Add(9*time.Second).UnixNano(); got != want {
|
||||
t.Errorf("max %v, want %v", got, want)
|
||||
}
|
||||
|
||||
stats["p0"] = stats["p0"][1:]
|
||||
if got, want := e.getSystemColumnGlobalMax(SW_COLUMN_NAME_TIMESTAMP, stats), base.Add(5*time.Second).UnixNano(); got != want {
|
||||
t.Errorf("max without stats %v, want the name's %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user