Search in sources :

Example 1 with IndexWriter

use of org.apache.carbondata.core.index.dev.IndexWriter in project carbondata by apache.

the class IndexWriterListener method onPageAdded.

/**
 * Pick corresponding column pages and add to all registered index
 *
 * @param pageId     sequence number of page, start from 0
 * @param tablePage  page data
 */
public void onPageAdded(int blockletId, int pageId, TablePage tablePage) throws IOException {
    Set<Map.Entry<List<CarbonColumn>, List<IndexWriter>>> entries = registry.entrySet();
    for (Map.Entry<List<CarbonColumn>, List<IndexWriter>> entry : entries) {
        List<CarbonColumn> indexedColumns = entry.getKey();
        ColumnPage[] pages = new ColumnPage[indexedColumns.size()];
        for (int i = 0; i < indexedColumns.size(); i++) {
            pages[i] = tablePage.getColumnPage(indexedColumns.get(i).getColName());
        }
        List<IndexWriter> writers = entry.getValue();
        int pageSize = pages[0].getPageSize();
        for (IndexWriter writer : writers) {
            writer.onPageAdded(blockletId, pageId, pageSize, pages);
        }
    }
}
Also used : CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) IndexWriter(org.apache.carbondata.core.index.dev.IndexWriter) ColumnPage(org.apache.carbondata.core.datastore.page.ColumnPage) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 2 with IndexWriter

use of org.apache.carbondata.core.index.dev.IndexWriter in project carbondata by apache.

the class IndexWriterListener method register.

/**
 * Register a IndexWriter
 */
private void register(IndexFactory factory, String segmentId, String taskNo, SegmentProperties segmentProperties) {
    assert (factory != null);
    assert (segmentId != null);
    IndexMeta meta = factory.getMeta();
    if (meta == null) {
        // if index does not have meta, no need to register
        return;
    }
    List<CarbonColumn> columns = factory.getMeta().getIndexedColumns();
    List<IndexWriter> writers = registry.get(columns);
    IndexWriter writer = null;
    try {
        writer = factory.createWriter(new Segment(segmentId), taskNo, segmentProperties);
    } catch (IOException e) {
        LOG.error("Failed to create IndexWriter: " + e.getMessage(), e);
        throw new IndexWriterException(e);
    }
    if (writers != null) {
        writers.add(writer);
    } else {
        writers = new ArrayList<>();
        writers.add(writer);
        registry.put(columns, writers);
    }
    LOG.info("IndexWriter " + writer + " added");
}
Also used : CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) IndexWriter(org.apache.carbondata.core.index.dev.IndexWriter) IndexMeta(org.apache.carbondata.core.index.IndexMeta) IOException(java.io.IOException) Segment(org.apache.carbondata.core.index.Segment)

Aggregations

IndexWriter (org.apache.carbondata.core.index.dev.IndexWriter)2 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ColumnPage (org.apache.carbondata.core.datastore.page.ColumnPage)1 IndexMeta (org.apache.carbondata.core.index.IndexMeta)1 Segment (org.apache.carbondata.core.index.Segment)1