Search in sources :

Example 1 with CarbonTableCacheModel

use of org.apache.carbondata.presto.impl.CarbonTableCacheModel in project carbondata by apache.

the class CarbondataRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    CarbondataSplit carbondataSplit = checkType(split, CarbondataSplit.class, "split is not class CarbondataSplit");
    checkArgument(carbondataSplit.getConnectorId().equals(connectorId), "split is not for this connector");
    CarbonProjection carbonProjection = new CarbonProjection();
    // Convert all columns handles
    ImmutableList.Builder<CarbondataColumnHandle> handles = ImmutableList.builder();
    for (ColumnHandle handle : columns) {
        handles.add(checkType(handle, CarbondataColumnHandle.class, "handle"));
        carbonProjection.addColumn(((CarbondataColumnHandle) handle).getColumnName());
    }
    CarbonTableCacheModel tableCacheModel = carbonTableReader.getCarbonCache(carbondataSplit.getSchemaTableName());
    checkNotNull(tableCacheModel, "tableCacheModel should not be null");
    checkNotNull(tableCacheModel.carbonTable, "tableCacheModel.carbonTable should not be null");
    checkNotNull(tableCacheModel.carbonTable.getTableInfo(), "tableCacheModel.tableInfo should not be null");
    // Build Query Model
    CarbonTable targetTable = tableCacheModel.carbonTable;
    QueryModel queryModel;
    TaskAttemptContextImpl hadoopAttemptContext;
    try {
        Configuration conf = new Configuration();
        conf.set(CarbonTableInputFormat.INPUT_SEGMENT_NUMBERS, "");
        String carbonTablePath = targetTable.getAbsoluteTableIdentifier().getTablePath();
        conf.set(CarbonTableInputFormat.INPUT_DIR, carbonTablePath);
        JobConf jobConf = new JobConf(conf);
        CarbonTableInputFormat carbonTableInputFormat = createInputFormat(jobConf, tableCacheModel.carbonTable, PrestoFilterUtil.parseFilterExpression(carbondataSplit.getConstraints()), carbonProjection);
        hadoopAttemptContext = new TaskAttemptContextImpl(jobConf, new TaskAttemptID("", 1, TaskType.MAP, 0, 0));
        CarbonInputSplit carbonInputSplit = CarbonLocalInputSplit.convertSplit(carbondataSplit.getLocalInputSplit());
        queryModel = carbonTableInputFormat.createQueryModel(carbonInputSplit, hadoopAttemptContext);
        queryModel.setVectorReader(true);
    } catch (IOException e) {
        throw new RuntimeException("Unable to get the Query Model ", e);
    }
    return new CarbondataRecordSet(targetTable, session, carbondataSplit, handles.build(), queryModel, hadoopAttemptContext);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Configuration(org.apache.hadoop.conf.Configuration) ImmutableList(com.google.common.collect.ImmutableList) TaskAttemptID(org.apache.hadoop.mapred.TaskAttemptID) CarbonInputSplit(org.apache.carbondata.hadoop.CarbonInputSplit) IOException(java.io.IOException) QueryModel(org.apache.carbondata.core.scan.model.QueryModel) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) CarbonProjection(org.apache.carbondata.hadoop.CarbonProjection) TaskAttemptContextImpl(org.apache.hadoop.mapred.TaskAttemptContextImpl) CarbonTableCacheModel(org.apache.carbondata.presto.impl.CarbonTableCacheModel) CarbonTableInputFormat(org.apache.carbondata.hadoop.api.CarbonTableInputFormat) JobConf(org.apache.hadoop.mapred.JobConf)

Example 2 with CarbonTableCacheModel

use of org.apache.carbondata.presto.impl.CarbonTableCacheModel in project carbondata by apache.

the class CarbondataSplitManager method getSplits.

public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    CarbondataTableLayoutHandle layoutHandle = (CarbondataTableLayoutHandle) layout;
    CarbondataTableHandle tableHandle = layoutHandle.getTable();
    SchemaTableName key = tableHandle.getSchemaTableName();
    // Packaging presto-TupleDomain into CarbondataColumnConstraint, to decouple from presto-spi Module
    List<CarbondataColumnConstraint> rebuildConstraints = getColumnConstraints(layoutHandle.getConstraint());
    CarbonTableCacheModel cache = carbonTableReader.getCarbonCache(key);
    Expression filters = PrestoFilterUtil.parseFilterExpression(layoutHandle.getConstraint());
    try {
        List<CarbonLocalInputSplit> splits = carbonTableReader.getInputSplits2(cache, filters);
        ImmutableList.Builder<ConnectorSplit> cSplits = ImmutableList.builder();
        for (CarbonLocalInputSplit split : splits) {
            cSplits.add(new CarbondataSplit(connectorId, tableHandle.getSchemaTableName(), layoutHandle.getConstraint(), split, rebuildConstraints));
        }
        return new FixedSplitSource(cSplits.build());
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Expression(org.apache.carbondata.core.scan.expression.Expression) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) CarbonLocalInputSplit(org.apache.carbondata.presto.impl.CarbonLocalInputSplit) CarbonTableCacheModel(org.apache.carbondata.presto.impl.CarbonTableCacheModel) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 CarbonTableCacheModel (org.apache.carbondata.presto.impl.CarbonTableCacheModel)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)1 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 IOException (java.io.IOException)1 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)1 Expression (org.apache.carbondata.core.scan.expression.Expression)1 QueryModel (org.apache.carbondata.core.scan.model.QueryModel)1 CarbonInputSplit (org.apache.carbondata.hadoop.CarbonInputSplit)1 CarbonProjection (org.apache.carbondata.hadoop.CarbonProjection)1 CarbonTableInputFormat (org.apache.carbondata.hadoop.api.CarbonTableInputFormat)1 CarbonLocalInputSplit (org.apache.carbondata.presto.impl.CarbonLocalInputSplit)1 Configuration (org.apache.hadoop.conf.Configuration)1 JobConf (org.apache.hadoop.mapred.JobConf)1 TaskAttemptContextImpl (org.apache.hadoop.mapred.TaskAttemptContextImpl)1 TaskAttemptID (org.apache.hadoop.mapred.TaskAttemptID)1