use of org.apache.beam.vendor.calcite.v1_28_0.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.beam.vendor.calcite.v1_28_0.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.beam.vendor.calcite.v1_28_0.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);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class HazelcastOperandTypeInference method inferOperandTypes.
@Override
public void inferOperandTypes(SqlCallBinding callBinding, RelDataType returnType, RelDataType[] operandTypes) {
SqlCall call = callBinding.getCall();
if (ValidationUtil.hasAssignment(call)) {
RelDataTypeFactory typeFactory = callBinding.getTypeFactory();
RelDataType[] parameterTypes = new RelDataType[parametersByName.size()];
for (int i = 0; i < call.operandCount(); i++) {
SqlCall assignment = call.operand(i);
SqlIdentifier id = assignment.operand(1);
String name = id.getSimple();
HazelcastTableFunctionParameter parameter = parametersByName.get(name);
if (parameter != null) {
SqlTypeName parameterType = parameter.type();
parameterTypes[parameter.ordinal()] = toType(parameterType, typeFactory);
} else {
throw SqlUtil.newContextException(id.getParserPosition(), RESOURCE.unknownArgumentName(name));
}
}
// noinspection ResultOfMethodCallIgnored
Arrays.stream(parameterTypes).filter(Objects::nonNull).toArray(ignored -> operandTypes);
} else {
positionalOperandTypeInference.inferOperandTypes(callBinding, returnType, operandTypes);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project hazelcast by hazelcast.
the class HazelcastTypeFactory method leastRestrictive.
@Override
public RelDataType leastRestrictive(List<RelDataType> types) {
// special-case for JSON - see https://github.com/hazelcast/hazelcast/issues/20303
// SqlTypeName for JSON is OTHER, there's missing handling for OTHER in SqlTypeAssignmentRule,
// and we don't know how to add it there. And even if we did, OTHER can represent both JSON and
// a JAVA object, and these aren't assignable.
boolean containsNullable = false;
boolean allJson = true;
boolean allJsonOrVarchar = true;
for (RelDataType type : types) {
if (!(type instanceof HazelcastJsonType)) {
allJson = false;
}
if (!(type instanceof HazelcastJsonType) && type.getSqlTypeName() != VARCHAR) {
allJsonOrVarchar = false;
}
if (type.isNullable()) {
containsNullable = true;
}
}
if (allJson) {
return containsNullable ? HazelcastJsonType.TYPE_NULLABLE : HazelcastJsonType.TYPE;
}
if (allJsonOrVarchar) {
return createSqlType(VARCHAR, containsNullable);
}
// Calcite returns BIGINT for all integer types and DOUBLE for all inexact fractional types.
// This code allows us to use more narrow types in these cases.
RelDataType selected = super.leastRestrictive(types);
if (selected == null) {
return null;
}
SqlTypeName selectedTypeName = selected.getSqlTypeName();
if (HazelcastTypeUtils.isNumericIntegerType(selectedTypeName)) {
return leastRestrictive(selected, types);
}
if (selectedTypeName == DOUBLE) {
boolean seenDouble = false;
boolean seenReal = false;
for (RelDataType type : types) {
if (type.getSqlTypeName() == DOUBLE) {
seenDouble = true;
break;
}
if (type.getSqlTypeName() == REAL) {
seenReal = true;
}
}
if (!seenDouble && seenReal) {
selected = createSqlType(REAL, selected.isNullable());
}
}
return selected;
}
Aggregations