use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class TupleMarshallerImpl method toInternalTuple.
/**
* Analyze tuple and wrap into internal tuple.
*
* @param schema Schema.
* @param tuple Key or value tuple.
* @param keyFlag If {@code true} marshal key columns, otherwise marshall value columns.
* @return Internal tuple.
* @throws SchemaMismatchException If tuple doesn't match the schema.
*/
@NotNull
private InternalTuple toInternalTuple(SchemaDescriptor schema, Tuple tuple, boolean keyFlag) throws SchemaMismatchException {
if (tuple == null) {
return InternalTuple.NO_VALUE;
}
Columns columns = keyFlag ? schema.keyColumns() : schema.valueColumns();
int nonNullVarlen = 0;
int nonNullVarlenSize = 0;
int knownColumns = 0;
Map<String, Object> defaults = new HashMap<>();
if (tuple instanceof SchemaAware && Objects.equals(((SchemaAware) tuple).schema(), schema)) {
for (int i = 0, len = columns.length(); i < len; i++) {
final Column col = columns.column(i);
Object val = tuple.valueOrDefault(col.name(), POISON_OBJECT);
assert val != POISON_OBJECT;
if (val == null || columns.firstVarlengthColumn() < i) {
continue;
}
nonNullVarlenSize += getValueSize(val, col.type());
nonNullVarlen++;
}
} else {
for (int i = 0, len = columns.length(); i < len; i++) {
final Column col = columns.column(i);
Object val = tuple.valueOrDefault(col.name(), POISON_OBJECT);
if (val == POISON_OBJECT) {
if (keyFlag) {
throw new SchemaMismatchException("Missed key column: " + col.name());
}
val = col.defaultValue();
defaults.put(col.name(), val);
} else {
knownColumns++;
}
col.validate(val);
if (val == null || columns.isFixedSize(i)) {
continue;
}
nonNullVarlenSize += getValueSize(val, col.type());
nonNullVarlen++;
}
}
return new InternalTuple(tuple, nonNullVarlen, nonNullVarlenSize, defaults, knownColumns);
}
use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class AsmMarshallerGenerator method generateAssemblerFactoryMethod.
/**
* Generates helper method.
*
* @param classDef Marshaller class definition.
* @param schema Schema descriptor.
* @param keyMarsh Key marshaller code generator.
* @param valMarsh Value marshaller code generator.
*/
private void generateAssemblerFactoryMethod(ClassDefinition classDef, SchemaDescriptor schema, MarshallerCodeGenerator keyMarsh, MarshallerCodeGenerator valMarsh) {
final MethodDefinition methodDef = classDef.declareMethod(EnumSet.of(Access.PRIVATE), "createAssembler", ParameterizedType.type(RowAssembler.class), Parameter.arg("key", Object.class), Parameter.arg("val", Object.class));
final Scope scope = methodDef.getScope();
final BytecodeBlock body = methodDef.getBody();
final Variable varlenKeyCols = scope.declareVariable("varlenKeyCols", body, BytecodeExpressions.defaultValue(int.class));
final Variable varlenValueCols = scope.declareVariable("varlenValueCols", body, BytecodeExpressions.defaultValue(int.class));
final Variable keyCols = scope.declareVariable(Columns.class, "keyCols");
final Variable valCols = scope.declareVariable(Columns.class, "valCols");
body.append(keyCols.set(methodDef.getThis().getField("schema", SchemaDescriptor.class).invoke("keyColumns", Columns.class)));
body.append(valCols.set(methodDef.getThis().getField("schema", SchemaDescriptor.class).invoke("valueColumns", Columns.class)));
Columns columns = schema.keyColumns();
if (columns.hasVarlengthColumns()) {
final Variable tmp = scope.createTempVariable(Object.class);
for (int i = columns.firstVarlengthColumn(); i < columns.length(); i++) {
assert !columns.column(i).type().spec().fixedLength();
body.append(keyMarsh.getValue(classDef.getType(), scope.getVariable("key"), i)).putVariable(tmp);
body.append(new IfStatement().condition(BytecodeExpressions.isNotNull(tmp)).ifTrue(new BytecodeBlock().append(varlenKeyCols.increment())));
}
}
columns = schema.valueColumns();
if (columns.hasVarlengthColumns()) {
final Variable tmp = scope.createTempVariable(Object.class);
for (int i = columns.firstVarlengthColumn(); i < columns.length(); i++) {
assert !columns.column(i).type().spec().fixedLength();
body.append(valMarsh.getValue(classDef.getType(), scope.getVariable("val"), i)).putVariable(tmp);
body.append(new IfStatement().condition(BytecodeExpressions.isNotNull(tmp)).ifTrue(new BytecodeBlock().append(varlenValueCols.increment())));
}
}
body.append(BytecodeExpressions.newInstance(RowAssembler.class, methodDef.getThis().getField("schema", SchemaDescriptor.class), varlenKeyCols, varlenValueCols));
body.retObject();
}
use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class TupleMarshallerFixlenOnlyBenchmark method measureTupleBuildAndMarshallerCost.
/**
* Measure tuple build then marshall.
*
* @param bh Black hole.
*/
@Benchmark
public void measureTupleBuildAndMarshallerCost(Blackhole bh) throws TupleMarshallerException {
final Columns cols = schema.valueColumns();
final Tuple valBld = Tuple.create(cols.length());
for (int i = 0; i < cols.length(); i++) {
valBld.set(cols.column(i).name(), vals[i]);
}
Tuple keyTuple = Tuple.create(1).set("key", rnd.nextLong());
final Row row = marshaller.marshal(keyTuple, valBld);
bh.consume(row);
}
use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class TupleMarshallerVarlenOnlyBenchmark method measureTupleBuildAndMarshallerCost.
/**
* Measure tuple build then marshall.
*
* @param bh Black hole.
*/
@Benchmark
public void measureTupleBuildAndMarshallerCost(Blackhole bh) throws TupleMarshallerException {
final Columns cols = schema.valueColumns();
final Tuple valBld = Tuple.create(cols.length());
for (int i = 0; i < cols.length(); i++) {
valBld.set(cols.column(i).name(), val);
}
Tuple keyTuple = Tuple.create(1).set("key", rnd.nextLong());
final Row row = marshaller.marshal(keyTuple, valBld);
bh.consume(row);
}
use of org.apache.ignite.internal.schema.Columns in project ignite-3 by apache.
the class TupleMarshallerImpl method buildRow.
/**
* Marshal tuple to a row.
*
* @param schema Schema.
* @param keyTuple0 Internal key tuple.
* @param valTuple0 Internal value tuple.
* @return Row.
* @throws SchemaMismatchException If failed to write tuple column.
*/
@NotNull
private Row buildRow(SchemaDescriptor schema, InternalTuple keyTuple0, InternalTuple valTuple0) throws SchemaMismatchException {
RowAssembler rowBuilder = createAssembler(schema, keyTuple0, valTuple0);
Columns columns = schema.keyColumns();
for (int i = 0, len = columns.length(); i < len; i++) {
final Column col = columns.column(i);
writeColumn(rowBuilder, col, keyTuple0);
}
if (valTuple0.tuple != null) {
columns = schema.valueColumns();
for (int i = 0, len = columns.length(); i < len; i++) {
final Column col = columns.column(i);
writeColumn(rowBuilder, col, valTuple0);
}
}
return new Row(schema, rowBuilder.build());
}
Aggregations