use of io.prestosql.plugin.hive.HiveStorageFormat in project carbondata by apache.
the class CarbondataConnectorFactory method setCarbonEnum.
/**
* Set the Carbon format enum to HiveStorageFormat, its a hack but for time being it is best
* choice to avoid lot of code change.
*
* @throws Exception
*/
private static void setCarbonEnum() throws Exception {
for (HiveStorageFormat format : HiveStorageFormat.values()) {
if (format.name().equals("CARBON") || format.name().equals("ORG.APACHE.CARBONDATA.FORMAT") || format.name().equals("CARBONDATA")) {
return;
}
}
addHiveStorageFormatsForCarbondata("CARBON");
addHiveStorageFormatsForCarbondata("ORG.APACHE.CARBONDATA.FORMAT");
addHiveStorageFormatsForCarbondata("CARBONDATA");
}
use of io.prestosql.plugin.hive.HiveStorageFormat in project carbondata by apache.
the class CarbondataConnectorFactory method addHiveStorageFormatsForCarbondata.
private static void addHiveStorageFormatsForCarbondata(String storedAs) throws Exception {
Constructor<?> constructor = Unsafe.class.getDeclaredConstructors()[0];
constructor.setAccessible(true);
Unsafe unsafe = (Unsafe) constructor.newInstance();
HiveStorageFormat enumValue = (HiveStorageFormat) unsafe.allocateInstance(HiveStorageFormat.class);
Field nameField = Enum.class.getDeclaredField("name");
makeAccessible(nameField);
nameField.set(enumValue, storedAs);
Field ordinalField = Enum.class.getDeclaredField("ordinal");
makeAccessible(ordinalField);
ordinalField.setInt(enumValue, HiveStorageFormat.values().length);
Field serdeField = HiveStorageFormat.class.getDeclaredField("serde");
makeAccessible(serdeField);
serdeField.set(enumValue, CarbonHiveSerDe.class.getName());
Field inputFormatField = HiveStorageFormat.class.getDeclaredField("inputFormat");
makeAccessible(inputFormatField);
inputFormatField.set(enumValue, MapredCarbonInputFormat.class.getName());
Field outputFormatField = HiveStorageFormat.class.getDeclaredField("outputFormat");
makeAccessible(outputFormatField);
outputFormatField.set(enumValue, MapredCarbonOutputFormat.class.getName());
Field estimatedWriterSystemMemoryUsageField = HiveStorageFormat.class.getDeclaredField("estimatedWriterSystemMemoryUsage");
makeAccessible(estimatedWriterSystemMemoryUsageField);
estimatedWriterSystemMemoryUsageField.set(enumValue, new DataSize((long) 256, MEGABYTE));
Field values = HiveStorageFormat.class.getDeclaredField("$VALUES");
makeAccessible(values);
HiveStorageFormat[] hiveStorageFormats = new HiveStorageFormat[HiveStorageFormat.values().length + 1];
HiveStorageFormat[] src = (HiveStorageFormat[]) values.get(null);
System.arraycopy(src, 0, hiveStorageFormats, 0, src.length);
hiveStorageFormats[src.length] = enumValue;
values.set(null, hiveStorageFormats);
}
Aggregations