Search in sources :

Example 1 with BlockMetadata

use of com.linkedin.pinot.core.common.BlockMetadata in project pinot by linkedin.

the class RealtimeTableDataManagerTest method testSetup.

public void testSetup() throws Exception {
    final HLRealtimeSegmentDataManager manager = new HLRealtimeSegmentDataManager(realtimeSegmentZKMetadata, tableConfig, instanceZKMetadata, null, tableDataManagerConfig.getDataDir(), ReadMode.valueOf(tableDataManagerConfig.getReadMode()), getTestSchema(), new ServerMetrics(new MetricsRegistry()));
    final long start = System.currentTimeMillis();
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            if (System.currentTimeMillis() - start >= (SEGMENT_CONSUMING_TIME)) {
                keepOnRunning = false;
            }
        }
    }, 1000, 1000 * 60 * 1);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("count");
                BlockValSet valSet = mDs.nextBlock().getBlockValueSet();
                BlockSingleValIterator valIt = (BlockSingleValIterator) valSet.iterator();
                int val = valIt.nextIntVal();
                while (val != Constants.EOF) {
                    val = valIt.nextIntVal();
                    sum += val;
                }
            } catch (Exception e) {
                LOGGER.info("count column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan metric col count : " + (stop - start) + " sum : " + sum);
        }
    }, 20000, 1000 * 5);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("viewerId");
                BlockValSet valSet = mDs.nextBlock().getBlockValueSet();
                BlockSingleValIterator valIt = (BlockSingleValIterator) valSet.iterator();
                int val = valIt.nextIntVal();
                while (val != Constants.EOF) {
                    val = valIt.nextIntVal();
                    sum += val;
                }
            } catch (Exception e) {
                LOGGER.info("viewerId column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan SV dimension col viewerId : " + (stop - start) + " sum : " + sum);
        }
    }, 20000, 1000 * 5);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("daysSinceEpoch");
                BlockValSet valSet = mDs.nextBlock().getBlockValueSet();
                BlockSingleValIterator valIt = (BlockSingleValIterator) valSet.iterator();
                int val = valIt.nextIntVal();
                while (val != Constants.EOF) {
                    val = valIt.nextIntVal();
                    sum += val;
                }
            } catch (Exception e) {
                LOGGER.info("daysSinceEpoch column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan SV time col daysSinceEpoch : " + (stop - start) + " sum : " + sum);
        }
    }, 20000, 1000 * 5);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            float sumOfLengths = 0F;
            float counter = 0F;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("viewerCompanies");
                Block b = mDs.nextBlock();
                BlockValSet valSet = b.getBlockValueSet();
                BlockMultiValIterator valIt = (BlockMultiValIterator) valSet.iterator();
                BlockMetadata m = b.getMetadata();
                int maxVams = m.getMaxNumberOfMultiValues();
                while (valIt.hasNext()) {
                    int[] vals = new int[maxVams];
                    int len = valIt.nextIntVal(vals);
                    for (int i = 0; i < len; i++) {
                        sum += vals[i];
                    }
                    sumOfLengths += len;
                    counter++;
                }
            } catch (Exception e) {
                LOGGER.info("daysSinceEpoch column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan MV col viewerCompanies : " + (stop - start) + " sum : " + sum + " average len : " + (sumOfLengths / counter));
        }
    }, 20000, 1000 * 5);
    while (keepOnRunning) {
    // Wait for keepOnRunning to be set to false
    }
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) BlockMultiValIterator(com.linkedin.pinot.core.common.BlockMultiValIterator) TimerTask(java.util.TimerTask) RealtimeColumnDataSource(com.linkedin.pinot.core.realtime.impl.datasource.RealtimeColumnDataSource) BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) BlockMetadata(com.linkedin.pinot.core.common.BlockMetadata) BlockValSet(com.linkedin.pinot.core.common.BlockValSet) Block(com.linkedin.pinot.core.common.Block) ServerMetrics(com.linkedin.pinot.common.metrics.ServerMetrics) HLRealtimeSegmentDataManager(com.linkedin.pinot.core.data.manager.realtime.HLRealtimeSegmentDataManager) RealtimeSegment(com.linkedin.pinot.core.realtime.RealtimeSegment)

Example 2 with BlockMetadata

use of com.linkedin.pinot.core.common.BlockMetadata in project pinot by linkedin.

the class NoDictionaryMultiColumnGroupKeyGenerator method generateKeysForBlock.

@Override
public void generateKeysForBlock(TransformBlock transformBlock, int[] docIdToGroupKey) {
    int numGroupByColumns = _groupByColumns.length;
    int numDocs = transformBlock.getNumDocs();
    Object[] values = new Object[numGroupByColumns];
    boolean[] hasDictionary = new boolean[numGroupByColumns];
    FieldSpec.DataType[] dataTypes = new FieldSpec.DataType[numGroupByColumns];
    for (int i = 0; i < numGroupByColumns; i++) {
        BlockValSet blockValSet = transformBlock.getBlockValueSet(_groupByColumns[i]);
        dataTypes[i] = blockValSet.getValueType();
        BlockMetadata blockMetadata = transformBlock.getBlockMetadata(_groupByColumns[i]);
        if (blockMetadata.hasDictionary()) {
            hasDictionary[i] = true;
            values[i] = blockValSet.getDictionaryIds();
        } else {
            hasDictionary[i] = false;
            values[i] = getValuesFromBlockValSet(blockValSet, dataTypes[i]);
        }
    }
    for (int i = 0; i < numDocs; i++) {
        int[] keys = new int[numGroupByColumns];
        for (int j = 0; j < numGroupByColumns; j++) {
            if (hasDictionary[j]) {
                int[] dictIds = (int[]) values[j];
                keys[j] = dictIds[i];
            } else {
                switch(dataTypes[j]) {
                    case INT:
                        int[] intValues = (int[]) values[j];
                        keys[j] = _onTheFlyDictionaries[j].put(intValues[i]);
                        break;
                    case LONG:
                        long[] longValues = (long[]) values[j];
                        keys[j] = _onTheFlyDictionaries[j].put(longValues[i]);
                        break;
                    case FLOAT:
                        float[] floatValues = (float[]) values[j];
                        keys[j] = _onTheFlyDictionaries[j].put(floatValues[i]);
                        break;
                    case DOUBLE:
                        double[] doubleValues = (double[]) values[j];
                        keys[j] = _onTheFlyDictionaries[j].put(doubleValues[i]);
                        break;
                    case STRING:
                        String[] stringValues = (String[]) values[j];
                        keys[j] = _onTheFlyDictionaries[j].put(stringValues[i]);
                        break;
                    default:
                        throw new IllegalArgumentException("Illegal data type for no-dictionary key generator: " + dataTypes[j]);
                }
            }
        }
        docIdToGroupKey[i] = getGroupIdForKey(new FixedIntArray(keys));
    }
}
Also used : BlockMetadata(com.linkedin.pinot.core.common.BlockMetadata) BlockValSet(com.linkedin.pinot.core.common.BlockValSet)

Example 3 with BlockMetadata

use of com.linkedin.pinot.core.common.BlockMetadata in project pinot by linkedin.

the class RealtimeFileBasedReaderTest method testDataSourceWithoutPredicateForSingleValueTimeColumns.

private void testDataSourceWithoutPredicateForSingleValueTimeColumns() {
    for (FieldSpec spec : schema.getAllFieldSpecs()) {
        if (spec.isSingleValueField() && spec.getFieldType() == FieldType.TIME) {
            DataSource offlineDS = offlineSegment.getDataSource(spec.getName());
            DataSource realtimeDS = realtimeSegment.getDataSource(spec.getName());
            Block offlineBlock = offlineDS.nextBlock();
            Block realtimeBlock = realtimeDS.nextBlock();
            BlockMetadata offlineMetadata = offlineBlock.getMetadata();
            BlockMetadata realtimeMetadata = realtimeBlock.getMetadata();
            BlockSingleValIterator offlineValIterator = (BlockSingleValIterator) offlineBlock.getBlockValueSet().iterator();
            BlockSingleValIterator realtimeValIterator = (BlockSingleValIterator) realtimeBlock.getBlockValueSet().iterator();
            Assert.assertEquals(offlineSegment.getSegmentMetadata().getTotalDocs(), realtimeSegment.getAggregateDocumentCount());
            while (realtimeValIterator.hasNext()) {
                int offlineDicId = offlineValIterator.nextIntVal();
                int realtimeDicId = realtimeValIterator.nextIntVal();
                Assert.assertEquals(offlineMetadata.getDictionary().get(offlineDicId), realtimeMetadata.getDictionary().get(realtimeDicId));
            }
            Assert.assertEquals(offlineValIterator.hasNext(), realtimeValIterator.hasNext());
        }
    }
}
Also used : BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) BlockMetadata(com.linkedin.pinot.core.common.BlockMetadata) Block(com.linkedin.pinot.core.common.Block) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) DataSource(com.linkedin.pinot.core.common.DataSource)

Example 4 with BlockMetadata

use of com.linkedin.pinot.core.common.BlockMetadata in project pinot by linkedin.

the class RealtimeFileBasedReaderTest method testDataSourceWithoutPredicateForSingleValueMetricColumns.

private void testDataSourceWithoutPredicateForSingleValueMetricColumns() {
    for (FieldSpec spec : schema.getAllFieldSpecs()) {
        if (spec.isSingleValueField() && spec.getFieldType() == FieldType.METRIC) {
            DataSource offlineDS = offlineSegment.getDataSource(spec.getName());
            DataSource realtimeDS = realtimeSegment.getDataSource(spec.getName());
            Block offlineBlock = offlineDS.nextBlock();
            Block realtimeBlock = realtimeDS.nextBlock();
            BlockMetadata offlineMetadata = offlineBlock.getMetadata();
            BlockMetadata realtimeMetadata = realtimeBlock.getMetadata();
            BlockSingleValIterator offlineValIterator = (BlockSingleValIterator) offlineBlock.getBlockValueSet().iterator();
            BlockSingleValIterator realtimeValIterator = (BlockSingleValIterator) realtimeBlock.getBlockValueSet().iterator();
            Assert.assertEquals(offlineSegment.getSegmentMetadata().getTotalDocs(), realtimeSegment.getAggregateDocumentCount());
            while (realtimeValIterator.hasNext()) {
                int offlineDicId = offlineValIterator.nextIntVal();
                int realtimeDicId = realtimeValIterator.nextIntVal();
                Object value;
                if (realtimeMetadata.hasDictionary()) {
                    value = realtimeMetadata.getDictionary().get(realtimeDicId);
                } else {
                    value = realtimeDicId;
                }
                Assert.assertEquals(offlineMetadata.getDictionary().get(offlineDicId), value);
            }
            Assert.assertEquals(offlineValIterator.hasNext(), realtimeValIterator.hasNext());
        }
    }
}
Also used : BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) BlockMetadata(com.linkedin.pinot.core.common.BlockMetadata) Block(com.linkedin.pinot.core.common.Block) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) DataSource(com.linkedin.pinot.core.common.DataSource)

Example 5 with BlockMetadata

use of com.linkedin.pinot.core.common.BlockMetadata in project pinot by linkedin.

the class RealtimeFileBasedReaderTest method testDataSourceWithoutPredicateForSingleValueDimensionColumns.

private void testDataSourceWithoutPredicateForSingleValueDimensionColumns() {
    for (FieldSpec spec : schema.getAllFieldSpecs()) {
        if (spec.isSingleValueField() && spec.getFieldType() == FieldType.DIMENSION) {
            DataSource offlineDS = offlineSegment.getDataSource(spec.getName());
            DataSource realtimeDS = realtimeSegment.getDataSource(spec.getName());
            Block offlineBlock = offlineDS.nextBlock();
            Block realtimeBlock = realtimeDS.nextBlock();
            BlockMetadata offlineMetadata = offlineBlock.getMetadata();
            BlockMetadata realtimeMetadata = realtimeBlock.getMetadata();
            BlockSingleValIterator offlineValIterator = (BlockSingleValIterator) offlineBlock.getBlockValueSet().iterator();
            BlockSingleValIterator realtimeValIterator = (BlockSingleValIterator) realtimeBlock.getBlockValueSet().iterator();
            Assert.assertEquals(offlineSegment.getSegmentMetadata().getTotalDocs(), realtimeSegment.getAggregateDocumentCount());
            while (realtimeValIterator.hasNext()) {
                int offlineDicId = offlineValIterator.nextIntVal();
                int realtimeDicId = realtimeValIterator.nextIntVal();
                try {
                    Assert.assertEquals(offlineMetadata.getDictionary().get(offlineDicId), realtimeMetadata.getDictionary().get(realtimeDicId));
                } catch (AssertionError e) {
                    LOGGER.info("column : {}", spec.getName());
                    LOGGER.info("realtimeDicId : {}, rawValue : {}", realtimeDicId, realtimeMetadata.getDictionary().get(realtimeDicId));
                    LOGGER.info("offlineDicId : {}, rawValue : {}", offlineDicId, offlineMetadata.getDictionary().get(offlineDicId));
                    throw e;
                }
            }
            Assert.assertEquals(offlineValIterator.hasNext(), realtimeValIterator.hasNext());
        }
    }
}
Also used : BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) BlockMetadata(com.linkedin.pinot.core.common.BlockMetadata) Block(com.linkedin.pinot.core.common.Block) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) DataSource(com.linkedin.pinot.core.common.DataSource)

Aggregations

BlockMetadata (com.linkedin.pinot.core.common.BlockMetadata)11 Block (com.linkedin.pinot.core.common.Block)8 BlockSingleValIterator (com.linkedin.pinot.core.common.BlockSingleValIterator)6 DataSource (com.linkedin.pinot.core.common.DataSource)6 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)5 BlockValSet (com.linkedin.pinot.core.common.BlockValSet)5 Test (org.testng.annotations.Test)3 BlockMultiValIterator (com.linkedin.pinot.core.common.BlockMultiValIterator)2 RealtimeSegmentImplTest (com.linkedin.pinot.core.realtime.impl.kafka.RealtimeSegmentImplTest)2 ServerMetrics (com.linkedin.pinot.common.metrics.ServerMetrics)1 BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)1 DataSourceMetadata (com.linkedin.pinot.core.common.DataSourceMetadata)1 HLRealtimeSegmentDataManager (com.linkedin.pinot.core.data.manager.realtime.HLRealtimeSegmentDataManager)1 BaseFilterBlock (com.linkedin.pinot.core.operator.blocks.BaseFilterBlock)1 BitmapDocIdSet (com.linkedin.pinot.core.operator.docidsets.BitmapDocIdSet)1 FilterBlockDocIdSet (com.linkedin.pinot.core.operator.docidsets.FilterBlockDocIdSet)1 ScanBasedMultiValueDocIdSet (com.linkedin.pinot.core.operator.docidsets.ScanBasedMultiValueDocIdSet)1 ScanBasedSingleValueDocIdSet (com.linkedin.pinot.core.operator.docidsets.ScanBasedSingleValueDocIdSet)1 RealtimeSegment (com.linkedin.pinot.core.realtime.RealtimeSegment)1 RealtimeColumnDataSource (com.linkedin.pinot.core.realtime.impl.datasource.RealtimeColumnDataSource)1