private List<RexNode> rewriteToDateChildren(List<RexNode> childRexNodeLst) { List<RexNode> newChildRexNodeLst = new ArrayList<RexNode>(); assert childRexNodeLst.size() == 1; RexNode child = childRexNodeLst.get(0); if (SqlTypeUtil.isDatetime(child.getType()) || SqlTypeUtil.isInterval(child.getType())) { newChildRexNodeLst.add(child); } else { newChildRexNodeLst.add(makeCast(SqlTypeName.TIMESTAMP, child)); } return newChildRexNodeLst; }
if (SqlTypeUtil.isDatetime(child.getType()) || SqlTypeUtil.isInterval(child.getType())) { newChildRexNodeLst.add(child); } else {
@Override public RexNode makeCast( RelDataType type, RexNode exp, boolean matchNullability) { // Special case: bypassing Calcite for interval types if (!(exp instanceof RexLiteral) && SqlTypeUtil.isExactNumeric(type) && SqlTypeUtil.isInterval(exp.getType())) { return makeAbstractCast(type, exp); } RexNode castRexNode = super.makeCast(type, exp, matchNullability); // If we have a CAST(A, TYPE) and A is already of the same TYPE (including nullability), // then return just A. if (castRexNode instanceof RexCall && castRexNode.getKind() == SqlKind.CAST && castRexNode.getType().equals(((RexCall) castRexNode).getOperands().get(0).getType())) { return ((RexCall) castRexNode).getOperands().get(0); } return castRexNode; } }
/** * Retrieves an interval or decimal node's integer representation * * @param node the interval or decimal value as an opaque type * @return an integer representation of the decimal value */ public RexNode decodeIntervalOrDecimal(RexNode node) { assert SqlTypeUtil.isDecimal(node.getType()) || SqlTypeUtil.isInterval(node.getType()); RelDataType bigintType = typeFactory.createSqlType(SqlTypeName.BIGINT); return makeReinterpretCast( matchNullability(bigintType, node), node, makeLiteral(false)); }
/** * Retrieves an interval or decimal node's integer representation * * @param node the interval or decimal value as an opaque type * @return an integer representation of the decimal value */ public RexNode decodeIntervalOrDecimal(RexNode node) { assert SqlTypeUtil.isDecimal(node.getType()) || SqlTypeUtil.isInterval(node.getType()); RelDataType bigintType = typeFactory.createSqlType(SqlTypeName.BIGINT); return makeReinterpretCast( matchNullability(bigintType, node), node, makeLiteral(false)); }
public boolean checkSingleOperandType(SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) { assert 0 == iFormalOperand; RelDataType type = callBinding.getValidator().deriveType(callBinding.getScope(), node); boolean valid = false; if (type.isStruct() && type.getFieldList().size() == 2) { final RelDataType t0 = type.getFieldList().get(0).getType(); final RelDataType t1 = type.getFieldList().get(1).getType(); if (SqlTypeUtil.isDatetime(t0)) { if (SqlTypeUtil.isDatetime(t1)) { // t0 must be comparable with t1; (DATE, TIMESTAMP) is not valid if (SqlTypeUtil.sameNamedType(t0, t1)) { valid = true; } } else if (SqlTypeUtil.isInterval(t1)) { valid = true; } } } if (!valid && throwOnFailure) { throw callBinding.newValidationSignatureError(); } return valid; }
public boolean checkSingleOperandType(SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) { assert 0 == iFormalOperand; RelDataType type = callBinding.getValidator().deriveType(callBinding.getScope(), node); boolean valid = false; if (type.isStruct() && type.getFieldList().size() == 2) { final RelDataType t0 = type.getFieldList().get(0).getType(); final RelDataType t1 = type.getFieldList().get(1).getType(); if (SqlTypeUtil.isDatetime(t0)) { if (SqlTypeUtil.isDatetime(t1)) { // t0 must be comparable with t1; (DATE, TIMESTAMP) is not valid if (SqlTypeUtil.sameNamedType(t0, t1)) { valid = true; } } else if (SqlTypeUtil.isInterval(t1)) { valid = true; } } } if (!valid && throwOnFailure) { throw callBinding.newValidationSignatureError(); } return valid; }
private Pair<RexNode, RexNode> convertOverlapsOperand(SqlRexContext cx, SqlParserPos pos, SqlNode operand) { final SqlNode a0; final SqlNode a1; switch (operand.getKind()) { case ROW: a0 = ((SqlCall) operand).operand(0); final SqlNode a10 = ((SqlCall) operand).operand(1); final RelDataType t1 = cx.getValidator().getValidatedNodeType(a10); if (SqlTypeUtil.isInterval(t1)) { // make t1 = t0 + t1 when t1 is an interval. a1 = plus(pos, a0, a10); } else { a1 = a10; } break; default: a0 = operand; a1 = operand; } final RexNode r0 = cx.convertExpression(a0); final RexNode r1 = cx.convertExpression(a1); return Pair.of(r0, r1); }
private Pair<RexNode, RexNode> convertOverlapsOperand(SqlRexContext cx, SqlParserPos pos, SqlNode operand) { final SqlNode a0; final SqlNode a1; switch (operand.getKind()) { case ROW: a0 = ((SqlCall) operand).operand(0); final SqlNode a10 = ((SqlCall) operand).operand(1); final RelDataType t1 = cx.getValidator().getValidatedNodeType(a10); if (SqlTypeUtil.isInterval(t1)) { // make t1 = t0 + t1 when t1 is an interval. a1 = plus(pos, a0, a10); } else { a1 = a10; } break; default: a0 = operand; a1 = operand; } final RexNode r0 = cx.convertExpression(a0); final RexNode r1 = cx.convertExpression(a1); return Pair.of(r0, r1); }
if ((isInterval(fromType) && isExactNumeric(toType)) || (isInterval(toType) && isExactNumeric(fromType))) { IntervalSqlType intervalType = (IntervalSqlType) (isInterval(fromType) ? fromType : toType); if (!intervalType.getIntervalQualifier().isSingleDatetimeField()) {
if ((isInterval(fromType) && isExactNumeric(toType)) || (isInterval(toType) && isExactNumeric(fromType))) { IntervalSqlType intervalType = (IntervalSqlType) (isInterval(fromType) ? fromType : toType); if (!intervalType.getIntervalQualifier().isSingleDatetimeField()) {
if ((isInterval(fromType) && isExactNumeric(toType)) || (isInterval(toType) && isExactNumeric(fromType))) { IntervalSqlType intervalType = (IntervalSqlType) (isInterval(fromType) ? fromType : toType); if (!intervalType.getIntervalQualifier().isSingleDatetimeField()) {
return null; } else if (SqlTypeUtil.isInterval(type)) { if (SqlTypeUtil.isInterval(type1) || SqlTypeUtil.isIntType(type1)) { resultType = type;
return null; } else if (SqlTypeUtil.isInterval(type)) { if (SqlTypeUtil.isInterval(type1) || SqlTypeUtil.isIntType(type1)) { resultType = type;
&& SqlTypeUtil.isInterval(exp.getType())) { return makeCastIntervalToExact(type, exp); } else if (sqlType == SqlTypeName.BOOLEAN
&& SqlTypeUtil.isInterval(exp.getType())) { return makeCastIntervalToExact(type, exp); } else if (sqlType == SqlTypeName.BOOLEAN