Search in sources :

Example 1 with IndexInputFormat

use of org.apache.carbondata.core.index.IndexInputFormat in project carbondata by apache.

the class CarbonInputFormat method getDistributedCount.

/**
 * This method will execute a distributed job to get the count for the
 * table. If the job fails for some reason then an embedded job is fired to
 * get the count.
 */
Long getDistributedCount(CarbonTable table, List<PartitionSpec> partitionNames, List<Segment> validSegments, Configuration configuration) {
    IndexInputFormat indexInputFormat = new IndexInputFormat(table, null, validSegments, new ArrayList<>(), partitionNames, false, null, false, false);
    indexInputFormat.setIsWriteToFile(false);
    try {
        IndexJob indexJob = (IndexJob) IndexUtil.createIndexJob(IndexUtil.DISTRIBUTED_JOB_NAME);
        if (indexJob == null) {
            throw new ExceptionInInitializerError("Unable to create index job");
        }
        return indexJob.executeCountJob(indexInputFormat, configuration);
    } catch (Exception e) {
        if (CarbonProperties.getInstance().isFallBackDisabled()) {
            LOG.error("Fallback is disabled");
            throw e;
        }
        LOG.error("Failed to get count from index server. Initializing fallback", e);
        IndexJob indexJob = IndexUtil.getEmbeddedJob();
        return indexJob.executeCountJob(indexInputFormat, configuration);
    }
}
Also used : IndexJob(org.apache.carbondata.core.index.IndexJob) IndexInputFormat(org.apache.carbondata.core.index.IndexInputFormat) InvalidConfigurationException(org.apache.carbondata.core.exception.InvalidConfigurationException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InvalidConfigurationException (org.apache.carbondata.core.exception.InvalidConfigurationException)1 IndexInputFormat (org.apache.carbondata.core.index.IndexInputFormat)1 IndexJob (org.apache.carbondata.core.index.IndexJob)1