/** Returns whether this type is a primitive, box or other type. Useful for * switch statements. */ public static Flavor flavor(Type type) { if (is(type)) { return Flavor.PRIMITIVE; } else if (isBox(type)) { return Flavor.BOX; } else { return Flavor.OBJECT; } }
public ArrayType(Type componentType) { this(componentType, !Primitive.is(componentType), -1L); }
RecordFieldImpl( SyntheticRecordType syntheticType, String name, Type type, boolean nullable, int modifiers) { this.syntheticType = Objects.requireNonNull(syntheticType); this.name = Objects.requireNonNull(name); this.type = Objects.requireNonNull(type); this.nullable = nullable; this.modifiers = modifiers; assert !(nullable && Primitive.is(type)) : "type [" + type + "] can never be null"; }
RecordFieldImpl( SyntheticRecordType syntheticType, String name, Type type, boolean nullable, int modifiers) { this.syntheticType = Objects.requireNonNull(syntheticType); this.name = Objects.requireNonNull(name); this.type = Objects.requireNonNull(type); this.nullable = nullable; this.modifiers = modifiers; assert !(nullable && Primitive.is(type)) : "type [" + type + "] can never be null"; }
private boolean isAbstractMethodPrimitive() { Method method = getAbstractMethod(); return method != null && Primitive.is(method.getReturnType()); }
/** Returns e.g. ", ignoreNulls". */ private static StringBuilder safeArgList(StringBuilder buff, Method method) { for (Ord<Class<?>> t : Ord.zip(method.getParameterTypes())) { if (Primitive.is(t.e)) { buff.append(", a").append(t.i); } else if (RexNode.class.isAssignableFrom(t.e)) { // For RexNode, convert to string, because equals does not look deep. // a1 == null ? "" : a1.toString() buff.append(", a").append(t.i).append(" == null ? \"\" : a") .append(t.i).append(".toString()"); } else { buff.append(", ") .append(NullSentinel.class.getName()) .append(".mask(a").append(t.i).append(")"); } } return buff; }
/** Returns e.g. ", ignoreNulls". */ private static StringBuilder safeArgList(StringBuilder buff, Method method) { for (Ord<Class<?>> t : Ord.zip(method.getParameterTypes())) { if (Primitive.is(t.e)) { buff.append(", a").append(t.i); } else if (RexNode.class.isAssignableFrom(t.e)) { // For RexNode, convert to string, because equals does not look deep. // a1 == null ? "" : a1.toString() buff.append(", a").append(t.i).append(" == null ? \"\" : a") .append(t.i).append(".toString()"); } else { buff.append(", ") .append(NullSentinel.class.getName()) .append(".mask(a").append(t.i).append(")"); } } return buff; }
/** * Returns whether an expression always returns a non-null result. * For instance, primitive types cannot contain null values. * * @param expression expression to test * @return true when the expression is known to be not-null */ protected boolean isKnownNotNull(Expression expression) { return Primitive.is(expression.getType()) || always(expression) != null || (expression instanceof MethodCallExpression && KNOWN_NON_NULL_METHODS.contains( ((MethodCallExpression) expression).method)); }
private JavaRowFormat format() { int fieldCount = getRowType().getFieldCount(); if (fieldCount == 0) { return JavaRowFormat.LIST; } if (Object[].class.isAssignableFrom(elementType)) { return fieldCount == 1 ? JavaRowFormat.SCALAR : JavaRowFormat.ARRAY; } if (Row.class.isAssignableFrom(elementType)) { return JavaRowFormat.ROW; } if (fieldCount == 1 && (Object.class == elementType || Primitive.is(elementType) || Number.class.isAssignableFrom(elementType))) { return JavaRowFormat.SCALAR; } return JavaRowFormat.CUSTOM; }
private JavaRowFormat format() { int fieldCount = getRowType().getFieldCount(); if (fieldCount == 0) { return JavaRowFormat.LIST; } if (Object[].class.isAssignableFrom(elementType)) { return fieldCount == 1 ? JavaRowFormat.SCALAR : JavaRowFormat.ARRAY; } if (Row.class.isAssignableFrom(elementType)) { return JavaRowFormat.ROW; } if (fieldCount == 1 && (Object.class == elementType || Primitive.is(elementType) || Number.class.isAssignableFrom(elementType))) { return JavaRowFormat.SCALAR; } return JavaRowFormat.CUSTOM; }
public Type createSyntheticType(List<Type> types) { if (types.isEmpty()) { // Unit is a pre-defined synthetic type to be used when there are 0 // fields. Because all instances are the same, we use a singleton. return Unit.class; } final String name = "Record" + types.size() + "_" + syntheticTypes.size(); final SyntheticRecordType syntheticType = new SyntheticRecordType(null, name); for (final Ord<Type> ord : Ord.zip(types)) { syntheticType.fields.add( new RecordFieldImpl( syntheticType, "f" + ord.i, ord.e, !Primitive.is(ord.e), Modifier.PUBLIC)); } return register(syntheticType); }
public Type createSyntheticType(List<Type> types) { if (types.isEmpty()) { // Unit is a pre-defined synthetic type to be used when there are 0 // fields. Because all instances are the same, we use a singleton. return Unit.class; } final String name = "Record" + types.size() + "_" + syntheticTypes.size(); final SyntheticRecordType syntheticType = new SyntheticRecordType(null, name); for (final Ord<Type> ord : Ord.zip(types)) { syntheticType.fields.add( new RecordFieldImpl( syntheticType, "f" + ord.i, ord.e, !Primitive.is(ord.e), Modifier.PUBLIC)); } return register(syntheticType); }
static Expression getDefaultValue(Type type) { if (Primitive.is(type)) { Primitive p = Primitive.of(type); return Expressions.constant(p.defaultValue, type); } return Expressions.constant(null, type); }
static Expression getDefaultValue(Type type) { if (Primitive.is(type)) { Primitive p = Primitive.of(type); return Expressions.constant(p.defaultValue, type); } return Expressions.constant(null, type); }
public Expression implement( RexToLixTranslator translator, RexCall call, List<Expression> translatedOperands) { assert call.getOperands().size() == 1; final RelDataType sourceType = call.getOperands().get(0).getType(); // It's only possible for the result to be null if both expression // and target type are nullable. We assume that the caller did not // make a mistake. If expression looks nullable, caller WILL have // checked that expression is not null before calling us. final boolean nullable = translator.isNullable(call) && sourceType.isNullable() && !Primitive.is(translatedOperands.get(0).getType()); final RelDataType targetType = translator.nullifyType(call.getType(), nullable); return translator.translateCast(sourceType, targetType, translatedOperands.get(0)); } }
public Expression implement( RexToLixTranslator translator, RexCall call, List<Expression> translatedOperands) { assert call.getOperands().size() == 1; final RelDataType sourceType = call.getOperands().get(0).getType(); // It's only possible for the result to be null if both expression // and target type are nullable. We assume that the caller did not // make a mistake. If expression looks nullable, caller WILL have // checked that expression is not null before calling us. final boolean nullable = translator.isNullable(call) && sourceType.isNullable() && !Primitive.is(translatedOperands.get(0).getType()); final RelDataType targetType = translator.nullifyType(call.getType(), nullable); return translator.translateCast(sourceType, targetType, translatedOperands.get(0)); } }
static Expression optimize2(Expression operand, Expression expression) { if (Primitive.is(operand.getType())) { // Primitive values cannot be null return optimize(expression); } else { return optimize( Expressions.condition( Expressions.equal( operand, NULL_EXPR), NULL_EXPR, expression)); } }
static Expression optimize2(Expression operand, Expression expression) { if (Primitive.is(operand.getType())) { // Primitive values cannot be null return optimize(expression); } else { return optimize( Expressions.condition( Expressions.equal( operand, NULL_EXPR), NULL_EXPR, expression)); } }
/** Creates a synthetic Java class whose fields have the same names and * relational types. */ private Type createSyntheticType(RelRecordType type) { final String name = "Record" + type.getFieldCount() + "_" + syntheticTypes.size(); final SyntheticRecordType syntheticType = new SyntheticRecordType(type, name); for (final RelDataTypeField recordField : type.getFieldList()) { final Type javaClass = getJavaClass(recordField.getType()); syntheticType.fields.add( new RecordFieldImpl( syntheticType, recordField.getName(), javaClass, recordField.getType().isNullable() && !Primitive.is(javaClass), Modifier.PUBLIC)); } return register(syntheticType); }
/** Creates a synthetic Java class whose fields have the same names and * relational types. */ private Type createSyntheticType(RelRecordType type) { final String name = "Record" + type.getFieldCount() + "_" + syntheticTypes.size(); final SyntheticRecordType syntheticType = new SyntheticRecordType(type, name); for (final RelDataTypeField recordField : type.getFieldList()) { final Type javaClass = getJavaClass(recordField.getType()); syntheticType.fields.add( new RecordFieldImpl( syntheticType, recordField.getName(), javaClass, recordField.getType().isNullable() && !Primitive.is(javaClass), Modifier.PUBLIC)); } return register(syntheticType); }