public RelDataType createType(Type type) {
   if (type instanceof RelDataType) {
     return (RelDataType) type;
   }
   if (type instanceof SyntheticRecordType) {
     final SyntheticRecordType syntheticRecordType = (SyntheticRecordType) type;
     return syntheticRecordType.relType;
   }
   if (type instanceof Types.ArrayType) {
     final Types.ArrayType arrayType = (Types.ArrayType) type;
     final RelDataType componentRelType = createType(arrayType.getComponentType());
     return createArrayType(
         createTypeWithNullability(componentRelType, arrayType.componentIsNullable()),
         arrayType.maximumCardinality());
   }
   if (type instanceof Types.MapType) {
     final Types.MapType mapType = (Types.MapType) type;
     final RelDataType keyRelType = createType(mapType.getKeyType());
     final RelDataType valueRelType = createType(mapType.getValueType());
     return createMapType(
         createTypeWithNullability(keyRelType, mapType.keyIsNullable()),
         createTypeWithNullability(valueRelType, mapType.valueIsNullable()));
   }
   if (!(type instanceof Class)) {
     throw new UnsupportedOperationException("TODO: implement " + type);
   }
   final Class clazz = (Class) type;
   switch (Primitive.flavor(clazz)) {
     case PRIMITIVE:
       return createJavaType(clazz);
     case BOX:
       return createJavaType(Primitive.ofBox(clazz).boxClass);
   }
   if (JavaToSqlTypeConversionRules.instance().lookup(clazz) != null) {
     return createJavaType(clazz);
   } else if (clazz.isArray()) {
     return createMultisetType(createType(clazz.getComponentType()), -1);
   } else if (List.class.isAssignableFrom(clazz)) {
     return createArrayType(createTypeWithNullability(createSqlType(SqlTypeName.ANY), true), -1);
   } else if (Map.class.isAssignableFrom(clazz)) {
     return createMapType(
         createTypeWithNullability(createSqlType(SqlTypeName.ANY), true),
         createTypeWithNullability(createSqlType(SqlTypeName.ANY), true));
   } else {
     return createStructType(clazz);
   }
 }
示例#2
0
 // Only generate inline expressions when comparing primitive types
 private boolean primitiveCompareExpr(SqlOperator op, RelDataType type) {
   final Primitive primitive = Primitive.ofBoxOr(typeFactory.getJavaClass(type));
   return primitive != null
       && (op == LESS_THAN
           || op == LESS_THAN_OR_EQUAL
           || op == GREATER_THAN
           || op == GREATER_THAN_OR_EQUAL);
 }
 public RecordFieldImpl(
     SyntheticRecordType syntheticType,
     String name,
     Type type,
     boolean nullable,
     int modifiers) {
   this.syntheticType = Preconditions.checkNotNull(syntheticType);
   this.name = Preconditions.checkNotNull(name);
   this.type = Preconditions.checkNotNull(type);
   this.nullable = nullable;
   this.modifiers = modifiers;
   assert !(nullable && Primitive.is(type)) : "type [" + type + "] can never be null";
 }
 /** 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);
 }
 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);
 }