Skip to content

Commit ebddf5b

Browse files
committed
fix: test failures
1 parent 995c015 commit ebddf5b

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

db_proto/sql/risingwave/database_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/streamingfast/substreams-sink-sql/internal/timefmt"
78
"github.com/stretchr/testify/assert"
89
)
910

@@ -30,6 +31,8 @@ func TestTableName(t *testing.T) {
3031

3132
// Test value conversion for RisingWave-specific handling
3233
func TestValueConversion(t *testing.T) {
34+
timeValue := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
35+
3336
tests := []struct {
3437
name string
3538
input interface{}
@@ -41,7 +44,7 @@ func TestValueConversion(t *testing.T) {
4144
{"uint64", uint64(456), "456"},
4245
{"bool true", true, "true"},
4346
{"bool false", false, "false"},
44-
{"time", time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC), "'2023-01-01 00:00:00.000000+00:00'"},
47+
{"time", timeValue, "'" + timefmt.FormatRisingWave(timeValue) + "'"},
4548
{"bytes", []byte{0xDE, 0xAD}, "'\\xDEAD'"},
4649
}
4750

db_proto/sql/risingwave/types_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestValueToString(t *testing.T) {
4646
{"empty bytes", []uint8{}, "'\\x'"},
4747

4848
// Time values
49-
{"time", time.Date(2023, 1, 15, 10, 30, 0, 0, time.UTC), "'2023-01-15 10:30:00.000000+00:00'"},
49+
{"time", time.Date(2023, 1, 15, 10, 30, 0, 0, time.UTC), "'" + timefmt.FormatRisingWave(time.Date(2023, 1, 15, 10, 30, 0, 0, time.UTC)) + "'"},
5050
}
5151

5252
for _, tt := range tests {
@@ -62,7 +62,7 @@ func TestValueToStringTimestamp(t *testing.T) {
6262
testTime := time.Date(2023, 1, 15, 10, 30, 0, 0, time.UTC)
6363
pbTime := timestamppb.New(testTime)
6464
result := ValueToString(pbTime)
65-
assert.Equal(t, "'2023-01-15 10:30:00.000000+00:00'", result)
65+
assert.Equal(t, "'"+timefmt.FormatRisingWave(testTime)+"'", result)
6666

6767
// Non-UTC timestamp should be converted to UTC before formatting
6868
nonUTCTime := time.Date(2023, 1, 15, 10, 30, 0, 987000000, time.FixedZone("UTC-5", -5*3600))

internal/timefmt/risingwave.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package timefmt
22

3-
import "time"
3+
import (
4+
"fmt"
5+
"time"
6+
)
47

5-
// RisingWaveTimestampLayout is the canonical layout accepted by RisingWave for timestamptz values.
6-
// RisingWave rejects RFC3339 timestamps with the 'T' separator, so we normalize to the layout
7-
// "YYYY-MM-DD HH:MM:SS[.up to 6 digits]±HH:MM".
8-
const RisingWaveTimestampLayout = "2006-01-02 15:04:05.999999Z07:00"
9-
10-
// FormatRisingWave returns the UTC representation of t formatted according to
11-
// RisingWaveTimestampLayout. RisingWave expects timestamps with a space separator
12-
// between the date and the time component and supports microsecond precision.
8+
// FormatRisingWave renders a UTC timestamp in the layout accepted by RisingWave
9+
// ("YYYY-MM-DD HH:MM:SS[.dddddd]+HH:MM"), always returning a space separator and
10+
// microsecond precision when sub-second data is present.
1311
func FormatRisingWave(t time.Time) string {
14-
return t.UTC().Format(RisingWaveTimestampLayout)
12+
utc := t.UTC()
13+
base := utc.Format("2006-01-02 15:04:05")
14+
if ns := utc.Nanosecond(); ns != 0 {
15+
base = fmt.Sprintf("%s.%06d", base, ns/1000)
16+
}
17+
return base + "+00:00"
1518
}

0 commit comments

Comments
 (0)