forked from zinggAI/zingg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
long hash functions issue zinggAI#539
- Loading branch information
1 parent
cb992e9
commit 6218fc0
Showing
10 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
common/core/src/main/java/zingg/common/core/hash/IdentityLong.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,16 @@ | ||
package zingg.common.core.hash; | ||
|
||
|
||
public class IdentityLong extends BaseHash<Long,Long>{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public IdentityLong() { | ||
setName("identityLong"); | ||
} | ||
|
||
public Long call(Long field) { | ||
return field; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
common/core/src/main/java/zingg/common/core/hash/LessThanZeroLong.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,18 @@ | ||
package zingg.common.core.hash; | ||
|
||
public class LessThanZeroLong extends BaseHash<Long,Boolean>{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public LessThanZeroLong() { | ||
setName("lessThanZeroLong"); | ||
} | ||
|
||
public Boolean call(Long field) { | ||
Boolean r = false; | ||
if (field != null) { | ||
r = field < 0 ? true : false; | ||
} | ||
return r; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
common/core/src/main/java/zingg/common/core/hash/RangeLong.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,33 @@ | ||
package zingg.common.core.hash; | ||
|
||
public class RangeLong extends BaseHash<Long,Long>{ | ||
private static final long serialVersionUID = 1L; | ||
private long lowerLimit; | ||
private long upperLimit; | ||
|
||
public RangeLong(long lower, long upper) { | ||
setName("rangeBetween" + lower + "And" + upper + "Long"); | ||
this.lowerLimit = lower; | ||
this.upperLimit = upper; | ||
} | ||
|
||
|
||
public Long call(Long field) { | ||
long withinRange = 0; | ||
if (field != null && field >= lowerLimit && field < upperLimit) { | ||
withinRange = 1; | ||
} | ||
return withinRange; | ||
} | ||
|
||
|
||
public long getLowerLimit() { | ||
return lowerLimit; | ||
} | ||
|
||
|
||
public long getUpperLimit() { | ||
return upperLimit; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
common/core/src/main/java/zingg/common/core/hash/TrimLastDigitsLong.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,30 @@ | ||
package zingg.common.core.hash; | ||
|
||
/** | ||
* Base class for hash functions related to trimming of longs | ||
* | ||
*/ | ||
public class TrimLastDigitsLong extends BaseHash<Long,Long>{ | ||
private static final long serialVersionUID = 1L; | ||
private int numDigits; | ||
static final int[] POWERS_OF_10 = {1, 10, 100, 1000, 10000, 100000}; | ||
public TrimLastDigitsLong(int count) { | ||
setName("trimLast" + count + "DigitsLong"); | ||
this.numDigits = count; | ||
} | ||
|
||
public Long call(Long field) { | ||
Long r = null; | ||
if (field == null) { | ||
r = field; | ||
} else { | ||
r = field / POWERS_OF_10[numDigits]; | ||
} | ||
return r; | ||
} | ||
|
||
public int getNumDigits() { | ||
return numDigits; | ||
} | ||
|
||
} |
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
20 changes: 20 additions & 0 deletions
20
spark/core/src/main/java/zingg/spark/core/hash/SparkIdentityLong.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,20 @@ | ||
package zingg.spark.core.hash; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
import zingg.common.core.hash.IdentityLong; | ||
|
||
public class SparkIdentityLong extends SparkHashFunction<Long, Long>{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory.getLog(SparkIdentityLong.class); | ||
|
||
public SparkIdentityLong() { | ||
setBaseHash(new IdentityLong()); | ||
setDataType(DataTypes.LongType); | ||
setReturnType(DataTypes.LongType); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
spark/core/src/main/java/zingg/spark/core/hash/SparkLessThanZeroLong.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,20 @@ | ||
package zingg.spark.core.hash; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
import zingg.common.core.hash.LessThanZeroLong; | ||
|
||
public class SparkLessThanZeroLong extends SparkHashFunction<Long, Boolean>{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory.getLog(SparkLessThanZeroLong.class); | ||
|
||
public SparkLessThanZeroLong() { | ||
setBaseHash(new LessThanZeroLong()); | ||
setDataType(DataTypes.LongType); | ||
setReturnType(DataTypes.BooleanType); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
spark/core/src/main/java/zingg/spark/core/hash/SparkRangeLong.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,20 @@ | ||
package zingg.spark.core.hash; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
import zingg.common.core.hash.RangeLong; | ||
|
||
public class SparkRangeLong extends SparkHashFunction<Long, Long>{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory.getLog(SparkRangeLong.class); | ||
|
||
public SparkRangeLong(long lower, long upper) { | ||
setBaseHash(new RangeLong(lower ,upper)); | ||
setDataType(DataTypes.LongType); | ||
setReturnType(DataTypes.LongType); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
spark/core/src/main/java/zingg/spark/core/hash/SparkTrimLastDigitsLong.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,25 @@ | ||
package zingg.spark.core.hash; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
import zingg.common.core.hash.TrimLastDigitsLong; | ||
|
||
/** | ||
* Spark specific trim function for Long | ||
* | ||
* | ||
*/ | ||
public class SparkTrimLastDigitsLong extends SparkHashFunction<Long, Long>{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory.getLog(SparkTrimLastDigitsLong.class); | ||
|
||
public SparkTrimLastDigitsLong(int count){ | ||
setBaseHash(new TrimLastDigitsLong(count)); | ||
setDataType(DataTypes.LongType); | ||
setReturnType(DataTypes.LongType); | ||
} | ||
|
||
} |