OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.sql2rel.StandardConvertletTable.TimestampAddConvertlet Class Reference
+ Inheritance diagram for org.apache.calcite.sql2rel.StandardConvertletTable.TimestampAddConvertlet:
+ Collaboration diagram for org.apache.calcite.sql2rel.StandardConvertletTable.TimestampAddConvertlet:

Public Member Functions

RexNode convertCall (SqlRexContext cx, SqlCall call)
 

Detailed Description

Convertlet that handles the

TIMESTAMPADD

function.

Definition at line 1394 of file StandardConvertletTable.java.

Member Function Documentation

RexNode org.apache.calcite.sql2rel.StandardConvertletTable.TimestampAddConvertlet.convertCall ( SqlRexContext  cx,
SqlCall  call 
)
inline

Definition at line 1395 of file StandardConvertletTable.java.

1395  {
1396  // TIMESTAMPADD(unit, count, timestamp)
1397  // => timestamp + count * INTERVAL '1' UNIT
1398  final RexBuilder rexBuilder = cx.getRexBuilder();
1399  final SqlLiteral unitLiteral = call.operand(0);
1400  final TimeUnit unit = unitLiteral.symbolValue(TimeUnit.class);
1401  RexNode interval2Add;
1402  SqlIntervalQualifier qualifier =
1403  new SqlIntervalQualifier(unit, null, unitLiteral.getParserPosition());
1404  RexNode op1 = cx.convertExpression(call.operand(1));
1405  switch (unit) {
1406  case MICROSECOND:
1407  case NANOSECOND:
1408  interval2Add = divide(rexBuilder,
1409  multiply(rexBuilder,
1410  rexBuilder.makeIntervalLiteral(BigDecimal.ONE, qualifier),
1411  op1),
1412  BigDecimal.ONE.divide(unit.multiplier, RoundingMode.UNNECESSARY));
1413  break;
1414  default:
1415  interval2Add = multiply(rexBuilder,
1416  rexBuilder.makeIntervalLiteral(unit.multiplier, qualifier),
1417  op1);
1418  }
1419 
1420  return rexBuilder.makeCall(SqlStdOperatorTable.DATETIME_PLUS,
1421  cx.convertExpression(call.operand(2)),
1422  interval2Add);
1423  }
static RexNode multiply(RexBuilder rexBuilder, RexNode a0, RexNode a1)
static RexNode divide(RexBuilder rexBuilder, RexNode res, BigDecimal val)

The documentation for this class was generated from the following file: