Github user KanakaKumar commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2715#discussion_r217682375
--- Diff:
core/src/main/java/org/apache/carbondata/core/datastore/compression/CompressorFactory.java
---
@@ -62,15 +67,54 @@ public Compressor getCompressor() {
}
private CompressorFactory() {
- for (SupportedCompressor supportedCompressor :
SupportedCompressor.values()) {
- compressors.put(supportedCompressor.getName(), supportedCompressor);
+ for (NativeSupportedCompressor nativeSupportedCompressor :
NativeSupportedCompressor.values()) {
+ allSupportedCompressors.put(nativeSupportedCompressor.getName(),
+ nativeSupportedCompressor.getCompressor());
}
}
public static CompressorFactory getInstance() {
return COMPRESSOR_FACTORY;
}
+ /**
+ * register the compressor using reflection.
+ * If the class name of the compressor has already been registered
before, it will return false;
+ * If the reflection fails to work or the compressor name has problem,
it will throw
+ * RunTimeException; If it is registered successfully, it will return
true.
+ *
+ * @param compressorClassName full class name of the compressor
+ * @return true if register successfully, false if failed.
+ */
+ private Compressor registerColumnCompressor(String compressorClassName) {
+ if (allSupportedCompressors.containsKey(compressorClassName)) {
+ return allSupportedCompressors.get(compressorClassName);
+ }
+
+ Class clazz;
+ try {
+ clazz = Class.forName(compressorClassName);
+ Object instance = clazz.newInstance();
+ if (instance instanceof Compressor) {
+ if (!((Compressor)
instance).getName().equals(compressorClassName)) {
+ throw new RuntimeException(String.format("For not carbondata
native supported compressor,"
+ + " the result of method getName() should be the full class
name. Expected '%s',"
+ + " found '%s'", compressorClassName, ((Compressor)
instance).getName()));
+ }
+ allSupportedCompressors.put(compressorClassName, (Compressor)
instance);
--- End diff --
Please add a info log for new compression registered.
---