Search in sources :

Example 1 with HiveStorageFormat

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");
}
Also used : HiveStorageFormat(io.prestosql.plugin.hive.HiveStorageFormat)

Example 2 with HiveStorageFormat

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);
}
Also used : MapredCarbonInputFormat(org.apache.carbondata.hive.MapredCarbonInputFormat) HiveStorageFormat(io.prestosql.plugin.hive.HiveStorageFormat) DataSize(io.airlift.units.DataSize) Unsafe(sun.misc.Unsafe) CarbonHiveSerDe(org.apache.carbondata.hive.CarbonHiveSerDe) MapredCarbonOutputFormat(org.apache.carbondata.hive.MapredCarbonOutputFormat)

Aggregations

HiveStorageFormat (io.prestosql.plugin.hive.HiveStorageFormat)2 DataSize (io.airlift.units.DataSize)1 CarbonHiveSerDe (org.apache.carbondata.hive.CarbonHiveSerDe)1 MapredCarbonInputFormat (org.apache.carbondata.hive.MapredCarbonInputFormat)1 MapredCarbonOutputFormat (org.apache.carbondata.hive.MapredCarbonOutputFormat)1 Unsafe (sun.misc.Unsafe)1