Skip to content

Commit

Permalink
plus and minus infinity keyword tests implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkan-ag5 committed Feb 25, 2024
1 parent 1f8ca31 commit 121d39b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
40 changes: 2 additions & 38 deletions internal/jet/literal_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ var (
// STAR is jet equivalent of SQL *
STAR = newStarLiteral()
// PLUS_INFINITY is jet equivalent for sql infinity
PLUS_INFINITY = newPlusInfinityLiteral()
PLUS_INFINITY = String("infinity")
// MINUS_INFINITY is jet equivalent for sql -infinity
MINUS_INFINITY = newMinusInfinityLiteral()
MINUS_INFINITY = String("-infinity")
)

type nullLiteral struct {
Expand Down Expand Up @@ -374,42 +374,6 @@ func (n *starLiteral) serialize(statement StatementType, out *SQLBuilder, option

//---------------------------------------------------//

type plusInfinityLiteral struct {
ExpressionInterfaceImpl
}

func newPlusInfinityLiteral() Expression {
plusInfinityExpression := &plusInfinityLiteral{}

plusInfinityExpression.ExpressionInterfaceImpl.Parent = plusInfinityExpression

return plusInfinityExpression
}

func (n *plusInfinityLiteral) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
out.WriteString("infinity")
}

//---------------------------------------------------//

type minusInfinityLiteral struct {
ExpressionInterfaceImpl
}

func newMinusInfinityLiteral() Expression {
minusInfinityExpression := &minusInfinityLiteral{}

minusInfinityExpression.ExpressionInterfaceImpl.Parent = minusInfinityExpression

return minusInfinityExpression
}

func (n *minusInfinityLiteral) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
out.WriteString("-infinity")
}

//---------------------------------------------------//

type wrap struct {
ExpressionInterfaceImpl
expressions []Expression
Expand Down
41 changes: 41 additions & 0 deletions tests/postgres/range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,44 @@ WHERE sample_ranges.date_range @> '2023-12-12'::date;
t.Errorf("expected: 2023-09-25 got: %s", date.Format("2006-01-02"))
}
}

func TestRangeTable_InsertInfinite(t *testing.T) {
skipForCockroachDB(t)

insertQuery := SampleRanges.INSERT(SampleRanges.AllColumns).
VALUES(
DATE_RANGE(
Date(2010, 01, 01),
DateExp(PLUS_INFINITY),
String("[)"),
),
DEFAULT,
TIMESTAMPTZ_RANGE(
TimestampzExp(MINUS_INFINITY),
TimestampzT(time.Date(2014, 01, 01, 15, 0, 0, 0, time.UTC)),
String("[)"),
),
INT4_RANGE(Int(64), Int(128), String("[]")),
INT8_RANGE(Int(1024), Int(2048), String("[]")),
DEFAULT,
).
RETURNING(SampleRanges.AllColumns)

expectedQuery := `
INSERT INTO test_sample.sample_ranges (date_range, timestamp_range, timestampz_range, int4_range, int8_range, num_range)
VALUES (daterange('2010-01-01'::date, 'infinity', '[)'::text), DEFAULT, tstzrange('-infinity', '2014-01-01 15:00:00Z'::timestamp with time zone, '[)'::text), int4range(64, 128, '[]'::text), int8range(1024, 2048, '[]'::text), DEFAULT)
RETURNING sample_ranges.date_range AS "sample_ranges.date_range",
sample_ranges.timestamp_range AS "sample_ranges.timestamp_range",
sample_ranges.timestampz_range AS "sample_ranges.timestampz_range",
sample_ranges.int4_range AS "sample_ranges.int4_range",
sample_ranges.int8_range AS "sample_ranges.int8_range",
sample_ranges.num_range AS "sample_ranges.num_range";
`

testutils.AssertDebugStatementSql(t, insertQuery, expectedQuery,
"2010-01-01", "infinity", "[)",
"-infinity", time.Date(2014, 01, 01, 15, 0, 0, 0, time.UTC), "[)",
int64(64), int64(128), "[]",
int64(1024), int64(2048), "[]",
)
}

0 comments on commit 121d39b

Please sign in to comment.