use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class HashAggregateSingleGroupExecutionTest method mapReduceMin.
@Test
public void mapReduceMin() {
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Arrays.asList(row("Igor", 200), row("Roman", 300), row("Ivan", 1400), row("Alexey", 1000)));
AggregateCall call = AggregateCall.create(SqlStdOperatorTable.MIN, false, false, false, ImmutableIntList.of(1), -1, RelCollations.EMPTY, tf.createJavaType(int.class), null);
List<ImmutableBitSet> grpSets = List.of(ImmutableBitSet.of());
RelDataType mapType = IgniteMapHashAggregate.rowType(tf, true);
HashAggregateNode<Object[]> map = new HashAggregateNode<>(ctx, mapType, MAP, grpSets, accFactory(ctx, call, MAP, rowType), rowFactory());
map.register(scan);
RelDataType reduceType = TypeUtils.createRowType(tf, int.class);
HashAggregateNode<Object[]> reduce = new HashAggregateNode<>(ctx, reduceType, REDUCE, grpSets, accFactory(ctx, call, REDUCE, null), rowFactory());
reduce.register(map);
RootNode<Object[]> root = new RootNode<>(ctx, reduceType);
root.register(reduce);
assertTrue(root.hasNext());
assertEquals(200, root.next()[0]);
assertFalse(root.hasNext());
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class HashIndexSpoolExecutionTest method testIndexSpool.
@Test
public void testIndexSpool() {
ExecutionContext<Object[]> ctx = executionContext(true);
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, int.class, String.class, int.class);
int inBufSize = Commons.IN_BUFFER_SIZE;
int[] sizes = { 1, inBufSize / 2 - 1, inBufSize / 2, inBufSize / 2 + 1, inBufSize, inBufSize + 1, inBufSize * 4 };
int[] eqCnts = { 1, 10 };
for (int size : sizes) {
for (int eqCnt : eqCnts) {
TestParams[] params;
if (size == 1) {
params = new TestParams[] { new TestParams(null, new Object[] { 0, null, null }, eqCnt) };
} else {
params = new TestParams[] { new TestParams(null, new Object[] { size / 2, null, null }, eqCnt), new TestParams(null, new Object[] { size / 2 + 1, null, null }, eqCnt), new TestParams(r -> ((int) r[2]) == 0, new Object[] { size / 2 + 1, null, null }, 1) };
}
log.info("Check: size=" + size);
ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, new TestTable(size * eqCnt, rowType, (rowId) -> rowId / eqCnt, (rowId) -> "val_" + (rowId % eqCnt), (rowId) -> rowId % eqCnt) {
boolean first = true;
@Override
@NotNull
public Iterator<Object[]> iterator() {
assertTrue(first, "Rewind right");
first = false;
return super.iterator();
}
});
Object[] searchRow = new Object[3];
TestPredicate testFilter = new TestPredicate();
IndexSpoolNode<Object[]> spool = IndexSpoolNode.createHashSpool(ctx, rowType, ImmutableBitSet.of(0), testFilter, () -> searchRow);
spool.register(singletonList(scan));
RootRewindable<Object[]> root = new RootRewindable<>(ctx, rowType);
root.register(spool);
for (TestParams param : params) {
log.info("Check: param=" + param);
// Set up bounds
testFilter.delegate = param.pred;
System.arraycopy(param.bounds, 0, searchRow, 0, searchRow.length);
int cnt = 0;
while (root.hasNext()) {
root.next();
cnt++;
}
assertEquals(param.expectedResultSize, cnt, "Invalid result size");
root.rewind();
}
root.closeRewindableRoot();
}
}
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class IgniteLogicalIndexScan method create.
/**
* Creates a IgniteLogicalIndexScan.
*/
public static IgniteLogicalIndexScan create(RelOptCluster cluster, RelTraitSet traits, RelOptTable table, String idxName, @Nullable List<RexNode> proj, @Nullable RexNode cond, @Nullable ImmutableBitSet requiredColumns) {
InternalIgniteTable tbl = table.unwrap(InternalIgniteTable.class);
IgniteTypeFactory typeFactory = Commons.typeFactory(cluster);
RelCollation collation = tbl.getIndex(idxName).collation();
if (requiredColumns != null) {
Mappings.TargetMapping targetMapping = Commons.mapping(requiredColumns, tbl.getRowType(typeFactory).getFieldCount());
collation = collation.apply(targetMapping);
}
IndexConditions idxCond = new IndexConditions();
if (collation != null && !collation.getFieldCollations().isEmpty()) {
idxCond = RexUtils.buildSortedIndexConditions(cluster, collation, cond, tbl.getRowType(typeFactory), requiredColumns);
}
return new IgniteLogicalIndexScan(cluster, traits, table, idxName, proj, cond, idxCond, requiredColumns);
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class IgniteMapSetOp method buildRowType.
/**
* Build RowType for MAP node.
*/
public default RelDataType buildRowType() {
RelDataTypeFactory typeFactory = Commons.typeFactory(getCluster());
assert typeFactory instanceof IgniteTypeFactory;
RelDataTypeFactory.Builder builder = new RelDataTypeFactory.Builder(typeFactory);
builder.add("GROUP_KEY", typeFactory.createJavaType(GroupKey.class));
builder.add("COUNTERS", typeFactory.createJavaType(int[].class));
return builder.build();
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class IgniteSqlValidator method createSourceSelectForDelete.
/**
* {@inheritDoc}
*/
@Override
protected SqlSelect createSourceSelectForDelete(SqlDelete call) {
final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
final SqlValidatorTable table = getCatalogReader().getTable(((SqlIdentifier) call.getTargetTable()).names);
table.unwrap(IgniteTable.class).descriptor().deleteRowType((IgniteTypeFactory) typeFactory).getFieldNames().stream().map(name -> new SqlIdentifier(name, SqlParserPos.ZERO)).forEach(selectList::add);
SqlNode sourceTable = call.getTargetTable();
if (call.getAlias() != null) {
sourceTable = SqlValidatorUtil.addAlias(sourceTable, call.getAlias().getSimple());
}
return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, call.getCondition(), null, null, null, null, null, null, null);
}
Aggregations