**Problem:**
- CURRENT_TIMESTAMP test had timing race condition that could cause flaky failures
- CURRENT_DATE test could fail if run exactly at midnight boundary
- Tests were too strict about timing precision without accounting for system variations
**Root Cause:**
- Test captured before/after timestamps and expected function result to be exactly between them
- No tolerance for clock precision differences, NTP adjustments, or system timing variations
- Date boundary race condition around midnight transitions
**Solution:**
✅ **CURRENT_TIMESTAMP test**: Added 100ms tolerance buffer to account for:
- Clock precision differences between time.Now() calls
- System timing variations and NTP corrections
- Microsecond vs nanosecond precision differences
✅ **CURRENT_DATE test**: Enhanced to handle midnight boundary crossings:
- Captures date before and after function call
- Accepts either date value in case of midnight transition
- Prevents false failures during overnight test runs
**Testing:**
- Verified with repeated test runs (5x iterations) - all pass consistently
- Full test suite passes - no regressions introduced
- Tests are now robust against timing edge cases
**Impact:**
🚀 **Eliminated flaky test failures** while maintaining function correctness validation
🔧 **Production-ready testing** that works across different system environments
⚡ **CI/CD reliability** - tests won't fail due to timing variations
- Implement comprehensive DATE_TRUNC function supporting:
- Time precisions: microsecond, millisecond, second, minute, hour
- Date precisions: day, week, month, quarter, year, decade, century, millennium
- Support both singular and plural forms (e.g., 'minute' and 'minutes')
- Enhanced date/time parsing with proper timezone handling:
- Assume local timezone for non-timezone string formats
- Support UTC formats with explicit timezone indicators
- Consistent behavior between parsing and truncation
- Comprehensive test suite with 11 test cases covering:
- All supported precisions from microsecond to year
- Multiple input types (TimestampValue, string dates)
- Edge cases (null values, invalid precisions)
- Timezone consistency validation
All tests passing ✅
- Implement CURRENT_DATE returning YYYY-MM-DD format
- Add CURRENT_TIMESTAMP returning TimestampValue with microseconds
- Add CURRENT_TIME returning HH:MM:SS format
- Add NOW() as alias for CURRENT_TIMESTAMP
- Implement comprehensive EXTRACT function supporting:
- YEAR, MONTH, DAY, HOUR, MINUTE, SECOND
- QUARTER, WEEK, DOY (day of year), DOW (day of week)
- EPOCH (Unix timestamp)
- Support multiple input formats:
- TimestampValue (microseconds)
- String dates (multiple formats)
- Unix timestamps (int64 seconds)
- Comprehensive test suite with 15+ test cases covering:
- All date/time constants
- Extract from different value types
- Error handling for invalid inputs
- Timezone handling
All tests passing ✅
- Implement ROUND with optional precision parameter
- Add CEIL function for rounding up to nearest integer
- Add FLOOR function for rounding down to nearest integer
- Add ABS function for absolute values with type preservation
- Support all numeric types (int32, int64, float32, double)
- Comprehensive test suite with 20+ test cases covering:
- Positive/negative numbers
- Integer/float type preservation
- Precision handling for ROUND
- Null value error handling
- Edge cases (zero, large numbers)
All tests passing ✅
- Implement EvaluateArithmeticExpression with support for all basic operators
- Handle type conversions between int, float, string, and boolean
- Add proper error handling for division/modulo by zero
- Include 14 comprehensive test cases covering all edge cases
- Support mixed type arithmetic (int + float, string numbers, etc.)
All tests passing ✅
Added comprehensive foundation for SQL window functions with timestamp analytics:
Core Window Function Types:
- WindowSpec with PartitionBy and OrderBy support
- WindowFunction struct for ROW_NUMBER, RANK, LAG, LEAD
- OrderByClause for timestamp-based ordering
- Extended SelectStatement to support WindowFunctions field
Timestamp Analytics Functions:
✅ ApplyRowNumber() - ROW_NUMBER() OVER (ORDER BY timestamp)
✅ ExtractYear() - Extract year from TIMESTAMP logical type
✅ ExtractMonth() - Extract month from TIMESTAMP logical type
✅ ExtractDay() - Extract day from TIMESTAMP logical type
✅ FilterByYear() - Filter records by timestamp year
Foundation for Advanced Window Functions:
- LAG/LEAD for time-series access to previous/next values
- RANK/DENSE_RANK for temporal ranking
- FIRST_VALUE/LAST_VALUE for window boundaries
- PARTITION BY support for grouped analytics
This enables sophisticated time-series analytics like:
- SELECT *, ROW_NUMBER() OVER (ORDER BY timestamp) FROM user_events WHERE EXTRACT(YEAR FROM timestamp) = 2024
- Trend analysis over time windows
- Session analytics with LAG/LEAD functions
- Time-based ranking and percentiles
Ready for production time-series analytics with proper timestamp logical type support! 🚀
Enhanced MQ publishers to utilize the new logical types:
- Updated convertToRecordValue() to use TimestampValue instead of string RFC3339
- Added DateValue support for birth_date field (days since epoch)
- Added DecimalValue support for precise_amount field with configurable precision/scale
- Enhanced UserEvent struct with PreciseAmount and BirthDate fields
- Added convertToDecimal() helper using big.Rat for precise decimal conversion
- Updated test data generator to produce varied birth dates (1970-2005) and precise amounts
Publishers now generate structured data with proper logical types:
- ✅ TIMESTAMP: Microsecond precision UTC timestamps
- ✅ DATE: Birth dates as days since Unix epoch
- ✅ DECIMAL: Precise amounts with 18-digit precision, 4-decimal scale
Successfully tested with PostgreSQL integration - all topics created with logical type data.
Added support for Parquet logical types in SeaweedFS message queue schema:
- TIMESTAMP: UTC timestamp in microseconds since epoch with timezone flag
- DATE: Date as days since Unix epoch (1970-01-01)
- DECIMAL: Arbitrary precision decimal with configurable precision/scale
- TIME: Time of day in microseconds since midnight
These types enable advanced analytics features:
- Time-based filtering and window functions
- Date arithmetic and year/month/day extraction
- High-precision numeric calculations
- Proper time zone handling for global deployments
Regenerated protobuf Go code with new scalar types and value messages.
- Remove github.com/pganalyze/pg_query_go/v6 dependency to avoid CGO requirement
- Implement lightweight SQL parser for basic SELECT, SHOW, and DDL statements
- Fix operator precedence in WHERE clause parsing (handle AND/OR before comparisons)
- Support INTEGER, FLOAT, and STRING literals in WHERE conditions
- All SQL engine tests passing with new parser
- PostgreSQL integration tests can now build without CGO
The lightweight parser handles the essential SQL features needed for the
SeaweedFS query engine while maintaining compatibility and avoiding CGO
dependencies that caused Docker build issues.
The pg_query_go library requires CGO to be enabled as it wraps the libpg_query C library.
Added gcc and musl-dev dependencies to the Docker build for proper compilation.