Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuldata committed Aug 13, 2024
1 parent 0b329bb commit 3fb386a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions expr/interval_compound_literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ func newIntervalPartsValInternal(datePartsOptions ...intervalDatePartsOptions) *
return intervalPartsVal
}

func intervalPartsValToProto(idp *intervalDateParts, ict *types.IntervalCompoundType) *proto.Expression_Literal_IntervalCompound {
func (m *intervalDateParts) ToProto(ict *types.IntervalCompoundType) *proto.Expression_Literal_IntervalCompound {
intrCompPB := &proto.Expression_Literal_IntervalCompound{}

if idp.years > 0 || idp.months > 0 {
if m.years > 0 || m.months > 0 {
yearToMonthProto := &proto.Expression_Literal_IntervalYearToMonth{
Years: idp.years,
Months: idp.months,
Years: m.years,
Months: m.months,
}
intrCompPB.IntervalYearToMonth = yearToMonthProto
}

dayToSecondProto := &proto.Expression_Literal_IntervalDayToSecond{
Days: idp.days,
Seconds: idp.seconds,
Days: m.days,
Seconds: m.seconds,
PrecisionMode: &proto.Expression_Literal_IntervalDayToSecond_Precision{Precision: ict.GetPrecisionProtoVal()},
Subseconds: idp.subSeconds,
Subseconds: m.subSeconds,
}
intrCompPB.IntervalDayToSecond = dayToSecondProto
return intrCompPB
Expand Down
12 changes: 6 additions & 6 deletions expr/interval_year_to_month.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ type intervalYearMonthVal struct {
months int32
}

// NewIntervalLiteralUptoMonth creates an interval literal which allows setting only year and month
// NewIntervalLiteralYearToMonth creates an interval literal which allows setting only year and month
// arguments: nullable property (n), years and months
func NewIntervalLiteralUptoMonth(n types.Nullability, years int32, months int32) Literal {
func NewIntervalLiteralYearToMonth(n types.Nullability, years int32, months int32) Literal {
intervalCompoundType := types.NewIntervalYearToMonthType().WithNullability(n)
intervalPartsVal := &intervalYearMonthVal{
years: years,
Expand All @@ -24,13 +24,13 @@ func NewIntervalLiteralUptoMonth(n types.Nullability, years int32, months int32)
}
}

func intervalYearToMonthValToProto(idp *intervalYearMonthVal) *proto.Expression_Literal_IntervalYearToMonth {
func (m *intervalYearMonthVal) ToProto() *proto.Expression_Literal_IntervalYearToMonth {
return &proto.Expression_Literal_IntervalYearToMonth{
Years: idp.years,
Months: idp.months,
Years: m.years,
Months: m.months,
}
}

func intervalYearToMonthFromProto(protoVal *proto.Expression_Literal_IntervalYearToMonth, nullability types.Nullability) Literal {
return NewIntervalLiteralUptoMonth(nullability, protoVal.Years, protoVal.Months)
return NewIntervalLiteralYearToMonth(nullability, protoVal.Years, protoVal.Months)
}
4 changes: 2 additions & 2 deletions expr/interval_year_to_month_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func TestIntervalYearToMonthToProto(t *testing.T) {
expectedExpressionLiteral *proto.Expression_Literal_IntervalYearToMonth_
}{
{"WithOnlyYear",
NewIntervalLiteralUptoMonth(nullability, oneYear, 0),
NewIntervalLiteralYearToMonth(nullability, oneYear, 0),
&proto.Expression_Literal_IntervalYearToMonth_{IntervalYearToMonth: &proto.Expression_Literal_IntervalYearToMonth{Years: oneYear}},
},
{"WithOnlyMonth",
NewIntervalLiteralUptoMonth(nullability, 0, oneMonth),
NewIntervalLiteralYearToMonth(nullability, 0, oneMonth),
&proto.Expression_Literal_IntervalYearToMonth_{IntervalYearToMonth: &proto.Expression_Literal_IntervalYearToMonth{Months: oneMonth}},
},
} {
Expand Down
4 changes: 2 additions & 2 deletions expr/literals.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,12 @@ func (t *ProtoLiteral) ToProtoLiteral() *proto.Expression_Literal {
case types.IntervalCompoundType:
v := t.Value.(*intervalDateParts)
lit.LiteralType = &proto.Expression_Literal_IntervalCompound_{
IntervalCompound: intervalPartsValToProto(v, &literalType),
IntervalCompound: v.ToProto(&literalType),
}
case types.IntervalYearToMonthType:
v := t.Value.(*intervalYearMonthVal)
lit.LiteralType = &proto.Expression_Literal_IntervalYearToMonth_{
IntervalYearToMonth: intervalYearToMonthValToProto(v),
IntervalYearToMonth: v.ToProto(),
}
}
return lit
Expand Down

0 comments on commit 3fb386a

Please sign in to comment.