Search in sources :

Example 16 with MapValue

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

the class HashJoinLightRecordCursorFactory method buildMapOfSlaveRecords.

private void buildMapOfSlaveRecords(RecordCursor slaveCursor, SqlExecutionInterruptor interruptor) {
    slaveChain.clear();
    joinKeyMap.clear();
    final Record record = slaveCursor.getRecord();
    while (slaveCursor.hasNext()) {
        interruptor.checkInterrupted();
        MapKey key = joinKeyMap.withKey();
        key.put(record, slaveKeySink);
        MapValue value = key.createValue();
        if (value.isNew()) {
            final long offset = slaveChain.put(record.getRowId(), -1);
            value.putLong(0, offset);
            value.putLong(1, offset);
        } else {
            value.putLong(1, slaveChain.put(record.getRowId(), value.getLong(1)));
        }
    }
}
Also used : MapKey(io.questdb.cairo.map.MapKey) MapValue(io.questdb.cairo.map.MapValue)

Example 17 with MapValue

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

the class HashOuterJoinLightRecordCursorFactory method buildMapOfSlaveRecords.

private void buildMapOfSlaveRecords(RecordCursor slaveCursor, SqlExecutionInterruptor interruptor) {
    slaveChain.clear();
    joinKeyMap.clear();
    final Record record = slaveCursor.getRecord();
    while (slaveCursor.hasNext()) {
        interruptor.checkInterrupted();
        MapKey key = joinKeyMap.withKey();
        key.put(record, slaveKeySink);
        MapValue value = key.createValue();
        if (value.isNew()) {
            final long offset = slaveChain.put(record.getRowId(), -1);
            value.putLong(0, offset);
            value.putLong(1, offset);
        } else {
            value.putLong(1, slaveChain.put(record.getRowId(), value.getLong(1)));
        }
    }
}
Also used : MapKey(io.questdb.cairo.map.MapKey) MapValue(io.questdb.cairo.map.MapValue)

Example 18 with MapValue

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

the class HaversineDistDegreeGroupByFunction method interpolateBoundary.

@Override
public void interpolateBoundary(MapValue value1, MapValue value2, long boundaryTimestamp, boolean isEndOfBoundary) {
    double distance = calculateHaversineDistance(value1, value2);
    // interpolate
    long ts1 = getLastTimestamp(value1);
    long ts2 = getFirstTimestamp(value2);
    long boundaryLength = isEndOfBoundary ? boundaryTimestamp - ts1 : ts2 - boundaryTimestamp;
    double interpolatedBoundaryDistance = (boundaryLength * distance) / (ts2 - ts1);
    // save
    MapValue result = isEndOfBoundary ? value1 : value2;
    saveDistance(interpolatedBoundaryDistance, result, getDistance(result));
}
Also used : MapValue(io.questdb.cairo.map.MapValue)

Example 19 with MapValue

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

the class AbstractSampleByFillValueRecordCursor method toTop.

@Override
public void toTop() {
    super.toTop();
    if (base.hasNext()) {
        baseRecord = base.getRecord();
        int n = groupByFunctions.size();
        RecordCursor mapCursor = map.getCursor();
        MapRecord mapRecord = map.getRecord();
        while (mapCursor.hasNext()) {
            MapValue value = mapRecord.getValue();
            // 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);
            }
        }
    }
}
Also used : MapRecord(io.questdb.cairo.map.MapRecord) RecordCursor(io.questdb.cairo.sql.RecordCursor) MapValue(io.questdb.cairo.map.MapValue)

Example 20 with MapValue

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

the class SampleByFillPrevRecordCursor method hasNext.

@Override
public boolean hasNext() {
    // 
    if (mapCursor.hasNext()) {
        // next() will return record that uses current map position
        return true;
    }
    if (baseRecord == null) {
        return false;
    }
    // the next sample epoch could be different from current sample epoch due to DST transition,
    // e.g. clock going backward
    // we need to ensure we do not fill time transition
    final 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
        map.getCursor().hasNext();
        return true;
    }
    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 this.map.getCursor().hasNext();
    }
}
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