Search in sources :

Example 6 with MapValue

use of io.questdb.cairo.map.MapValue in project questdb by bluestreak01.

the class AbstractSampleByFillRecordCursorFactory method getCursor.

@Override
public RecordCursor getCursor(SqlExecutionContext executionContext) throws SqlException {
    final RecordCursor baseCursor = base.getCursor(executionContext);
    final SqlExecutionInterruptor interruptor = executionContext.getSqlExecutionInterruptor();
    try {
        map.clear();
        // This factory fills gaps in data. To do that we
        // have to know all possible key values. Essentially, every time
        // we sample we return same set of key values with different
        // aggregation results and timestamp
        int n = groupByFunctions.size();
        final Record baseCursorRecord = baseCursor.getRecord();
        while (baseCursor.hasNext()) {
            interruptor.checkInterrupted();
            MapKey key = map.withKey();
            mapSink.copy(baseCursorRecord, key);
            MapValue value = key.createValue();
            if (value.isNew()) {
                // timestamp is always stored in value field 0
                value.putLong(0, Numbers.LONG_NaN);
                // this would set values for when keys are not found right away
                for (int i = 0; i < n; i++) {
                    groupByFunctions.getQuick(i).setNull(value);
                }
            }
        }
        // empty map? this means that base cursor was empty
        if (map.size() == 0) {
            baseCursor.close();
            return EmptyTableNoSizeRecordCursor.INSTANCE;
        }
        // because we pass base cursor twice we have to go back to top
        // for the second run
        baseCursor.toTop();
        boolean next = baseCursor.hasNext();
        // we know base cursor has value
        assert next;
        return initFunctionsAndCursor(executionContext, baseCursor);
    } catch (Throwable ex) {
        baseCursor.close();
        throw ex;
    }
}
Also used : EmptyTableNoSizeRecordCursor(io.questdb.griffin.engine.EmptyTableNoSizeRecordCursor) MapKey(io.questdb.cairo.map.MapKey) SqlExecutionInterruptor(io.questdb.griffin.SqlExecutionInterruptor) MapValue(io.questdb.cairo.map.MapValue)

Example 7 with MapValue

use of io.questdb.cairo.map.MapValue in project questdb by bluestreak01.

the class AbstractSampleByFillValueRecordCursor method hasNext.

@Override
public boolean hasNext() {
    // 
    if (mapCursor.hasNext()) {
        // next() will return record that uses current map position
        return refreshRecord();
    }
    if (baseRecord == null) {
        return false;
    }
    // key map has been flushed
    // before we build another one we need to check
    // for timestamp gaps
    // what is the next timestamp we are expecting?
    long expectedLocalEpoch = timestampSampler.nextTimestamp(nextSampleLocalEpoch);
    // is data timestamp ahead of next expected timestamp?
    if (expectedLocalEpoch < localEpoch) {
        this.sampleLocalEpoch = expectedLocalEpoch;
        this.nextSampleLocalEpoch = expectedLocalEpoch;
        // reset iterator on map and stream contents
        return refreshMapCursor();
    }
    long next = timestampSampler.nextTimestamp(localEpoch);
    this.sampleLocalEpoch = localEpoch;
    this.nextSampleLocalEpoch = localEpoch;
    // looks like we need to populate key map
    int n = groupByFunctions.size();
    while (true) {
        long timestamp = getBaseRecordTimestamp();
        if (timestamp < next) {
            adjustDSTInFlight(timestamp - tzOffset);
            final MapKey key = map.withKey();
            keyMapSink.copy(baseRecord, key);
            final MapValue value = key.findValue();
            assert value != null;
            if (value.getLong(0) != localEpoch) {
                value.putLong(0, localEpoch);
                GroupByUtils.updateNew(groupByFunctions, n, value, baseRecord);
            } else {
                GroupByUtils.updateExisting(groupByFunctions, n, value, baseRecord);
            }
            // carry on with the loop if we still have data
            if (base.hasNext()) {
                interruptor.checkInterrupted();
                continue;
            }
            // we ran out of data, make sure hasNext() returns false at the next
            // opportunity, after we stream map that is.
            baseRecord = null;
        } else {
            // timestamp changed, make sure we keep the value of 'lastTimestamp'
            // unchanged. Timestamp columns uses this variable
            // When map is exhausted we would assign 'next' to 'lastTimestamp'
            // and build another map
            timestamp = adjustDST(timestamp, n, null, next);
            if (timestamp != Long.MIN_VALUE) {
                nextSamplePeriod(timestamp);
            }
        }
        return refreshMapCursor();
    }
}
Also used : MapKey(io.questdb.cairo.map.MapKey) MapValue(io.questdb.cairo.map.MapValue)

Example 8 with MapValue

use of io.questdb.cairo.map.MapValue in project questdb by bluestreak01.

the class QMapWriteBenchmark method testDirectMap.

@Benchmark
public void testDirectMap() {
    MapKey key = map.withKey();
    key.putStr(rnd.nextChars(M));
    MapValue values = key.createValue();
    values.putLong(0, 20);
}
Also used : MapKey(io.questdb.cairo.map.MapKey) MapValue(io.questdb.cairo.map.MapValue)

Example 9 with MapValue

use of io.questdb.cairo.map.MapValue in project questdb by bluestreak01.

the class QMapWriteBenchmark method testQMap.

@Benchmark
public void testQMap() {
    MapKey key = qmap.withKey();
    key.putStr(rnd.nextChars(M));
    MapValue value = key.createValue();
    value.putLong(0, 20);
}
Also used : MapKey(io.questdb.cairo.map.MapKey) MapValue(io.questdb.cairo.map.MapValue)

Example 10 with MapValue

use of io.questdb.cairo.map.MapValue in project questdb by bluestreak01.

the class QMapWriteLongBenchmark method testDirectMap.

@Benchmark
public void testDirectMap() {
    MapKey key = map.withKey();
    key.putLong(rnd.nextLong());
    MapValue values = key.createValue();
    values.putLong(0, 20);
}
Also used : MapKey(io.questdb.cairo.map.MapKey) MapValue(io.questdb.cairo.map.MapValue)

Aggregations

MapValue (io.questdb.cairo.map.MapValue)23 MapKey (io.questdb.cairo.map.MapKey)17 MapRecord (io.questdb.cairo.map.MapRecord)2 RecordCursor (io.questdb.cairo.sql.RecordCursor)2 SqlExecutionInterruptor (io.questdb.griffin.SqlExecutionInterruptor)2 EmptyTableRandomRecordCursor (io.questdb.griffin.engine.EmptyTableRandomRecordCursor)2 GroupByFunction (io.questdb.griffin.engine.functions.GroupByFunction)2 Function (io.questdb.cairo.sql.Function)1 Record (io.questdb.cairo.sql.Record)1 EmptyTableNoSizeRecordCursor (io.questdb.griffin.engine.EmptyTableNoSizeRecordCursor)1