@Test
 public void testNonAvailableAnnotations() throws Exception {
   TypeDescription typeDescription =
       describe(
           new ByteArrayClassLoader(
                   null,
                   ClassFileExtraction.of(MissingAnnotations.class),
                   null,
                   ByteArrayClassLoader.PersistenceHandler.MANIFEST,
                   PackageDefinitionStrategy.NoOp.INSTANCE)
               .loadClass(MissingAnnotations.class.getName()));
   assertThat(
       typeDescription.getDeclaredAnnotations().isAnnotationPresent(SampleAnnotation.class),
       is(false));
   assertThat(
       typeDescription
           .getDeclaredFields()
           .getOnly()
           .getDeclaredAnnotations()
           .isAnnotationPresent(SampleAnnotation.class),
       is(false));
   assertThat(
       typeDescription
           .getDeclaredMethods()
           .filter(isMethod())
           .getOnly()
           .getDeclaredAnnotations()
           .isAnnotationPresent(SampleAnnotation.class),
       is(false));
 }
 @Override
 public ISpecies getParentSpecies() {
   if (parentSpecies == null) {
     final TypeDescription parentSpecDesc = getDescription().getParent();
     // Takes care of invalid species (see Issue 711)
     if (parentSpecDesc == null || parentSpecDesc == getDescription()) {
       return null;
     }
     ISpecies currentMacroSpec = this.getMacroSpecies();
     while (currentMacroSpec != null && parentSpecies == null) {
       parentSpecies = currentMacroSpec.getMicroSpecies(parentSpecDesc.getName());
       currentMacroSpec = currentMacroSpec.getMacroSpecies();
     }
   }
   return parentSpecies;
 }
 @Test
 public void testEquals() throws Exception {
   TypeDescription identical = describe(SampleClass.class);
   assertThat(identical, equalTo(identical));
   TypeDescription equalFirst = mock(TypeDescription.class);
   when(equalFirst.getName()).thenReturn(SampleClass.class.getName());
   assertThat(describe(SampleClass.class), equalTo(equalFirst));
   assertThat(describe(SampleClass.class), not(equalTo(describe(SampleInterface.class))));
   assertThat(
       describe(SampleClass.class),
       not(equalTo((TypeDescription) new TypeDescription.ForLoadedType(SampleInterface.class))));
   assertThat(describe(SampleClass.class), not(equalTo(new Object())));
   assertThat(describe(SampleClass.class), not(equalTo(null)));
   assertThat(
       describe(Object[].class),
       equalTo((TypeDescription) new TypeDescription.ForLoadedType(Object[].class)));
   assertThat(
       describe(Object[].class),
       not(equalTo((TypeDescription) new TypeDescription.ForLoadedType(Object.class))));
 }
 @Test
 public void testGenericType() throws Exception {
   DynamicType.Unloaded<?> unloaded = new ByteBuddy().redefine(GenericType.class).make();
   Class<?> type =
       unloaded
           .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
           .getLoaded();
   TypeDescription createdType = new TypeDescription.ForLoadedType(type);
   TypeDescription originalType = new TypeDescription.ForLoadedType(GenericType.class);
   assertThat(createdType.getTypeVariables(), is(originalType.getTypeVariables()));
   assertThat(createdType.getSuperClass(), is(originalType.getSuperClass()));
   assertThat(createdType.getInterfaces(), is(originalType.getInterfaces()));
 }
 @Test
 public void testEquals() throws Exception {
   TypeDescription identical = describe(SampleClass.class);
   assertThat(identical, is(identical));
   TypeDescription equalFirst = mock(TypeDescription.class);
   when(equalFirst.getSort()).thenReturn(TypeDefinition.Sort.NON_GENERIC);
   when(equalFirst.asErasure()).thenReturn(equalFirst);
   when(equalFirst.getName()).thenReturn(SampleClass.class.getName());
   assertThat(describe(SampleClass.class), is(equalFirst));
   assertThat(describe(SampleClass.class), not(describe(SampleInterface.class)));
   assertThat(
       describe(SampleClass.class),
       not((TypeDescription) new TypeDescription.ForLoadedType(SampleInterface.class)));
   TypeDefinition nonRawType = mock(TypeDescription.Generic.class);
   when(nonRawType.getSort()).thenReturn(TypeDefinition.Sort.VARIABLE);
   assertThat(describe(SampleClass.class), not(nonRawType));
   assertThat(describe(SampleClass.class), not(new Object()));
   assertThat(describe(SampleClass.class), not(equalTo(null)));
   assertThat(
       describe(Object[].class),
       is((TypeDescription) new TypeDescription.ForLoadedType(Object[].class)));
   assertThat(describe(Object[].class), not(TypeDescription.OBJECT));
 }
Exemple #6
0
  private OrcFile.WriterOptions getOptions(JobConf conf, Properties props) {
    OrcFile.WriterOptions result = OrcFile.writerOptions(props, conf);
    if (props != null) {
      final String columnNameProperty = props.getProperty(IOConstants.COLUMNS);
      final String columnTypeProperty = props.getProperty(IOConstants.COLUMNS_TYPES);
      if (columnNameProperty != null
          && !columnNameProperty.isEmpty()
          && columnTypeProperty != null
          && !columnTypeProperty.isEmpty()) {
        List<String> columnNames;
        List<TypeInfo> columnTypes;

        if (columnNameProperty.length() == 0) {
          columnNames = new ArrayList<String>();
        } else {
          columnNames = Arrays.asList(columnNameProperty.split(","));
        }

        if (columnTypeProperty.length() == 0) {
          columnTypes = new ArrayList<TypeInfo>();
        } else {
          columnTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty);
        }

        TypeDescription schema = TypeDescription.createStruct();
        for (int i = 0; i < columnNames.size(); ++i) {
          schema.addField(columnNames.get(i), convertTypeInfo(columnTypes.get(i)));
        }
        if (LOG.isDebugEnabled()) {
          LOG.debug("ORC schema = " + schema);
        }
        result.setSchema(schema);
      }
    }
    return result;
  }
Exemple #7
0
 static TypeDescription convertTypeInfo(TypeInfo info) {
   switch (info.getCategory()) {
     case PRIMITIVE:
       {
         PrimitiveTypeInfo pinfo = (PrimitiveTypeInfo) info;
         switch (pinfo.getPrimitiveCategory()) {
           case BOOLEAN:
             return TypeDescription.createBoolean();
           case BYTE:
             return TypeDescription.createByte();
           case SHORT:
             return TypeDescription.createShort();
           case INT:
             return TypeDescription.createInt();
           case LONG:
             return TypeDescription.createLong();
           case FLOAT:
             return TypeDescription.createFloat();
           case DOUBLE:
             return TypeDescription.createDouble();
           case STRING:
             return TypeDescription.createString();
           case DATE:
             return TypeDescription.createDate();
           case TIMESTAMP:
             return TypeDescription.createTimestamp();
           case BINARY:
             return TypeDescription.createBinary();
           case DECIMAL:
             {
               DecimalTypeInfo dinfo = (DecimalTypeInfo) pinfo;
               return TypeDescription.createDecimal()
                   .withScale(dinfo.getScale())
                   .withPrecision(dinfo.getPrecision());
             }
           case VARCHAR:
             {
               BaseCharTypeInfo cinfo = (BaseCharTypeInfo) pinfo;
               return TypeDescription.createVarchar().withMaxLength(cinfo.getLength());
             }
           case CHAR:
             {
               BaseCharTypeInfo cinfo = (BaseCharTypeInfo) pinfo;
               return TypeDescription.createChar().withMaxLength(cinfo.getLength());
             }
           default:
             throw new IllegalArgumentException(
                 "ORC doesn't handle primitive" + " category " + pinfo.getPrimitiveCategory());
         }
       }
     case LIST:
       {
         ListTypeInfo linfo = (ListTypeInfo) info;
         return TypeDescription.createList(convertTypeInfo(linfo.getListElementTypeInfo()));
       }
     case MAP:
       {
         MapTypeInfo minfo = (MapTypeInfo) info;
         return TypeDescription.createMap(
             convertTypeInfo(minfo.getMapKeyTypeInfo()),
             convertTypeInfo(minfo.getMapValueTypeInfo()));
       }
     case UNION:
       {
         UnionTypeInfo minfo = (UnionTypeInfo) info;
         TypeDescription result = TypeDescription.createUnion();
         for (TypeInfo child : minfo.getAllUnionObjectTypeInfos()) {
           result.addUnionChild(convertTypeInfo(child));
         }
         return result;
       }
     case STRUCT:
       {
         StructTypeInfo sinfo = (StructTypeInfo) info;
         TypeDescription result = TypeDescription.createStruct();
         for (String fieldName : sinfo.getAllStructFieldNames()) {
           result.addField(fieldName, convertTypeInfo(sinfo.getStructFieldTypeInfo(fieldName)));
         }
         return result;
       }
     default:
       throw new IllegalArgumentException("ORC doesn't handle " + info.getCategory());
   }
 }
 @Test(expected = GenericSignatureFormatError.class)
 public void testMalformedMethodSignature() throws Exception {
   TypeDescription typeDescription = describe(SignatureMalformer.malform(MalformedBase.class));
   assertThat(typeDescription.getDeclaredMethods().filter(isMethod()).size(), is(1));
   typeDescription.getDeclaredMethods().filter(isMethod()).getOnly().getReturnType().getSort();
 }
 @Test(expected = GenericSignatureFormatError.class)
 public void testMalformedTypeSignature() throws Exception {
   TypeDescription typeDescription = describe(SignatureMalformer.malform(MalformedBase.class));
   assertThat(typeDescription.getInterfaces().size(), is(1));
   typeDescription.getInterfaces().getOnly().getSort();
 }