use of org.apache.carbondata.core.datastore.block.TableBlockInfo in project carbondata by apache.
the class CarbondataRecordSet method cursor.
/**
* get data blocks via Carbondata QueryModel API
*/
@Override
public RecordCursor cursor() {
List<TableBlockInfo> tableBlockInfoList = new ArrayList<TableBlockInfo>();
tableBlockInfoList.add(new TableBlockInfo(split.getLocalInputSplit().getPath().toString(), split.getLocalInputSplit().getStart(), split.getLocalInputSplit().getSegmentId(), split.getLocalInputSplit().getLocations().toArray(new String[0]), split.getLocalInputSplit().getLength(), //blockletInfos,
ColumnarFormatVersion.valueOf(split.getLocalInputSplit().getVersion())));
queryModel.setTableBlockInfos(tableBlockInfoList);
queryExecutor = QueryExecutorFactory.getQueryExecutor(queryModel);
//queryModel.setQueryId(queryModel.getQueryId() + "_" + split.getLocalInputSplit().getSegmentId());
try {
readSupport.initialize(queryModel.getProjectionColumns(), queryModel.getAbsoluteTableIdentifier());
CarbonIterator<Object[]> carbonIterator = new ChunkRowIterator((CarbonIterator<BatchResult>) queryExecutor.execute(queryModel));
RecordCursor rc = new CarbondataRecordCursor(readSupport, carbonIterator, columns, split);
return rc;
} catch (QueryExecutionException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
use of org.apache.carbondata.core.datastore.block.TableBlockInfo in project carbondata by apache.
the class CarbonHiveRecordReader method initialize.
public void initialize(InputSplit inputSplit, Configuration conf) throws IOException {
// The input split can contain single HDFS block or multiple blocks, so firstly get all the
// blocks and then set them in the query model.
List<CarbonHiveInputSplit> splitList;
if (inputSplit instanceof CarbonHiveInputSplit) {
splitList = new ArrayList<>(1);
splitList.add((CarbonHiveInputSplit) inputSplit);
} else {
throw new RuntimeException("unsupported input split type: " + inputSplit);
}
List<TableBlockInfo> tableBlockInfoList = CarbonHiveInputSplit.createBlocks(splitList);
queryModel.setTableBlockInfos(tableBlockInfoList);
readSupport.initialize(queryModel.getProjectionColumns(), queryModel.getAbsoluteTableIdentifier());
try {
carbonIterator = new ChunkRowIterator(queryExecutor.execute(queryModel));
} catch (QueryExecutionException e) {
throw new IOException(e.getMessage(), e.getCause());
}
if (valueObj == null) {
valueObj = new ArrayWritable(Writable.class, new Writable[queryModel.getProjectionColumns().length]);
}
final TypeInfo rowTypeInfo;
final List<String> columnNames;
List<TypeInfo> columnTypes;
// Get column names and sort order
final String colIds = conf.get("hive.io.file.readcolumn.ids");
final String columnNameProperty = conf.get("hive.io.file.readcolumn.names");
final String columnTypeProperty = conf.get(serdeConstants.LIST_COLUMN_TYPES);
if (columnNameProperty.length() == 0) {
columnNames = new ArrayList<String>();
} else {
columnNames = Arrays.asList(columnNameProperty.split(","));
}
if (columnTypeProperty.length() == 0) {
columnTypes = new ArrayList<TypeInfo>();
} else {
columnTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty);
}
String[] arraySelectedColId = colIds.split(",");
List<TypeInfo> reqColTypes = new ArrayList<TypeInfo>();
for (String anArrayColId : arraySelectedColId) {
reqColTypes.add(columnTypes.get(Integer.parseInt(anArrayColId)));
}
// Create row related objects
rowTypeInfo = TypeInfoFactory.getStructTypeInfo(columnNames, reqColTypes);
this.objInspector = new CarbonObjectInspector((StructTypeInfo) rowTypeInfo);
}
use of org.apache.carbondata.core.datastore.block.TableBlockInfo in project carbondata by apache.
the class InMemoryBTreeIndex method filter.
@Override
public List<Block> filter(JobContext job, FilterResolverIntf filter) throws IOException {
List<Block> result = new LinkedList<>();
FilterExpressionProcessor filterExpressionProcessor = new FilterExpressionProcessor();
AbsoluteTableIdentifier identifier = null;
//for this segment fetch blocks matching filter in BTree
List<DataRefNode> dataRefNodes = getDataBlocksOfSegment(job, filterExpressionProcessor, identifier, filter);
for (DataRefNode dataRefNode : dataRefNodes) {
BlockBTreeLeafNode leafNode = (BlockBTreeLeafNode) dataRefNode;
TableBlockInfo tableBlockInfo = leafNode.getTableBlockInfo();
result.add(new CarbonInputSplit(segment.getId(), new Path(tableBlockInfo.getFilePath()), tableBlockInfo.getBlockOffset(), tableBlockInfo.getBlockLength(), tableBlockInfo.getLocations(), tableBlockInfo.getBlockletInfos().getNoOfBlockLets(), tableBlockInfo.getVersion()));
}
return result;
}
use of org.apache.carbondata.core.datastore.block.TableBlockInfo in project carbondata by apache.
the class InMemoryBTreeIndex method getSegmentAbstractIndexs.
private Map<SegmentTaskIndexStore.TaskBucketHolder, AbstractIndex> getSegmentAbstractIndexs(JobContext job, AbsoluteTableIdentifier identifier) throws IOException {
Map<SegmentTaskIndexStore.TaskBucketHolder, AbstractIndex> segmentIndexMap = null;
CacheClient cacheClient = new CacheClient(identifier.getStorePath());
TableSegmentUniqueIdentifier segmentUniqueIdentifier = new TableSegmentUniqueIdentifier(identifier, segment.getId());
try {
SegmentTaskIndexWrapper segmentTaskIndexWrapper = cacheClient.getSegmentAccessClient().getIfPresent(segmentUniqueIdentifier);
if (null != segmentTaskIndexWrapper) {
segmentIndexMap = segmentTaskIndexWrapper.getTaskIdToTableSegmentMap();
}
// if segment tree is not loaded, load the segment tree
if (segmentIndexMap == null) {
List<TableBlockInfo> tableBlockInfoList = getTableBlockInfo(job);
Map<String, List<TableBlockInfo>> segmentToTableBlocksInfos = new HashMap<>();
segmentToTableBlocksInfos.put(segment.getId(), tableBlockInfoList);
segmentUniqueIdentifier.setSegmentToTableBlocksInfos(segmentToTableBlocksInfos);
// TODO: loadAndGetTaskIdToSegmentsMap can be optimized, use tableBlockInfoList as input
// get Btree blocks for given segment
segmentTaskIndexWrapper = cacheClient.getSegmentAccessClient().get(segmentUniqueIdentifier);
segmentIndexMap = segmentTaskIndexWrapper.getTaskIdToTableSegmentMap();
}
} finally {
cacheClient.close();
}
return segmentIndexMap;
}
use of org.apache.carbondata.core.datastore.block.TableBlockInfo in project carbondata by apache.
the class CarbonLoaderUtilTest method initSet2.
void initSet2() {
blockInfos = new ArrayList<>();
activeNode = new ArrayList<>();
activeNode.add("node-7");
activeNode.add("node-9");
activeNode.add("node-11");
String[] location = { "node-7", "node-11" };
blockInfos.add(new TableBlockInfo("node", 1, "1", location, 0));
blockInfos.add(new TableBlockInfo("node", 2, "1", location, 0));
blockInfos.add(new TableBlockInfo("node", 3, "1", location, 0));
blockInfos.add(new TableBlockInfo("node", 4, "1", location, 0));
blockInfos.add(new TableBlockInfo("node", 5, "1", location, 0));
blockInfos.add(new TableBlockInfo("node", 6, "1", location, 0));
expected = new HashMap<>();
expected.put("node-7", blockInfos.subList(0, 2));
expected.put("node-9", blockInfos.subList(2, 4));
expected.put("node-11", blockInfos.subList(4, 6));
}
Aggregations