use of io.questdb.cairo.map.Map in project Mycat2 by MyCATApache.
the class MapFactory method createMap.
public static Map createMap(IntInnerType[] keys, InnerType[] values) {
ColumnTypes keyTypes = getKeyTypes(keys);
int[] valueTypes = Arrays.stream(values).mapToInt(i -> toQuestDbType(i)).toArray();
int MB = 1024 * 1024;
return new FastMap(16 * MB, keyTypes, new ColumnTypes() {
@Override
public int getColumnCount() {
return valueTypes.length;
}
@Override
public int getColumnType(int columnIndex) {
return valueTypes[columnIndex];
}
}, 128, 0.5, 64);
}
use of io.questdb.cairo.map.Map in project Mycat2 by MyCATApache.
the class DistinctPlan method execute.
@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
// DistinctContext distinctContext = new DistinctContext();
IntInnerType[] intPairs = getIntTypes();
Map map = MapFactory.createMap(intPairs);
RecordSink recordSink = RecordSinkFactory.INSTANCE.buildRecordSink(intPairs);
return input.execute(rootContext).flatMap(input -> {
int rowCount = input.getRowCount();
int columnCount = input.getFieldVectors().size();
VectorSchemaRoot output = rootContext.getVectorSchemaRoot(schema(), rowCount);
VectorBatchRecord record = new VectorBatchRecord(input);
int outputRowId = 0;
for (int rowId = 0; rowId < rowCount; rowId++) {
record.setPosition(rowId);
MapKey key = map.withKey();
RecordSetter recordSinkSPI = RecordSinkFactory.INSTANCE.getRecordSinkSPI(key);
recordSink.copy(record, recordSinkSPI);
if (key.create()) {
recordSink.copy(record, outputRowId, output);
outputRowId++;
// output
} else {
// skip
}
}
if (outputRowId == 0) {
output.close();
return Observable.empty();
}
output.setRowCount(outputRowId);
return Observable.fromArray(output);
}).doOnComplete(new Action() {
@Override
public void run() throws Throwable {
map.close();
}
});
}
use of io.questdb.cairo.map.Map in project Mycat2 by MyCATApache.
the class GroupByKeyPlan method execute.
@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
List<Field> fields = schema().getFields();
InnerType[] innerTypes = schema().getFields().stream().map(i -> InnerType.from(i.getType())).toArray(n -> new InnerType[n]);
Map map = MapFactory.createMap(innerTypes);
RecordSink[] recordSinks = new RecordSink[groupByKeys.length];
int groupIndex = 0;
for (GroupKeys groupByKey : groupByKeys) {
IntInnerType[] intPairs = new IntInnerType[groupByKey.getKeys().length];
int[] keys = groupByKey.getKeys();
int index = 0;
for (int key : keys) {
Field field = fields.get(key);
intPairs[index] = IntInnerType.of(index, InnerType.from(field.getType()));
index++;
}
recordSinks[groupIndex] = RecordSinkFactory.INSTANCE.buildRecordSink(intPairs);
groupIndex++;
}
return inputPlan.execute(rootContext).flatMap(new Function<VectorSchemaRoot, ObservableSource<? extends VectorSchemaRoot>>() {
@Override
public ObservableSource<? extends VectorSchemaRoot> apply(VectorSchemaRoot input) throws Throwable {
int rowCount = input.getRowCount();
VectorBatchRecord record = new VectorBatchRecord(input);
VectorSchemaRoot output = rootContext.getVectorSchemaRoot(schema, rowCount * recordSinks.length);
int outputRowId = 0;
for (int i = 0; i < recordSinks.length; i++) {
RecordSink recordSink = recordSinks[i];
for (int rowId = 0; rowId < rowCount; rowId++) {
record.setPosition(rowId);
MapKey key = map.withKey();
RecordSetter recordSinkSPI = RecordSinkFactory.INSTANCE.getRecordSinkSPI(key);
recordSink.copy(record, recordSinkSPI);
if (key.create()) {
recordSink.copy(record, outputRowId, output);
outputRowId++;
// output
} else {
// skip
}
}
}
if (outputRowId == 0) {
output.close();
return Observable.empty();
}
output.setRowCount(outputRowId);
inputPlan.eachFree(input);
return Observable.fromArray(output);
}
}).doOnComplete(new Action() {
@Override
public void run() throws Throwable {
map.close();
}
});
}
use of io.questdb.cairo.map.Map in project Mycat2 by MyCATApache.
the class GroupByKeyWithAggPlan method execute.
@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
List<Field> fields = schema().getFields();
InnerType[] innerTypes = schema().getFields().stream().map(i -> InnerType.from(i.getType())).toArray(n -> new InnerType[n]);
if (groupByKeys.length > 0) {
ColumnTypes arrayColumnTypes = RecordUtil.getArrayColumnTypes(accumulators);
Map map = MapFactory.createMap2(innerTypes, arrayColumnTypes);
RecordSink[] recordSinks = buildRecordSink(fields);
return physicalPlan.execute(rootContext).reduce(map, (mapKey, input) -> {
int rowCount = input.getRowCount();
VectorBatchRecord record = new VectorBatchRecord(input);
for (RecordSink recordSink : recordSinks) {
for (int rowId = 0; rowId < rowCount; rowId++) {
record.setPosition(rowId);
MapKey key = mapKey.withKey();
RecordSetter recordSinkSPI = RecordSinkFactory.INSTANCE.getRecordSinkSPI(key);
recordSink.copy(record, recordSinkSPI);
MapValue value = key.createValue();
if (value.isNew()) {
for (AccumulatorFunction accumulator : accumulators) {
accumulator.computeFirst(value, record);
}
} else {
for (AccumulatorFunction accumulator : accumulators) {
accumulator.computeNext(value, record);
}
}
}
}
physicalPlan.eachFree(input);
return mapKey;
}).map(map1 -> {
int size = (int) map1.size();
VectorSchemaRoot output = rootContext.getVectorSchemaRoot(schema(), size);
RecordCursor cursor = map1.getCursor();
cursor.toTop();
int index = 0;
while (cursor.hasNext()) {
Record record = cursor.getRecord();
functionSink.copy(accumulators, RecordUtil.wrapAsAggRecord(record), index++, output);
}
output.setRowCount(index);
map1.clear();
return output;
}).toObservable().doOnComplete(() -> map.close());
} else {
SimpleMapValue mapValue = new SimpleMapValue(RecordUtil.getContextSize(accumulators));
return physicalPlan.execute(rootContext).reduce(mapValue, new BiFunction<SimpleMapValue, VectorSchemaRoot, SimpleMapValue>() {
AtomicBoolean first = new AtomicBoolean(true);
@Override
public SimpleMapValue apply(SimpleMapValue simpleMapValue, VectorSchemaRoot root) throws Throwable {
int rowCount = root.getRowCount();
VectorBatchRecord record = new VectorBatchRecord(root);
if (first.compareAndSet(true, false)) {
record.setPosition(0);
for (AccumulatorFunction accumulator : accumulators) {
accumulator.computeFirst(mapValue, record);
}
for (int i = 1; i < rowCount; i++) {
record.setPosition(i);
for (AccumulatorFunction accumulator : accumulators) {
accumulator.computeNext(mapValue, record);
}
}
} else {
for (int i = 0; i < rowCount; i++) {
record.setPosition(i);
for (AccumulatorFunction accumulator : accumulators) {
accumulator.computeNext(mapValue, record);
}
}
}
root.close();
return simpleMapValue;
}
}).map(new Function<SimpleMapValue, VectorSchemaRoot>() {
@Override
public VectorSchemaRoot apply(SimpleMapValue simpleMapValue) throws Throwable {
VectorSchemaRoot vectorSchemaRoot = rootContext.getVectorSchemaRoot(schema(), 1);
vectorSchemaRoot.setRowCount(1);
functionSink.copy(accumulators, RecordUtil.wrapAsAggRecord(simpleMapValue), 0, vectorSchemaRoot);
return vectorSchemaRoot;
}
}).toObservable();
}
}
use of io.questdb.cairo.map.Map in project Mycat2 by MyCATApache.
the class MapFactory method main.
public static void main(String[] args) {
Map map = MapFactory.createMap(InnerType.STRING_TYPE);
MapKey mapKey = map.withKey();
mapKey.putInt(1);
MapValue value = mapKey.findValue();
boolean b = mapKey.notFound();
mapKey.putStr("aaa");
MapValue value1 = mapKey.createValue();
MapValue value2 = mapKey.findValue();
System.out.println();
map.close();
}
Aggregations