Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions common/core/src/main/java/zingg/common/core/hash/IdentityDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package zingg.common.core.hash;
import java.util.Date;
import java.time.LocalDate;
public class IdentityDate extends BaseHash<Date, Integer> {

public IdentityDate() {
setName("identityDate");
}

@Override
public Integer call(Date date) {
if(date == null) {
return null;
}
int year = date.getYear() + 1900;
int month = date.getMonth() + 1;
int day = date.getDate();
return year * 10000 + month * 100 + day;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package zingg.common.core.hash;

import java.util.Date;

public class SameMonthYear extends BaseHash<Date, Integer>{
public SameMonthYear() {
setName("sameMonthYear");
}

@Override
public Integer call(Date date) {
if(date == null) {
return null;
}
int year = date.getYear() + 1900;
int month = date.getMonth() + 1;
return year * 100 + month;
}
}
28 changes: 28 additions & 0 deletions common/core/src/test/java/zingg/hash/TestIdentityDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package zingg.hash;

import org.junit.jupiter.api.Test;
import zingg.common.core.hash.IdentityDate;
import zingg.common.core.hash.IdentityInteger;

import java.util.Date;

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

public class TestIdentityDate {

@Test
public void testIdentityInteger() {
IdentityDate value = getInstance();
assertEquals(20020624, value.call(new Date("2002/06/24")));
}

@Test
public void testNullValue() {
IdentityDate value = getInstance();
assertEquals(null, value.call(null));
}

private IdentityDate getInstance() {
return new IdentityDate();
}
}
34 changes: 34 additions & 0 deletions common/core/src/test/java/zingg/hash/TestSameMonthYear.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package zingg.hash;

import java.util.Date;
import org.junit.jupiter.api.Test;
import zingg.common.core.hash.SameMonthYear;

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

public class TestSameMonthYear {
@Test
public void testSameMonthYear() {
SameMonthYear value = getInstance();
assertEquals(200206, value.call(new Date("2002/06/24")));
}

@Test
public void testSameMonthYear2() {
SameMonthYear value = getInstance();
assertEquals(value.call(new Date("2002/06/11")),
value.call(new Date("2002/06/24")));
}

@Test
public void testNullValue() {
SameMonthYear value = getInstance();
assertEquals(null, value.call(null));
}

private SameMonthYear getInstance() {
return new SameMonthYear();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package zingg.spark.core.hash;

import org.apache.spark.sql.types.DataTypes;
import zingg.common.core.hash.SameMonthYear;

import java.util.Date;

public class SparkSameMonthYear extends SparkHashFunction<Date, Integer> {
public SparkSameMonthYear() {
setBaseHash(new SameMonthYear());
setDataType(DataTypes.DateType);
setReturnType(DataTypes.IntegerType);
}
}

Loading