public static SchemaProvider createSchemaProvider(String schemaProviderClass, TypedProperties cfg, JavaSparkContext jssc) throws IOException { try { return (SchemaProvider) ReflectionUtils.loadClass(schemaProviderClass, cfg, jssc); } catch (Throwable e) { throw new IOException("Could not load schema provider class " + schemaProviderClass, e); } }
public static void main(String[] args) { ReflectionUtils.getTopLevelClassesInClasspath(Main.class).forEach(System.out::println); } }
/** * Creates an instnace of the given class. Use this version when dealing with interface types as constructor args. */ public static Object loadClass(String clazz, Class<?>[] constructorArgTypes, Object... constructorArgs) { try { return getClass(clazz).getConstructor(constructorArgTypes).newInstance(constructorArgs); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new HoodieException("Unable to instantiate class ", e); } }
/** * Utility method to convert bytes to HoodieRecord using schema and payload class */ public static <R> R convertToHoodieRecordPayload(GenericRecord rec, String payloadClazz) { String recKey = rec.get(HoodieRecord.RECORD_KEY_METADATA_FIELD) .toString(); String partitionPath = rec.get(HoodieRecord.PARTITION_PATH_METADATA_FIELD) .toString(); HoodieRecord<? extends HoodieRecordPayload> hoodieRecord = new HoodieRecord<>( new HoodieKey(recKey, partitionPath), ReflectionUtils .loadPayload(payloadClazz, new Object[]{Optional.of(rec)}, Optional.class)); return (R) hoodieRecord; }
public static <T> T loadClass(String fqcn) { try { return (T) getClass(fqcn).newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new HoodieException("Could not load class " + fqcn, e); } }
/** * Utility method to convert bytes to HoodieRecord using schema and payload class */ public static <R> R generateEmptyPayload(String recKey, String partitionPath, String payloadClazz) { HoodieRecord<? extends HoodieRecordPayload> hoodieRecord = new HoodieRecord<>( new HoodieKey(recKey, partitionPath), ReflectionUtils .loadPayload(payloadClazz, new Object[]{Optional.empty()}, Optional.class)); return (R) hoodieRecord; } }
/** * Create a payload class via reflection, passing in an ordering/precombine value. */ public static HoodieRecordPayload createPayload(String payloadClass, GenericRecord record, Comparable orderingVal) throws IOException { try { return (HoodieRecordPayload) ReflectionUtils .loadClass(payloadClass, new Class<?>[]{GenericRecord.class, Comparable.class}, record, orderingVal); } catch (Throwable e) { throw new IOException("Could not create payload for class: " + payloadClass, e); } }
public static void main(String[] args) { ReflectionUtils.getTopLevelClassesInClasspath(Main.class).forEach(System.out::println); } }
/** * Instantiate a given class with a generic record payload */ public static <T extends HoodieRecordPayload> T loadPayload(String recordPayloadClass, Object[] payloadArgs, Class<?>... constructorArgTypes) { try { return (T) getClass(recordPayloadClass).getConstructor(constructorArgTypes) .newInstance(payloadArgs); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new HoodieException("Unable to instantiate payload class ", e); } }
public static Source createSource(String sourceClass, TypedProperties cfg, JavaSparkContext jssc, SchemaProvider schemaProvider) throws IOException { try { return (Source) ReflectionUtils.loadClass(sourceClass, new Class<?>[]{TypedProperties.class, JavaSparkContext.class, SchemaProvider.class}, cfg, jssc, schemaProvider); } catch (Throwable e) { throw new IOException("Could not load source class " + sourceClass, e); } }
public static void main(String[] args) { ReflectionUtils.getTopLevelClassesInClasspath(Main.class).forEach(System.out::println); } }
public CompactionStrategy getCompactionStrategy() { return ReflectionUtils .loadClass(props.getProperty(HoodieCompactionConfig.COMPACTION_STRATEGY_PROP)); }
/** * Create a payload class via reflection, passing in an ordering/precombine value. */ public static HoodieRecordPayload createPayload(String payloadClass, GenericRecord record, Comparable orderingVal) throws IOException { try { return (HoodieRecordPayload) ReflectionUtils .loadClass(payloadClass, new Class<?>[]{GenericRecord.class, Comparable.class}, record, orderingVal); } catch (Throwable e) { throw new IOException("Could not create payload for class: " + payloadClass, e); } }
/** * Create a key generator class via reflection, passing in any configs needed */ public static KeyGenerator createKeyGenerator(String keyGeneratorClass, TypedProperties props) throws IOException { try { return (KeyGenerator) ReflectionUtils.loadClass(keyGeneratorClass, props); } catch (Throwable e) { throw new IOException("Could not load key generator class " + keyGeneratorClass, e); } }
public CompactionStrategy getCompactionStrategy() { return ReflectionUtils .loadClass(props.getProperty(HoodieCompactionConfig.COMPACTION_STRATEGY_PROP)); }
/** * Create a key generator class via reflection, passing in any configs needed */ public static KeyGenerator createKeyGenerator(String keyGeneratorClass, TypedProperties props) throws IOException { try { return (KeyGenerator) ReflectionUtils.loadClass(keyGeneratorClass, props); } catch (Throwable e) { throw new IOException("Could not load key generator class " + keyGeneratorClass, e); } }
public static Source createSource(String sourceClass, TypedProperties cfg, JavaSparkContext jssc, SchemaProvider schemaProvider) throws IOException { try { return (Source) ReflectionUtils.loadClass(sourceClass, new Class<?>[]{TypedProperties.class, JavaSparkContext.class, SchemaProvider.class}, cfg, jssc, schemaProvider); } catch (Throwable e) { throw new IOException("Could not load source class " + sourceClass, e); } }
public static SchemaProvider createSchemaProvider(String schemaProviderClass, TypedProperties cfg, JavaSparkContext jssc) throws IOException { try { return (SchemaProvider) ReflectionUtils.loadClass(schemaProviderClass, cfg, jssc); } catch (Throwable e) { throw new IOException("Could not load schema provider class " + schemaProviderClass, e); } }
/** * Creates an instance of the given class. Constructor arg types are inferred. */ public static Object loadClass(String clazz, Object... constructorArgs) { Class<?>[] constructorArgTypes = Arrays.stream(constructorArgs) .map(Object::getClass).toArray(Class<?>[]::new); return loadClass(clazz, constructorArgTypes, constructorArgs); }
public HoodieAppendHandle(HoodieWriteConfig config, String commitTime, HoodieTable<T> hoodieTable, String fileId, Iterator<HoodieRecord<T>> recordItr) { super(config, commitTime, hoodieTable); WriteStatus writeStatus = ReflectionUtils.loadClass(config.getWriteStatusClassName()); writeStatus.setStat(new HoodieDeltaWriteStat()); this.writeStatus = writeStatus; this.fileId = fileId; this.fileSystemView = hoodieTable.getRTFileSystemView(); this.recordItr = recordItr; }