Skip to content

Commit

Permalink
IGNITE-14823 Count abbrevation (#11101)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Dec 18, 2023
1 parent 8695fb0 commit 2e3ae15
Show file tree
Hide file tree
Showing 78 changed files with 398 additions and 398 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class IgniteLockExample {
/** Number of items for each producer/consumer to produce/consume. */
private static final int OPS_COUNT = 100;
private static final int OPS_CNT = 100;

/** Number of producers. */
private static final int NUM_PRODUCERS = 5;
Expand Down Expand Up @@ -101,12 +101,12 @@ public static void main(String[] args) {

IgniteCondition notDone = lock.getOrCreateCondition(SYNC_NAME);

int count = cache.get(SYNC_NAME);
int cnt = cache.get(SYNC_NAME);

while (count > 0) {
while (cnt > 0) {
notDone.await();

count = cache.get(SYNC_NAME);
cnt = cache.get(SYNC_NAME);
}
}
finally {
Expand Down Expand Up @@ -163,7 +163,7 @@ public Producer(String reentrantLockName) {

IgniteCache<String, Integer> cache = Ignition.ignite().cache(CACHE_NAME);

for (int i = 0; i < OPS_COUNT; i++) {
for (int i = 0; i < OPS_CNT; i++) {
try {
lock.lock();

Expand Down Expand Up @@ -197,11 +197,11 @@ public Producer(String reentrantLockName) {
try {
lock.lock();

int count = cache.get(SYNC_NAME);
int cnt = cache.get(SYNC_NAME);

count--;
cnt--;

cache.put(SYNC_NAME, count);
cache.put(SYNC_NAME, cnt);

// Signals the master thread.
done.signal();
Expand Down Expand Up @@ -242,7 +242,7 @@ public Consumer(String reentrantLockName) {

IgniteCache<String, Integer> cache = g.cache(CACHE_NAME);

for (int i = 0; i < OPS_COUNT; i++) {
for (int i = 0; i < OPS_CNT; i++) {
try {
lock.lock();

Expand Down Expand Up @@ -276,11 +276,11 @@ public Consumer(String reentrantLockName) {
try {
lock.lock();

int count = cache.get(SYNC_NAME);
int cnt = cache.get(SYNC_NAME);

count--;
cnt--;

cache.put(SYNC_NAME, count);
cache.put(SYNC_NAME, cnt);

// Signals the master thread.
done.signal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class IgniteSemaphoreExample {
/** Number of items for each producer/consumer to produce/consume. */
private static final int OPS_COUNT = 100;
private static final int OPS_CNT = 100;

/** Synchronization semaphore name. */
private static final String SEM_NAME = IgniteSemaphoreExample.class.getSimpleName();
Expand All @@ -47,12 +47,12 @@ public class IgniteSemaphoreExample {
*/
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
int nodeCount = ignite.cluster().forServers().nodes().size();
int nodeCnt = ignite.cluster().forServers().nodes().size();

// Number of producers should be equal to number of consumers.
// This value should not exceed overall number of public thread pools in a cluster,
// otherwise blocking consumer jobs can occupy all the threads leading to starvation.
int jobCount = ignite.configuration().getPublicThreadPoolSize() * nodeCount / 2;
int jobCnt = ignite.configuration().getPublicThreadPoolSize() * nodeCnt / 2;

System.out.println();
System.out.println(">>> Cache atomic semaphore example started.");
Expand All @@ -67,17 +67,17 @@ public static void main(String[] args) {
IgniteSemaphore semaphore = ignite.semaphore(semaphoreName, 0, false, true);

// Start consumers on all cluster nodes.
for (int i = 0; i < jobCount; i++)
for (int i = 0; i < jobCnt; i++)
ignite.compute().runAsync(new Consumer(semaphoreName));

// Start producers on all cluster nodes.
for (int i = 0; i < jobCount; i++)
for (int i = 0; i < jobCnt; i++)
ignite.compute().runAsync(new Producer(semaphoreName));

System.out.println("Master node is waiting for all other nodes to finish...");

// Wait for everyone to finish.
syncSemaphore.acquire(2 * jobCount);
syncSemaphore.acquire(2 * jobCnt);
}

System.out.flush();
Expand Down Expand Up @@ -116,7 +116,7 @@ public Producer(String semaphoreName) {
@Override public void run() {
IgniteSemaphore semaphore = Ignition.ignite().semaphore(semaphoreName, 0, true, true);

for (int i = 0; i < OPS_COUNT; i++) {
for (int i = 0; i < OPS_CNT; i++) {
System.out.println("Producer [nodeId=" + Ignition.ignite().cluster().localNode().id() +
", available=" + semaphore.availablePermits() + ']');

Expand Down Expand Up @@ -149,7 +149,7 @@ public Consumer(String semaphoreName) {
@Override public void run() {
IgniteSemaphore sem = Ignition.ignite().semaphore(semaphoreName, 0, true, true);

for (int i = 0; i < OPS_COUNT; i++) {
for (int i = 0; i < OPS_CNT; i++) {
// Block if no permits are available.
sem.acquire();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1998,15 +1998,15 @@ private ParameterExpression genIsNullStatement(
/** Ensures that operands have identical type. */
private List<Expression> harmonize(final List<Expression> argValueList,
final RexToLixTranslator translator, final RexCall call) {
int nullCount = 0;
int nullCnt = 0;
final List<RelDataType> types = new ArrayList<>();
final RelDataTypeFactory typeFactory =
translator.builder.getTypeFactory();
for (RexNode operand : call.getOperands()) {
RelDataType type = operand.getType();
type = toSql(typeFactory, type);
if (translator.isNullable(operand))
++nullCount;
++nullCnt;
else
type = typeFactory.createTypeWithNullability(type, false);

Expand All @@ -2024,7 +2024,7 @@ private List<Expression> harmonize(final List<Expression> argValueList,
// to be harmonized.
return argValueList;
}
assert (nullCount > 0) == type.isNullable();
assert (nullCnt > 0) == type.isNullable();
final Type javaCls =
translator.typeFactory.getJavaClass(type);
final List<Expression> harmonizedArgValues = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ private static class LongCount<Row> extends AbstractAccumulator<Row> {

/** {@inheritDoc} */
@Override public void add(Row row) {
int argsCount = aggregateCall().getArgList().size();
int argsCnt = aggregateCall().getArgList().size();

assert argsCount == 0 || argsCount == 1;
assert argsCnt == 0 || argsCnt == 1;

if (argsCount == 0 || get(0, row) != null)
if (argsCnt == 0 || get(0, row) != null)
cnt++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class IgniteMdDistinctRowCount extends RelMdDistinctRowCount {
if (groupKey.cardinality() == 0)
return 1d;

double rowCount = mq.getRowCount(rel);
double rowCnt = mq.getRowCount(rel);

rowCount *= 1.0 - Math.pow(.5, groupKey.cardinality());
rowCnt *= 1.0 - Math.pow(.5, groupKey.cardinality());

return rowCount;
return rowCnt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ public Double getPercentageOriginalRows(Union rel, RelMetadataQuery mq) {
// case where a huge table has been completely filtered away.

for (RelNode input : rel.getInputs()) {
Double rowCount = mq.getRowCount(input);
if (rowCount == null) {
Double rowCnt = mq.getRowCount(input);
if (rowCnt == null) {
continue;
}
Double percentage = mq.getPercentageOriginalRows(input);
if (percentage == null) {
continue;
}
if (percentage != 0.0) {
denominator += rowCount / percentage;
numerator += rowCount;
denominator += rowCnt / percentage;
numerator += rowCnt;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ public class IgniteMdRowCount extends RelMdRowCount {
double leftCardinality = leftDistinct / left;
double rightCardinality = rightDistinct / right;

double rowsCount = (Math.min(left, right) / (leftCardinality * rightCardinality)) * selectivity;
double rowsCnt = (Math.min(left, right) / (leftCardinality * rightCardinality)) * selectivity;

JoinRelType type = rel.getJoinType();

if (type == JoinRelType.LEFT)
rowsCount += left;
rowsCnt += left;
else if (type == JoinRelType.RIGHT)
rowsCount += right;
rowsCnt += right;
else if (type == JoinRelType.FULL)
rowsCount += left + right;
rowsCnt += left + right;

return rowsCount;
return rowsCnt;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ else if (joinType == RIGHT || joinType == JoinRelType.FULL) {

/** */
protected boolean projectsLeft(RelCollation collation) {
int leftFieldCount = getLeft().getRowType().getFieldCount();
int leftFieldCnt = getLeft().getRowType().getFieldCount();
for (int field : RelCollations.ordinals(collation)) {
if (field >= leftFieldCount)
if (field >= leftFieldCnt)
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,17 @@ public IgniteCorrelatedNestedLoopJoin(RelInput input) {
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
IgniteCostFactory costFactory = (IgniteCostFactory)planner.getCostFactory();

double leftCount = mq.getRowCount(getLeft());
double leftCnt = mq.getRowCount(getLeft());

if (Double.isInfinite(leftCount))
if (Double.isInfinite(leftCnt))
return costFactory.makeInfiniteCost();

double rightCount = mq.getRowCount(getRight());
double rightCnt = mq.getRowCount(getRight());

if (Double.isInfinite(rightCount))
if (Double.isInfinite(rightCnt))
return costFactory.makeInfiniteCost();

double rows = leftCount * rightCount;
double rows = leftCnt * rightCnt;

return costFactory.makeCost(rows,
rows * (IgniteCost.ROW_COMPARISON_COST + IgniteCost.ROW_PASS_THROUGH_COST), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ public IgniteExchange(RelInput input) {

/** {@inheritDoc} */
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
double rowCount = mq.getRowCount(getInput());
double rowCnt = mq.getRowCount(getInput());
double bytesPerRow = getRowType().getFieldCount() * IgniteCost.AVERAGE_FIELD_SIZE;
double totalBytes = rowCount * bytesPerRow;
double totalBytes = rowCnt * bytesPerRow;

IgniteCostFactory costFactory = (IgniteCostFactory)planner.getCostFactory();

if (RelDistributions.BROADCAST_DISTRIBUTED.equals(distribution))
totalBytes *= IgniteCost.BROADCAST_DISTRIBUTION_PENALTY;

return costFactory.makeCost(rowCount, rowCount * IgniteCost.ROW_PASS_THROUGH_COST, 0, 0, totalBytes);
return costFactory.makeCost(rowCnt, rowCnt * IgniteCost.ROW_PASS_THROUGH_COST, 0, 0, totalBytes);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ public IgniteFilter(RelInput input) {

/** {@inheritDoc} */
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
double rowCount = mq.getRowCount(getInput());
double rowCnt = mq.getRowCount(getInput());

return planner.getCostFactory().makeCost(rowCount,
rowCount * (IgniteCost.ROW_COMPARISON_COST + IgniteCost.ROW_PASS_THROUGH_COST), 0);
return planner.getCostFactory().makeCost(rowCnt,
rowCnt * (IgniteCost.ROW_COMPARISON_COST + IgniteCost.ROW_PASS_THROUGH_COST), 0);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ else if (containsOrderless(rightCollation, joinInfo.rightKeys)) // preserve righ
if (joinType == FULL)
return defaultCollationPair(required, left, right);

int leftInputFieldCount = this.left.getRowType().getFieldCount();
int leftInputFieldCnt = this.left.getRowType().getFieldCount();

List<Integer> reqKeys = RelCollations.ordinals(collation);
List<Integer> leftKeys = joinInfo.leftKeys.toIntegerList();
List<Integer> rightKeys = joinInfo.rightKeys.incr(leftInputFieldCount).toIntegerList();
List<Integer> rightKeys = joinInfo.rightKeys.incr(leftInputFieldCnt).toIntegerList();

ImmutableBitSet reqKeySet = ImmutableBitSet.of(reqKeys);
ImmutableBitSet leftKeySet = ImmutableBitSet.of(joinInfo.leftKeys);
Expand Down Expand Up @@ -208,7 +208,7 @@ else if (containsOrderless(leftKeys, collation)) {
leftCollation = extendCollation(collation, leftKeys);
rightCollation = leftCollation.apply(buildTransposeMapping(true));
}
else if (containsOrderless(collation, leftKeys) && reqKeys.stream().allMatch(i -> i < leftInputFieldCount)) {
else if (containsOrderless(collation, leftKeys) && reqKeys.stream().allMatch(i -> i < leftInputFieldCnt)) {
if (joinType == RIGHT)
return defaultCollationPair(required, left, right);

Expand All @@ -223,15 +223,15 @@ else if (reqKeySet.equals(rightKeySet)) {
return defaultCollationPair(required, left, right);

nodeCollation = collation;
rightCollation = RelCollations.shift(collation, -leftInputFieldCount);
rightCollation = RelCollations.shift(collation, -leftInputFieldCnt);
leftCollation = rightCollation.apply(buildTransposeMapping(false));
}
else if (containsOrderless(rightKeys, collation)) {
if (joinType == LEFT)
return defaultCollationPair(required, left, right);

nodeCollation = collation;
rightCollation = RelCollations.shift(extendCollation(collation, rightKeys), -leftInputFieldCount);
rightCollation = RelCollations.shift(extendCollation(collation, rightKeys), -leftInputFieldCnt);
leftCollation = rightCollation.apply(buildTransposeMapping(false));
}
else
Expand All @@ -250,17 +250,17 @@ else if (containsOrderless(rightKeys, collation)) {
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
IgniteCostFactory costFactory = (IgniteCostFactory)planner.getCostFactory();

double leftCount = mq.getRowCount(getLeft());
double leftCnt = mq.getRowCount(getLeft());

if (Double.isInfinite(leftCount))
if (Double.isInfinite(leftCnt))
return costFactory.makeInfiniteCost();

double rightCount = mq.getRowCount(getRight());
double rightCnt = mq.getRowCount(getRight());

if (Double.isInfinite(rightCount))
if (Double.isInfinite(rightCnt))
return costFactory.makeInfiniteCost();

double rows = leftCount + rightCount;
double rows = leftCnt + rightCnt;

return costFactory.makeCost(rows,
rows * (IgniteCost.ROW_COMPARISON_COST + IgniteCost.ROW_PASS_THROUGH_COST), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ public IgniteNestedLoopJoin(RelInput input) {
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
IgniteCostFactory costFactory = (IgniteCostFactory)planner.getCostFactory();

double leftCount = mq.getRowCount(getLeft());
double leftCnt = mq.getRowCount(getLeft());

if (Double.isInfinite(leftCount))
if (Double.isInfinite(leftCnt))
return costFactory.makeInfiniteCost();

double rightCount = mq.getRowCount(getRight());
double rightCnt = mq.getRowCount(getRight());

if (Double.isInfinite(rightCount))
if (Double.isInfinite(rightCnt))
return costFactory.makeInfiniteCost();

double rows = leftCount * rightCount;
double rows = leftCnt * rightCnt;

double rightSize = rightCount * getRight().getRowType().getFieldCount() * IgniteCost.AVERAGE_FIELD_SIZE;
double rightSize = rightCnt * getRight().getRowType().getFieldCount() * IgniteCost.AVERAGE_FIELD_SIZE;

return costFactory.makeCost(rows,
rows * (IgniteCost.ROW_COMPARISON_COST + IgniteCost.ROW_PASS_THROUGH_COST), 0, rightSize, 0);
Expand Down
Loading

0 comments on commit 2e3ae15

Please sign in to comment.