Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockSize - a new config paramter for max size of the block #272

Merged
merged 6 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions client/src/main/java/zingg/client/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.module.scala.DefaultScalaModule;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -106,6 +105,7 @@ public class Arguments implements Serializable {
boolean collectMetrics = true;
boolean showConcise = false;
float stopWordsCutoff = 0.1f;
long blockSize = 100L;

private static final String ENV_VAR_MARKER_START = "$";
private static final String ENV_VAR_MARKER_END = "$";
Expand Down Expand Up @@ -626,7 +626,15 @@ public boolean getShowConcise() {
public void setShowConcise(boolean showConcise) {
this.showConcise = showConcise;
}


public long getBlockSize() {
return blockSize;
}

public void setBlockSize(long blockSize){
this.blockSize = blockSize;
}

public String[] getPipeNames() {
Pipe[] input = this.getData();
String[] sourceNames = new String[input.length];
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/zingg/util/BlockingTreeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Tree<Canopy> createBlockingTree(Dataset<Row> testData,
LOG.debug("Learning blocking rules for sample count " + totalCount
+ " and pos " + positives.count() + " and testData count " + testData.count());
}
if (blockSize == -1) blockSize = Heuristics.getMaxBlockSize(totalCount);
if (blockSize == -1) blockSize = Heuristics.getMaxBlockSize(totalCount, args.getBlockSize());
LOG.info("Learning indexing rules for block size " + blockSize);

positives = positives.coalesce(1);
Expand Down
14 changes: 6 additions & 8 deletions core/src/main/java/zingg/util/Heuristics.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import zingg.block.Block;

public class Heuristics {

public static final Log LOG = LogFactory.getLog(Heuristics.class);

public static long getMaxBlockSize(long totalCount) {
long maxSize = 8;
public static final long MIN_SIZE = 8L;
public static long getMaxBlockSize(long totalCount, long blockSizeFromConfig) {
long maxSize = MIN_SIZE;
/*if (totalCount > 100 && totalCount < 500){
maxSize = totalCount / 5;
}
else {*/
maxSize = (long) (0.001 * totalCount);
LOG.debug("**Block size found **" + maxSize);
if (maxSize > 100) maxSize = 100;
if (maxSize <= 8) maxSize = 8;
LOG.debug("**Block size found **");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please print max size here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored

if (maxSize > blockSizeFromConfig) maxSize = blockSizeFromConfig;
if (maxSize <= MIN_SIZE) maxSize = MIN_SIZE;
//}
LOG.info("**Block size **" + maxSize + " and total count was " + totalCount);
LOG.info("Heuristics suggest " + maxSize);
Expand Down
34 changes: 34 additions & 0 deletions core/src/test/java/zingg/util/TestHeuristics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package zingg.util;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class TestHeuristics {
long blockSizeConfigured = 50L;

@Test
public void testMaxBlockSizeWhenCalculatedValueIsMoreThanConfigValue() throws Throwable {
long size = Heuristics.getMaxBlockSize(70000, blockSizeConfigured);
assertEquals(size, 50);
}

@Test
public void testMaxBlockSizeWhenCalculatedValueIsLessThanConfigValueButMoreThanMinValue() throws Throwable {
long size = Heuristics.getMaxBlockSize(25000, blockSizeConfigured);
assertEquals(size, 25);
}

@Test
public void testMaxBlockSizeWhenCalculatedValueIsLessThanMinValue() throws Throwable {
long size = Heuristics.getMaxBlockSize(5000, blockSizeConfigured);
assertEquals(size, Heuristics.MIN_SIZE);
}

@Test
public void testMaxBlockSizeWhenConfigValueItselfIsLessThanMinValue() throws Throwable {
long blockSizeConfigured = 5L;
long size = Heuristics.getMaxBlockSize(25000, blockSizeConfigured);
assertEquals(size, Heuristics.MIN_SIZE);
}
}