-
Notifications
You must be signed in to change notification settings - Fork 124
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
More blocking functions #292
Merged
sonalgoyal
merged 5 commits into
zinggAI:main
from
navinrathore:MoreBlockingFunctions261
May 26, 2022
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc5c7ee
Blocking functions to truncate Double to 1,2,3 decimal places
navinrathore 4bd0229
Blocking functions for less than zero (int, double)
navinrathore 8ed3e5b
Blocking functions for trimming last 1,2,3 digits (int, double)
navinrathore 3283cd3
Blocking functions for ranges 10-100-1000-10000 (int,double)
navinrathore 2946eb4
Split and Moved testcases into their separate classes
navinrathore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package zingg.hash; | ||
|
||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.api.java.UDF1; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
public class LessThanZeroDbl extends HashFunction implements UDF1<Double, Boolean> { | ||
public LessThanZeroDbl() { | ||
super("lessThanZeroDbl", DataTypes.DoubleType, DataTypes.BooleanType, true); | ||
} | ||
|
||
@Override | ||
public Boolean call(Double field) { | ||
Boolean r = false; | ||
if (field != null) { | ||
r = field < 0 ? true : false; | ||
} | ||
return r; | ||
} | ||
|
||
public Object apply(Row ds, String column) { | ||
return call((Double) ds.getAs(column)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package zingg.hash; | ||
|
||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.api.java.UDF1; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
public class LessThanZeroInt extends HashFunction implements UDF1<Integer, Boolean> { | ||
public LessThanZeroInt() { | ||
super("lessThanZeroInt", DataTypes.IntegerType, DataTypes.BooleanType, true); | ||
} | ||
|
||
@Override | ||
public Boolean call(Integer field) { | ||
Boolean r = false; | ||
if (field != null) { | ||
r = field < 0 ? true : false; | ||
} | ||
return r; | ||
} | ||
|
||
public Object apply(Row ds, String column) { | ||
return call((Integer) ds.getAs(column)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween0And10Dbl extends RangeDbl { | ||
|
||
public RangeBetween0And10Dbl() { | ||
super(0, 10); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween0And10Int extends RangeInt { | ||
|
||
public RangeBetween0And10Int() { | ||
super(0, 10); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/java/zingg/hash/RangeBetween1000And10000Dbl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween1000And10000Dbl extends RangeDbl { | ||
|
||
public RangeBetween1000And10000Dbl() { | ||
super(1000, 10000); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/java/zingg/hash/RangeBetween1000And10000Int.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween1000And10000Int extends RangeInt { | ||
|
||
public RangeBetween1000And10000Int() { | ||
super(1000, 10000); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween100And1000Dbl extends RangeDbl { | ||
|
||
public RangeBetween100And1000Dbl() { | ||
super(100, 1000); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween100And1000Int extends RangeInt { | ||
|
||
public RangeBetween100And1000Int() { | ||
super(100, 1000); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween10And100Dbl extends RangeDbl { | ||
|
||
public RangeBetween10And100Dbl() { | ||
super(10, 100); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class RangeBetween10And100Int extends RangeInt { | ||
|
||
public RangeBetween10And100Int() { | ||
super(10, 100); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zingg.hash; | ||
|
||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.api.java.UDF1; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
public class RangeDbl extends HashFunction implements UDF1<Double, Integer> { | ||
int lowerLimit; | ||
int upperLimit; | ||
|
||
public RangeDbl(int lower, int upper) { | ||
super("rangeBetween" + lower + "And" + upper + "Dbl", DataTypes.DoubleType, DataTypes.IntegerType, true); | ||
this.lowerLimit = lower; | ||
this.upperLimit = upper; | ||
} | ||
|
||
@Override | ||
public Integer call(Double field) { | ||
int withinRange = 0; | ||
if (field >= lowerLimit && field < upperLimit) { | ||
withinRange = 1; | ||
} | ||
return withinRange; | ||
} | ||
|
||
public Object apply(Row ds, String column) { | ||
return call((Double) ds.getAs(column)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zingg.hash; | ||
|
||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.api.java.UDF1; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
public class RangeInt extends HashFunction implements UDF1<Integer, Integer> { | ||
int lowerLimit; | ||
int upperLimit; | ||
|
||
public RangeInt(int lower, int upper) { | ||
super("rangeBetween" + lower + "And" + upper + "Int", DataTypes.IntegerType, DataTypes.IntegerType, true); | ||
this.lowerLimit = lower; | ||
this.upperLimit = upper; | ||
} | ||
|
||
@Override | ||
public Integer call(Integer field) { | ||
int withinRange = 0; | ||
if (field >= lowerLimit && field < upperLimit) { | ||
withinRange = 1; | ||
} | ||
return withinRange; | ||
} | ||
|
||
public Object apply(Row ds, String column) { | ||
return call((Integer) ds.getAs(column)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TrimLast1DigitDbl extends TrimLastDigitsDbl { | ||
|
||
public TrimLast1DigitDbl() { | ||
super(1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TrimLast1DigitInt extends TrimLastDigitsInt { | ||
|
||
public TrimLast1DigitInt() { | ||
super(1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TrimLast2DigitsDbl extends TrimLastDigitsDbl { | ||
|
||
public TrimLast2DigitsDbl() { | ||
super(2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TrimLast2DigitsInt extends TrimLastDigitsInt { | ||
|
||
public TrimLast2DigitsInt() { | ||
super(2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TrimLast3DigitsDbl extends TrimLastDigitsDbl { | ||
|
||
public TrimLast3DigitsDbl() { | ||
super(3); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TrimLast3DigitsInt extends TrimLastDigitsInt { | ||
|
||
public TrimLast3DigitsInt() { | ||
super(3); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zingg.hash; | ||
|
||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.api.java.UDF1; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
public class TrimLastDigitsDbl extends HashFunction implements UDF1<Double, Double> { | ||
int numDigits; | ||
static final int[] POWERS_OF_10 = {1, 10, 100, 1000, 10000, 100000}; | ||
public TrimLastDigitsDbl(int count) { | ||
super("trimLast" + count + "DigitsDbl", DataTypes.DoubleType, DataTypes.DoubleType, true); | ||
this.numDigits = count; | ||
} | ||
|
||
@Override | ||
public Double call(Double field) { | ||
Double r = null; | ||
if (field == null) { | ||
r = field; | ||
} else { | ||
r = Math.floor(field / POWERS_OF_10[numDigits]); | ||
} | ||
return r; | ||
} | ||
|
||
public Object apply(Row ds, String column) { | ||
return call((Double) ds.getAs(column)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zingg.hash; | ||
|
||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.api.java.UDF1; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
public class TrimLastDigitsInt extends HashFunction implements UDF1<Integer, Integer> { | ||
int numDigits; | ||
static final int[] POWERS_OF_10 = {1, 10, 100, 1000, 10000, 100000}; | ||
public TrimLastDigitsInt(int count) { | ||
super("trimLast" + count + "DigitsInt", DataTypes.IntegerType, DataTypes.IntegerType, true); | ||
this.numDigits = count; | ||
} | ||
|
||
@Override | ||
public Integer call(Integer field) { | ||
Integer r = null; | ||
if (field == null) { | ||
r = field; | ||
} else { | ||
r = field / POWERS_OF_10[numDigits]; | ||
} | ||
return r; | ||
} | ||
|
||
public Object apply(Row ds, String column) { | ||
return call((Integer) ds.getAs(column)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package zingg.hash; | ||
|
||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.api.java.UDF1; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
public class TruncateDouble extends HashFunction implements UDF1<Double, Double> { | ||
int numDecimalPlaces; | ||
static final int[] POWERS_OF_10 = {1, 10, 100, 1000, 10000, 100000}; | ||
public TruncateDouble(int numDecimalPlaces) { | ||
super("truncateDoubleTo" + numDecimalPlaces + "Places", DataTypes.DoubleType, DataTypes.DoubleType, true); | ||
this.numDecimalPlaces = numDecimalPlaces; | ||
} | ||
|
||
@Override | ||
public Double call(Double field) { | ||
Double r = null; | ||
if (field == null) { | ||
r = field; | ||
} else { | ||
r = Math.floor(field * POWERS_OF_10[numDecimalPlaces]) / POWERS_OF_10[numDecimalPlaces]; | ||
} | ||
return r; | ||
} | ||
|
||
@Override | ||
public Object apply(Row ds, String column) { | ||
return call((Double) ds.getAs(column)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TruncateDoubleTo1Place extends TruncateDouble { | ||
|
||
public TruncateDoubleTo1Place() { | ||
super(1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.hash; | ||
|
||
public class TruncateDoubleTo2Places extends TruncateDouble { | ||
|
||
public TruncateDoubleTo2Places() { | ||
super(2); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use this? just say 10 exp the argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pow() seems a relatively expansive operation.
https://stackoverflow.com/questions/46983772/fastest-way-to-obtain-a-power-of-10