MCPcopy Index your code
hub / github.com/cockscomb/cel2sql / callTimestampOperation

Method callTimestampOperation

cel2sql.go:191–251  ·  view source on GitHub ↗
(fun string, lhs *exprpb.Expr, rhs *exprpb.Expr)

Source from the content-addressed store, hash-verified

189}
190
191func (con *converter) callTimestampOperation(fun string, lhs *exprpb.Expr, rhs *exprpb.Expr) error {
192 lhsParen := isComplexOperatorWithRespectTo(fun, lhs)
193 rhsParen := isComplexOperatorWithRespectTo(fun, rhs)
194 lhsType := con.getType(lhs)
195 rhsType := con.getType(rhs)
196
197 var timestampType *exprpb.Type
198 var timestamp, duration *exprpb.Expr
199 var timestampParen, durationParen bool
200 switch {
201 case isTimestampRelatedType(lhsType):
202 timestampType = lhsType
203 timestamp, duration = lhs, rhs
204 timestampParen, durationParen = lhsParen, rhsParen
205 case isTimestampRelatedType(rhsType):
206 timestampType = rhsType
207 timestamp, duration = rhs, lhs
208 timestampParen, durationParen = rhsParen, lhsParen
209 default:
210 panic("lhs or rhs must be timestamp related type")
211 }
212
213 var sqlFun string
214 switch fun {
215 case operators.Add:
216 switch {
217 case isTimeType(timestampType):
218 sqlFun = "TIME_ADD"
219 case isDateType(timestampType):
220 sqlFun = "DATE_ADD"
221 case isDateTimeType(timestampType):
222 sqlFun = "DATETIME_ADD"
223 default:
224 sqlFun = "TIMESTAMP_ADD"
225 }
226 case operators.Subtract:
227 switch {
228 case isTimeType(timestampType):
229 sqlFun = "TIME_SUB"
230 case isDateType(timestampType):
231 sqlFun = "DATE_SUB"
232 case isDateTimeType(timestampType):
233 sqlFun = "DATETIME_SUB"
234 default:
235 sqlFun = "TIMESTAMP_SUB"
236 }
237 default:
238 return fmt.Errorf("unsupported operation (%s)", fun)
239 }
240 con.str.WriteString(sqlFun)
241 con.str.WriteString("(")
242 if err := con.visitMaybeNested(timestamp, timestampParen); err != nil {
243 return err
244 }
245 con.str.WriteString(", ")
246 if err := con.visitMaybeNested(duration, durationParen); err != nil {
247 return err
248 }

Callers 1

visitCallBinaryMethod · 0.95

Calls 7

getTypeMethod · 0.95
visitMaybeNestedMethod · 0.95
isTimestampRelatedTypeFunction · 0.85
isTimeTypeFunction · 0.85
isDateTypeFunction · 0.85
isDateTimeTypeFunction · 0.85

Tested by

no test coverage detected