use of org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class HazelcastRexBuilder method makeLiteral.
@Override
public RexNode makeLiteral(Object value, RelDataType type, boolean allowCast) {
if (type.getSqlTypeName() == ANY && value instanceof Number) {
Converter converter = Converters.getConverter(value.getClass());
if (converter != null) {
QueryDataTypeFamily typeFamily = converter.getTypeFamily();
if (typeFamily.isNumericInteger()) {
int bitWidth = HazelcastIntegerType.bitWidthOf(((Number) value).longValue());
type = HazelcastIntegerType.create(bitWidth, false);
} else {
SqlTypeName typeName = HazelcastTypeUtils.toCalciteType(typeFamily);
type = HazelcastTypeFactory.INSTANCE.createSqlType(typeName);
}
}
}
return super.makeLiteral(value, type, allowCast);
}
use of org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class WindowOperandMetadata method checkOperandTypes.
private boolean checkOperandTypes(HazelcastCallBinding binding, boolean throwOnFailure, int columnIndex) {
SqlNode lag = binding.operand(columnIndex);
HazelcastSqlValidator validator = binding.getValidator();
SqlTypeName orderingColumnType = getOrderingColumnType(binding, 1).getSqlTypeName();
boolean result;
SqlTypeName lagType = ((SqlValidator) validator).getValidatedNodeType(lag).getSqlTypeName();
if (SqlTypeName.INT_TYPES.contains(orderingColumnType)) {
result = SqlTypeName.INT_TYPES.contains(lagType);
} else if (SqlTypeName.DATETIME_TYPES.contains(orderingColumnType)) {
result = lagType.getFamily() == SqlTypeFamily.INTERVAL_DAY_TIME;
} else {
result = false;
}
if (!result && throwOnFailure) {
QueryDataTypeFamily hzOrderingColumnType = toHazelcastTypeFromSqlTypeName(orderingColumnType).getTypeFamily();
QueryDataTypeFamily hzLagType = toHazelcastTypeFromSqlTypeName(lagType).getTypeFamily();
throw validator.newValidationError(binding.getCall(), RESOURCES.windowFunctionTypeMismatch(hzOrderingColumnType.toString(), hzLagType.toString()));
}
return result;
}
use of org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class RexToExpression method convertLiteral.
/**
* Converts the given REX literal to runtime {@link ConstantExpression
* constant expression}.
*
* @param literal the literal to convert.
* @return the resulting constant expression.
*/
@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:ReturnCount" })
public static Expression<?> convertLiteral(RexLiteral literal) {
final RelDataType type = literal.getType();
final SqlTypeName typeName = literal.getTypeName();
if (literal.getValue() == null) {
return ConstantExpression.create(null, HazelcastTypeUtils.toHazelcastType(type));
}
if (literal.getTypeName() == SqlTypeName.SARG) {
return convertSargLiteral(literal, type);
}
switch(typeName) {
case BOOLEAN:
return convertBooleanLiteral(literal, type);
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
case DECIMAL:
case REAL:
case FLOAT:
case DOUBLE:
return convertNumericLiteral(literal, type);
case CHAR:
case VARCHAR:
return convertStringLiteral(literal, type);
case NULL:
return ConstantExpression.create(null, QueryDataType.NULL);
case SYMBOL:
return SymbolExpression.create(literal.getValue());
case DATE:
return convertDateLiteral(literal);
case TIME:
return convertTimeLiteral(literal);
case TIMESTAMP:
return convertTimestamp(literal);
case INTERVAL_YEAR_MONTH:
return convertIntervalYearMonth(literal);
case INTERVAL_DAY_SECOND:
return convertIntervalDaySecond(literal);
default:
throw QueryException.error("Unsupported literal: " + literal);
}
}
use of org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class LiteralUtils method literal.
public static Literal literal(SqlNode node) {
if (node.getKind() != SqlKind.LITERAL) {
// Not a literal
return null;
}
SqlLiteral literal = (SqlLiteral) node;
SqlTypeName typeName = literal.getTypeName();
Object value = CHAR_TYPES.contains(typeName) ? literal.toValue() : literal.getValue();
return literal0(typeName, value);
}
use of org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class HazelcastTrimFunction method getOperandsForSignatureError.
@Override
public Collection<SqlNode> getOperandsForSignatureError(SqlCall call) {
SqlNode fromOperand = call.operand(1);
SqlNode targetOperand = call.operand(2);
SqlTypeName literalType = LiteralUtils.literalTypeName(fromOperand);
if (literalType == SqlTypeName.VARCHAR && " ".equals(((SqlLiteral) fromOperand).getValueAs(String.class))) {
// Default value for the FROM operand, report only target operand.
return Collections.singletonList(targetOperand);
}
// Non-default FROM, report both target and FROM operands.
return Arrays.asList(fromOperand, targetOperand);
}
Aggregations