/** * @param readSupportClass to instantiate * @return the configured read support */ private static <T> ReadSupport<T> getReadSupportInstance( Class<? extends ReadSupport<T>> readSupportClass){ try { return readSupportClass.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new BadConfigurationException("could not instantiate read support class", e); } } }
/** * @param readSupportClass to instantiate * @return the configured read support */ private static <T> ReadSupport<T> getReadSupportInstance( Class<? extends ReadSupport<T>> readSupportClass){ try { return readSupportClass.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new BadConfigurationException("could not instantiate read support class", e); } } }
/** * @param readSupportClass to instantiate * @return the configured read support */ private static <T> ReadSupport<T> getReadSupportInstance( Class<? extends ReadSupport<T>> readSupportClass){ try { return readSupportClass.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new BadConfigurationException("could not instantiate read support class", e); } } }
/** * @param thriftClassName the name of the thrift class * @return the class */ public static Class<?> getThriftClass(String thriftClassName) { try { Class<?> thriftClass = Class.forName(thriftClassName); return thriftClass; } catch (ClassNotFoundException e) { throw new BadConfigurationException("Could not instantiate thrift class " + thriftClassName, e); } }
/** * @param readSupportClass to instantiate * @param <T> the Java type of objects created by the ReadSupport * @return the configured read support */ @SuppressWarnings("unchecked") static <T> ReadSupport<T> getReadSupportInstance( Class<? extends ReadSupport<T>> readSupportClass){ try { return readSupportClass.newInstance(); } catch (InstantiationException e) { throw new BadConfigurationException("could not instantiate read support class", e); } catch (IllegalAccessException e) { throw new BadConfigurationException("could not instantiate read support class", e); } }
/** * @param readSupportClass to instantiate * @param <T> the Java type of objects created by the ReadSupport * @return the configured read support */ @SuppressWarnings("unchecked") static <T> ReadSupport<T> getReadSupportInstance( Class<? extends ReadSupport<T>> readSupportClass){ try { return readSupportClass.newInstance(); } catch (InstantiationException e) { throw new BadConfigurationException("could not instantiate read support class", e); } catch (IllegalAccessException e) { throw new BadConfigurationException("could not instantiate read support class", e); } }
public static Class<TProtocolFactory> getTProtocolFactoryClass(Configuration conf) { final String tProtocolClassName = conf.get(PARQUET_PROTOCOL_CLASS); if (tProtocolClassName == null) { throw new BadConfigurationException("the protocol class conf is missing in job conf at " + PARQUET_PROTOCOL_CLASS); } try { @SuppressWarnings("unchecked") Class<TProtocolFactory> tProtocolFactoryClass = (Class<TProtocolFactory>)Class.forName(tProtocolClassName + "$Factory"); return tProtocolFactoryClass; } catch (ClassNotFoundException e) { throw new BadConfigurationException("the Factory for class " + tProtocolClassName + " in job conf at " + PARQUET_PROTOCOL_CLASS + " could not be found", e); } }
public static Class getGenericThriftClass(Configuration configuration) { final String thriftClassName = configuration.get(PARQUET_THRIFT_CLASS); if (thriftClassName == null) { throw new BadConfigurationException("the thrift class conf is missing in job conf at " + PARQUET_THRIFT_CLASS); } try { @SuppressWarnings("unchecked") Class thriftClass = Class.forName(thriftClassName); return thriftClass; } catch (ClassNotFoundException e) { throw new BadConfigurationException("the class "+thriftClassName+" in job conf at " + PARQUET_THRIFT_CLASS + " could not be found", e); } }
/** * @param readSupportClass to instantiate * @return the configured read support */ private static <T> ReadSupport<T> getReadSupportInstance( Class<? extends ReadSupport<T>> readSupportClass){ try { return readSupportClass.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new BadConfigurationException("could not instantiate read support class", e); } } }
public static Class<?> getClassFromConfig(Configuration configuration, String configName, Class<?> assignableFrom) { final String className = configuration.get(configName); if (className == null) { return null; } try { final Class<?> foundClass = configuration.getClassByName(className); if (!assignableFrom.isAssignableFrom(foundClass)) { throw new BadConfigurationException("class " + className + " set in job conf at " + configName + " is not a subclass of " + assignableFrom.getCanonicalName()); } return foundClass; } catch (ClassNotFoundException e) { throw new BadConfigurationException("could not instantiate class " + className + " set in job conf at " + configName, e); } }
private static StructType parseDescriptor(String json) { try { return (StructType)ThriftType.fromJSON(json); } catch (RuntimeException e) { throw new BadConfigurationException("Could not read the thrift descriptor " + json, e); } }
public static Class<?> getClassFromConfig(Configuration configuration, String configName, Class<?> assignableFrom) { final String className = configuration.get(configName); if (className == null) { return null; } try { final Class<?> foundClass = configuration.getClassByName(className); if (!assignableFrom.isAssignableFrom(foundClass)) { throw new BadConfigurationException("class " + className + " set in job conf at " + configName + " is not a subclass of " + assignableFrom.getCanonicalName()); } return foundClass; } catch (ClassNotFoundException e) { throw new BadConfigurationException("could not instantiate class " + className + " set in job conf at " + configName, e); } }
/** * @param configuration to find the configuration for the write support class * @return the configured write support */ @SuppressWarnings("unchecked") public WriteSupport<T> getWriteSupport(Configuration configuration){ if (writeSupport != null) return writeSupport; Class<?> writeSupportClass = getWriteSupportClass(configuration); try { return (WriteSupport<T>)checkNotNull(writeSupportClass, "writeSupportClass").newInstance(); } catch (InstantiationException e) { throw new BadConfigurationException("could not instantiate write support class: " + writeSupportClass, e); } catch (IllegalAccessException e) { throw new BadConfigurationException("could not instantiate write support class: " + writeSupportClass, e); } }
private static UnboundRecordFilter getUnboundRecordFilterInstance(Configuration configuration) { Class<?> clazz = ConfigurationUtil.getClassFromConfig(configuration, UNBOUND_RECORD_FILTER, UnboundRecordFilter.class); if (clazz == null) { return null; } try { UnboundRecordFilter unboundRecordFilter = (UnboundRecordFilter) clazz.newInstance(); if (unboundRecordFilter instanceof Configurable) { ((Configurable)unboundRecordFilter).setConf(configuration); } return unboundRecordFilter; } catch (InstantiationException e) { throw new BadConfigurationException("could not instantiate unbound record filter class", e); } catch (IllegalAccessException e) { throw new BadConfigurationException("could not instantiate unbound record filter class", e); } }
private static UnboundRecordFilter getUnboundRecordFilterInstance(Configuration configuration) { Class<?> clazz = ConfigurationUtil.getClassFromConfig(configuration, UNBOUND_RECORD_FILTER, UnboundRecordFilter.class); if (clazz == null) { return null; } try { UnboundRecordFilter unboundRecordFilter = (UnboundRecordFilter) clazz.newInstance(); if (unboundRecordFilter instanceof Configurable) { ((Configurable)unboundRecordFilter).setConf(configuration); } return unboundRecordFilter; } catch (InstantiationException e) { throw new BadConfigurationException("could not instantiate unbound record filter class", e); } catch (IllegalAccessException e) { throw new BadConfigurationException("could not instantiate unbound record filter class", e); } }
/** * @param configuration to find the configuration for the write support class * @return the configured write support */ @SuppressWarnings("unchecked") public WriteSupport<T> getWriteSupport(Configuration configuration){ if (writeSupport != null) return writeSupport; Class<?> writeSupportClass = getWriteSupportClass(configuration); try { return (WriteSupport<T>)checkNotNull(writeSupportClass, "writeSupportClass").newInstance(); } catch (InstantiationException e) { throw new BadConfigurationException("could not instantiate write support class: " + writeSupportClass, e); } catch (IllegalAccessException e) { throw new BadConfigurationException("could not instantiate write support class: " + writeSupportClass, e); } }
/** * * @param codecName * the requested codec * @return the corresponding hadoop codec. null if UNCOMPRESSED */ protected CompressionCodec getCodec(CompressionCodecName codecName) { String codecClassName = codecName.getHadoopCompressionCodecClassName(); if (codecClassName == null) { return null; } CompressionCodec codec = CODEC_BY_NAME.get(codecClassName); if (codec != null) { return codec; } try { Class<?> codecClass = Class.forName(codecClassName); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, configuration); CODEC_BY_NAME.put(codecClassName, codec); return codec; } catch (ClassNotFoundException e) { throw new BadConfigurationException("Class " + codecClassName + " was not found", e); } }
/** * * @param codecName * the requested codec * @return the corresponding hadoop codec. null if UNCOMPRESSED */ protected CompressionCodec getCodec(CompressionCodecName codecName) { String codecClassName = codecName.getHadoopCompressionCodecClassName(); if (codecClassName == null) { return null; } CompressionCodec codec = CODEC_BY_NAME.get(codecClassName); if (codec != null) { return codec; } try { Class<?> codecClass = Class.forName(codecClassName); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, configuration); CODEC_BY_NAME.put(codecClassName, codec); return codec; } catch (ClassNotFoundException e) { throw new BadConfigurationException("Class " + codecClassName + " was not found", e); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public WriteContext init(Configuration configuration) { try { Class<?> clazz = configuration.getClassByName(className).asSubclass(TBase.class); thriftWriteSupport = new ThriftWriteSupport(clazz); pigToThrift = new PigToThrift(clazz); return thriftWriteSupport.init(configuration); } catch (ClassNotFoundException e) { throw new BadConfigurationException("The thrift class name was not found: " + className, e); } catch (ClassCastException e) { throw new BadConfigurationException("The thrift class name should extend TBase: " + className, e); } }
@Override public WriteContext init(Configuration configuration) { // if no protobuf descriptor was given in constructor, load descriptor from configuration (set with setProtobufClass) if (protoMessage == null) { Class<? extends Message> pbClass = configuration.getClass(PB_CLASS_WRITE, null, Message.class); if (pbClass != null) { protoMessage = pbClass; } else { String msg = "Protocol buffer class not specified."; String hint = " Please use method ProtoParquetOutputFormat.setProtobufClass(...) or other similar method."; throw new BadConfigurationException(msg + hint); } } MessageType rootSchema = new ProtoSchemaConverter().convert(protoMessage); Descriptors.Descriptor messageDescriptor = Protobufs.getMessageDescriptor(protoMessage); validatedMapping(messageDescriptor, rootSchema); this.messageWriter = new MessageWriter(messageDescriptor, rootSchema); Map<String, String> extraMetaData = new HashMap<String, String>(); extraMetaData.put(ProtoReadSupport.PB_CLASS, protoMessage.getName()); extraMetaData.put(ProtoReadSupport.PB_DESCRIPTOR, serializeDescriptor(protoMessage)); return new WriteContext(rootSchema, extraMetaData); }