Search in sources :

Example 41 with IgniteTypeFactory

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());
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.jupiter.api.Test)

Example 42 with IgniteTypeFactory

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();
        }
    }
}
Also used : ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) RelDataType(org.apache.calcite.rel.type.RelDataType) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) Commons(org.apache.ignite.internal.sql.engine.util.Commons) Collections.singletonList(java.util.Collections.singletonList) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NotNull(org.jetbrains.annotations.NotNull) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) NotNull(org.jetbrains.annotations.NotNull) Iterator(java.util.Iterator) Test(org.junit.jupiter.api.Test)

Example 43 with IgniteTypeFactory

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);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) Mappings(org.apache.calcite.util.mapping.Mappings) IndexConditions(org.apache.ignite.internal.sql.engine.util.IndexConditions) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)

Example 44 with IgniteTypeFactory

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();
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) GroupKey(org.apache.ignite.internal.sql.engine.exec.exp.agg.GroupKey)

Example 45 with IgniteTypeFactory

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);
}
Also used : SqlUpdate(org.apache.calcite.sql.SqlUpdate) ArrayUtils.nullOrEmpty(org.apache.ignite.internal.util.ArrayUtils.nullOrEmpty) SqlInsert(org.apache.calcite.sql.SqlInsert) SqlDelete(org.apache.calcite.sql.SqlDelete) SqlValidatorScope(org.apache.calcite.sql.validate.SqlValidatorScope) RESOURCE(org.apache.calcite.util.Static.RESOURCE) RelOptTable(org.apache.calcite.plan.RelOptTable) BigDecimal(java.math.BigDecimal) SqlCall(org.apache.calcite.sql.SqlCall) SqlLiteral(org.apache.calcite.sql.SqlLiteral) SqlNode(org.apache.calcite.sql.SqlNode) SqlValidatorUtil(org.apache.calcite.sql.validate.SqlValidatorUtil) SqlUtil(org.apache.calcite.sql.SqlUtil) SqlValidatorNamespace(org.apache.calcite.sql.validate.SqlValidatorNamespace) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlValidator(org.apache.calcite.sql.validate.SqlValidator) CalciteSqlDialect(org.apache.calcite.sql.dialect.CalciteSqlDialect) SqlSelect(org.apache.calcite.sql.SqlSelect) EnumSet(java.util.EnumSet) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) TableDescriptor(org.apache.ignite.internal.sql.engine.schema.TableDescriptor) IgniteResource(org.apache.ignite.internal.sql.engine.util.IgniteResource) SqlKind(org.apache.calcite.sql.SqlKind) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) CalciteCatalogReader(org.apache.calcite.prepare.CalciteCatalogReader) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Set(java.util.Set) Prepare(org.apache.calcite.prepare.Prepare) Nullable(org.jetbrains.annotations.Nullable) IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlDynamicParam(org.apache.calcite.sql.SqlDynamicParam) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction) SqlValidatorImpl(org.apache.calcite.sql.validate.SqlValidatorImpl) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) Collections(java.util.Collections) SqlNodeList(org.apache.calcite.sql.SqlNodeList) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) SqlSelect(org.apache.calcite.sql.SqlSelect) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)80 Test (org.junit.jupiter.api.Test)48 RelDataType (org.apache.calcite.rel.type.RelDataType)47 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)27 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)22 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)21 AggregateCall (org.apache.calcite.rel.core.AggregateCall)19 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 RexNode (org.apache.calcite.rex.RexNode)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 ArrayList (java.util.ArrayList)10 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)8 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)7 List (java.util.List)6 MappingQueryContext (org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext)6 MultiStepPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan)6 MultiStepQueryPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan)6 QueryTemplate (org.apache.ignite.internal.sql.engine.prepare.QueryTemplate)6