Files
s3/weed/query/engine/sql_feature_diagnostic_test.go
zooqueen dd74d3e6d6 Replace AGPL MinIO fork with Apache-2.0 SeaweedFS fork; rebrand CLI weed->s3
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.

- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
  "Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
  SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
  (replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
  keep their upstream import paths with zero churn. Internal identifiers and
  import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
  help/usage/flag strings, shell autocomplete program name, and the product name
  in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
  (e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
  `cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
  updated to ignore the `s3` build output.
2026-06-18 23:41:25 -07:00

170 lines
5.5 KiB
Go

package engine
import (
"context"
"fmt"
"strings"
"testing"
)
// TestSQLFeatureDiagnostic provides comprehensive diagnosis of current SQL features
func TestSQLFeatureDiagnostic(t *testing.T) {
engine := NewTestSQLEngine()
t.Log("SEAWEEDFS SQL ENGINE FEATURE DIAGNOSTIC")
t.Log(strings.Repeat("=", 80))
// Test 1: LIMIT functionality
t.Log("\n1. TESTING LIMIT FUNCTIONALITY:")
for _, limit := range []int{0, 1, 3, 5, 10, 100} {
sql := fmt.Sprintf("SELECT id FROM user_events LIMIT %d", limit)
result, err := engine.ExecuteSQL(context.Background(), sql)
if err != nil {
t.Logf(" LIMIT %d: ERROR - %v", limit, err)
} else if result.Error != nil {
t.Logf(" LIMIT %d: RESULT ERROR - %v", limit, result.Error)
} else {
expected := limit
actual := len(result.Rows)
if limit > 10 {
expected = 10 // Test data has max 10 rows
}
if actual == expected {
t.Logf(" LIMIT %d: PASS - Got %d rows", limit, actual)
} else {
t.Logf(" LIMIT %d: PARTIAL - Expected %d, got %d rows", limit, expected, actual)
}
}
}
// Test 2: OFFSET functionality
t.Log("\n2. TESTING OFFSET FUNCTIONALITY:")
for _, offset := range []int{0, 1, 2, 5, 10, 100} {
sql := fmt.Sprintf("SELECT id FROM user_events LIMIT 3 OFFSET %d", offset)
result, err := engine.ExecuteSQL(context.Background(), sql)
if err != nil {
t.Logf(" OFFSET %d: ERROR - %v", offset, err)
} else if result.Error != nil {
t.Logf(" OFFSET %d: RESULT ERROR - %v", offset, result.Error)
} else {
actual := len(result.Rows)
if offset >= 10 {
t.Logf(" OFFSET %d: PASS - Beyond data range, got %d rows", offset, actual)
} else {
t.Logf(" OFFSET %d: PASS - Got %d rows", offset, actual)
}
}
}
// Test 3: WHERE clause functionality
t.Log("\n3. TESTING WHERE CLAUSE FUNCTIONALITY:")
whereTests := []struct {
sql string
desc string
}{
{"SELECT * FROM user_events WHERE id = 82460", "Specific ID match"},
{"SELECT * FROM user_events WHERE id > 100000", "Greater than comparison"},
{"SELECT * FROM user_events WHERE status = 'active'", "String equality"},
{"SELECT * FROM user_events WHERE id = -999999", "Non-existent ID"},
{"SELECT * FROM user_events WHERE 1 = 2", "Always false condition"},
}
allRowsCount := 10 // Expected total rows in test data
for _, test := range whereTests {
result, err := engine.ExecuteSQL(context.Background(), test.sql)
if err != nil {
t.Logf(" %s: ERROR - %v", test.desc, err)
} else if result.Error != nil {
t.Logf(" %s: RESULT ERROR - %v", test.desc, result.Error)
} else {
actual := len(result.Rows)
if actual == allRowsCount {
t.Logf(" %s: FAIL - WHERE clause ignored, got all %d rows", test.desc, actual)
} else {
t.Logf(" %s: PASS - WHERE clause working, got %d rows", test.desc, actual)
}
}
}
// Test 4: Combined functionality
t.Log("\n4. TESTING COMBINED LIMIT + OFFSET + WHERE:")
combinedSql := "SELECT id FROM user_events WHERE id > 0 LIMIT 2 OFFSET 1"
result, err := engine.ExecuteSQL(context.Background(), combinedSql)
if err != nil {
t.Logf(" Combined query: ERROR - %v", err)
} else if result.Error != nil {
t.Logf(" Combined query: RESULT ERROR - %v", result.Error)
} else {
actual := len(result.Rows)
t.Logf(" Combined query: Got %d rows (LIMIT=2 part works, WHERE filtering unknown)", actual)
}
// Summary
t.Log("\n" + strings.Repeat("=", 80))
t.Log("FEATURE SUMMARY:")
t.Log(" LIMIT: FULLY WORKING - Correctly limits result rows")
t.Log(" OFFSET: FULLY WORKING - Correctly skips rows")
t.Log(" WHERE: FULLY WORKING - All comparison operators working")
t.Log(" SELECT: WORKING - Supports *, columns, functions, arithmetic")
t.Log(" Functions: WORKING - String and datetime functions work")
t.Log(" Arithmetic: WORKING - +, -, *, / operations work")
t.Log(strings.Repeat("=", 80))
}
// TestSQLWhereClauseIssue creates a focused test to demonstrate WHERE clause issue
func TestSQLWhereClauseIssue(t *testing.T) {
engine := NewTestSQLEngine()
t.Log("DEMONSTRATING WHERE CLAUSE ISSUE:")
// Get all rows first to establish baseline
allResult, _ := engine.ExecuteSQL(context.Background(), "SELECT id FROM user_events")
allCount := len(allResult.Rows)
t.Logf("Total rows in test data: %d", allCount)
if allCount > 0 {
firstId := allResult.Rows[0][0].ToString()
t.Logf("First row ID: %s", firstId)
// Try to filter to just that specific ID
specificSql := fmt.Sprintf("SELECT id FROM user_events WHERE id = %s", firstId)
specificResult, err := engine.ExecuteSQL(context.Background(), specificSql)
if err != nil {
t.Errorf("WHERE query failed: %v", err)
} else {
actualCount := len(specificResult.Rows)
t.Logf("WHERE id = %s returned %d rows", firstId, actualCount)
if actualCount == allCount {
t.Log("CONFIRMED: WHERE clause is completely ignored")
t.Log(" - Query parsed successfully")
t.Log(" - No errors returned")
t.Log(" - But filtering logic not implemented in execution")
} else if actualCount == 1 {
t.Log("WHERE clause working correctly")
} else {
t.Logf("❓ Unexpected result: got %d rows instead of 1 or %d", actualCount, allCount)
}
}
}
// Test impossible condition
impossibleResult, _ := engine.ExecuteSQL(context.Background(), "SELECT * FROM user_events WHERE 1 = 0")
impossibleCount := len(impossibleResult.Rows)
t.Logf("WHERE 1 = 0 returned %d rows", impossibleCount)
if impossibleCount == allCount {
t.Log("CONFIRMED: Even impossible WHERE conditions are ignored")
} else if impossibleCount == 0 {
t.Log("Impossible WHERE condition correctly returns no rows")
}
}