public Type getJavaClass(RelDataType type) {
   if (type instanceof JavaType) {
     JavaType javaType = (JavaType) type;
     return javaType.getJavaClass();
   }
   if (type.isStruct() && type.getFieldCount() == 1) {
     return getJavaClass(type.getFieldList().get(0).getType());
   }
   if (type instanceof BasicSqlType || type instanceof IntervalSqlType) {
     switch (type.getSqlTypeName()) {
       case VARCHAR:
       case CHAR:
         return String.class;
       case DATE:
       case TIME:
       case INTEGER:
       case INTERVAL_YEAR_MONTH:
         return type.isNullable() ? Integer.class : int.class;
       case TIMESTAMP:
       case BIGINT:
       case INTERVAL_DAY_TIME:
         return type.isNullable() ? Long.class : long.class;
       case SMALLINT:
         return type.isNullable() ? Short.class : short.class;
       case TINYINT:
         return type.isNullable() ? Byte.class : byte.class;
       case DECIMAL:
         return BigDecimal.class;
       case BOOLEAN:
         return type.isNullable() ? Boolean.class : boolean.class;
       case DOUBLE:
       case FLOAT: // sic
         return type.isNullable() ? Double.class : double.class;
       case REAL:
         return type.isNullable() ? Float.class : float.class;
       case BINARY:
       case VARBINARY:
         return ByteString.class;
       case ARRAY:
         return Array.class;
       case ANY:
         return Object.class;
     }
   }
   switch (type.getSqlTypeName()) {
     case ROW:
       assert type instanceof RelRecordType;
       if (type instanceof JavaRecordType) {
         return ((JavaRecordType) type).clazz;
       } else {
         return createSyntheticType((RelRecordType) type);
       }
     case MAP:
       return Map.class;
     case ARRAY:
     case MULTISET:
       return List.class;
   }
   return null;
 }
 public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
   RelDataType type = opBinding.getOperandType(0);
   if (type.isStruct()) {
     type = type.getFieldList().get(0).getType();
   }
   assert type instanceof ArraySqlType || type instanceof MultisetSqlType;
   if (withOrdinality) {
     final RelDataTypeFactory.FieldInfoBuilder builder = opBinding.getTypeFactory().builder();
     if (type.getComponentType().isStruct()) {
       builder.addAll(type.getComponentType().getFieldList());
     } else {
       builder.add(SqlUtil.deriveAliasFromOrdinal(0), type.getComponentType());
     }
     return builder.add(ORDINALITY_COLUMN_NAME, SqlTypeName.INTEGER).build();
   } else {
     return type.getComponentType();
   }
 }