Files
s3/weed/query/engine/function_helpers.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

128 lines
4.0 KiB
Go

package engine
import (
"fmt"
"strconv"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
)
// Helper function to convert schema_pb.Value to float64
func (e *SQLEngine) valueToFloat64(value *schema_pb.Value) (float64, error) {
switch v := value.Kind.(type) {
case *schema_pb.Value_Int32Value:
return float64(v.Int32Value), nil
case *schema_pb.Value_Int64Value:
return float64(v.Int64Value), nil
case *schema_pb.Value_FloatValue:
return float64(v.FloatValue), nil
case *schema_pb.Value_DoubleValue:
return v.DoubleValue, nil
case *schema_pb.Value_StringValue:
// Try to parse string as number
if f, err := strconv.ParseFloat(v.StringValue, 64); err == nil {
return f, nil
}
return 0, fmt.Errorf("cannot convert string '%s' to number", v.StringValue)
case *schema_pb.Value_BoolValue:
if v.BoolValue {
return 1, nil
}
return 0, nil
default:
return 0, fmt.Errorf("cannot convert value type to number")
}
}
// Helper function to check if a value is an integer type
func (e *SQLEngine) isIntegerValue(value *schema_pb.Value) bool {
switch value.Kind.(type) {
case *schema_pb.Value_Int32Value, *schema_pb.Value_Int64Value:
return true
default:
return false
}
}
// Helper function to convert schema_pb.Value to string
func (e *SQLEngine) valueToString(value *schema_pb.Value) (string, error) {
switch v := value.Kind.(type) {
case *schema_pb.Value_StringValue:
return v.StringValue, nil
case *schema_pb.Value_Int32Value:
return strconv.FormatInt(int64(v.Int32Value), 10), nil
case *schema_pb.Value_Int64Value:
return strconv.FormatInt(v.Int64Value, 10), nil
case *schema_pb.Value_FloatValue:
return strconv.FormatFloat(float64(v.FloatValue), 'g', -1, 32), nil
case *schema_pb.Value_DoubleValue:
return strconv.FormatFloat(v.DoubleValue, 'g', -1, 64), nil
case *schema_pb.Value_BoolValue:
if v.BoolValue {
return "true", nil
}
return "false", nil
case *schema_pb.Value_BytesValue:
return string(v.BytesValue), nil
default:
return "", fmt.Errorf("cannot convert value type to string")
}
}
// Helper function to convert schema_pb.Value to int64
func (e *SQLEngine) valueToInt64(value *schema_pb.Value) (int64, error) {
switch v := value.Kind.(type) {
case *schema_pb.Value_Int32Value:
return int64(v.Int32Value), nil
case *schema_pb.Value_Int64Value:
return v.Int64Value, nil
case *schema_pb.Value_FloatValue:
return int64(v.FloatValue), nil
case *schema_pb.Value_DoubleValue:
return int64(v.DoubleValue), nil
case *schema_pb.Value_StringValue:
if i, err := strconv.ParseInt(v.StringValue, 10, 64); err == nil {
return i, nil
}
return 0, fmt.Errorf("cannot convert string '%s' to integer", v.StringValue)
default:
return 0, fmt.Errorf("cannot convert value type to integer")
}
}
// Helper function to convert schema_pb.Value to time.Time
func (e *SQLEngine) valueToTime(value *schema_pb.Value) (time.Time, error) {
switch v := value.Kind.(type) {
case *schema_pb.Value_TimestampValue:
if v.TimestampValue == nil {
return time.Time{}, fmt.Errorf("null timestamp value")
}
return time.UnixMicro(v.TimestampValue.TimestampMicros), nil
case *schema_pb.Value_StringValue:
// Try to parse various date/time string formats
dateFormats := []struct {
format string
tz *time.Location
}{
{"2006-01-02 15:04:05", time.Local}, // Local time assumed for non-timezone formats
{"2006-01-02T15:04:05Z", time.UTC}, // UTC format
{"2006-01-02T15:04:05", time.Local}, // Local time assumed
{"2006-01-02", time.Local}, // Local time assumed for date only
{"15:04:05", time.Local}, // Local time assumed for time only
}
for _, formatSpec := range dateFormats {
if t, err := time.ParseInLocation(formatSpec.format, v.StringValue, formatSpec.tz); err == nil {
return t, nil
}
}
return time.Time{}, fmt.Errorf("unable to parse date/time string: %s", v.StringValue)
case *schema_pb.Value_Int64Value:
// Assume Unix timestamp (seconds)
return time.Unix(v.Int64Value, 0), nil
default:
return time.Time{}, fmt.Errorf("cannot convert value type to date/time")
}
}