From e7c818a7a74386fe0b4d249f4f11e5bd69e8ef0f Mon Sep 17 00:00:00 2001 From: archon Date: Fri, 30 Aug 2019 17:53:15 +0800 Subject: [PATCH] 1. add array_max_count_element() and max_count_element() functions; 2. build with dependencies instead of using teradata's dependencies --- .gitignore | 8 +- .idea/compiler.xml | 13 - .idea/encodings.xml | 6 - .idea/misc.xml | 14 - .idea/vcs.xml | 6 - .idea/workspace.xml | 683 ------------------ README.md | 30 +- pom.xml | 44 +- .../archongum}/presto/UdfPlugin.java | 20 +- .../aggregate/MaxCountElementAggregation.java | 54 ++ .../presto/udf/aggregate/state/MapState.java | 14 + .../udf/aggregate/state/MapStateFactory.java | 88 +++ .../aggregate/state/MapStateSerializer.java | 52 ++ .../scalar/ArrayMaxCountElementFunction.java | 84 +++ .../presto/udf/scalar/CommonFunctions.java | 2 +- .../presto/udf/scalar/DateTimeFunctions.java | 4 +- .../presto/udf/scalar/DateTimeUtils.java | 2 +- .../META-INF/services/io.prestosql.spi.Plugin | 2 +- .../udf/aggregate/TestAggreateFunctions.java | 40 + .../udf/scalar/TestDateTimeFunctions.java} | 16 +- 20 files changed, 405 insertions(+), 777 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml rename src/main/java/com/{archon => github/archongum}/presto/UdfPlugin.java (54%) create mode 100644 src/main/java/com/github/archongum/presto/udf/aggregate/MaxCountElementAggregation.java create mode 100644 src/main/java/com/github/archongum/presto/udf/aggregate/state/MapState.java create mode 100644 src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateFactory.java create mode 100644 src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateSerializer.java create mode 100644 src/main/java/com/github/archongum/presto/udf/scalar/ArrayMaxCountElementFunction.java rename src/main/java/com/{archon => github/archongum}/presto/udf/scalar/CommonFunctions.java (89%) rename src/main/java/com/{archon => github/archongum}/presto/udf/scalar/DateTimeFunctions.java (91%) rename src/main/java/com/{archon => github/archongum}/presto/udf/scalar/DateTimeUtils.java (95%) create mode 100644 src/test/com/github/archongum/presto/udf/aggregate/TestAggreateFunctions.java rename src/test/com/{archon/presto/udf/scalar/DateTimeFunctionsTest.java => github/archongum/presto/udf/scalar/TestDateTimeFunctions.java} (73%) diff --git a/.gitignore b/.gitignore index 7d114b7..7715b75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/target/ +.idea +*.iml # Compiled class file *.class @@ -15,7 +16,6 @@ # Package Files # *.jar *.war -*.nar *.ear *.zip *.tar.gz @@ -23,3 +23,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# idea +target/ +out/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index e056590..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index c2bae49..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 4b661a5..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index ffff75a..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,683 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - mills - - - millis - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1537407300568 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No facets are configured - - - - - - - - scala-sdk-2.11.8 - - - - - - - - 11 - - - - - - - - presto-udf - - - - - - - - 1.8 - - - - - - - - Maven: com.facebook.presto:presto-spi:0.210 - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 592e6cf..2fd8904 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,23 @@ # Installation -1. `mvn package` -2. Copy `presto-udf-*.jar` to `PRESTO_HOME/plugin/teradata-functions/` in all presto nodes -(copy to this directory because it has all jars we need) -3. Restart presto +1. `mvn clean assembly:assembly` +2. Copy `presto-udf-*-jar-with-dependencies.jar` to `${PRESTO_HOME}/plugin/custom-functions/` in all presto nodes. +(create directory if not exists) +3. Restart presto cluster # Functions -| Function | Return Type | Argument Types | Description | Usage | -|-----------------------|-------------|----------------|--------------------------|---------------------------------------| -| first_day | date | date | first day of month | first_day(current_date) | -| last_day | date | date | last day of month | last_day(current_date) | -| to_datetime | timestamp | date, varchar | combine the two args | to_datetime(current_date, '23:59:59') | -| last_second | timestamp | date | last second of the date | last_second(current_date) | -| yesterday_last_second | timestamp | | last second of yesterday | yesterday_last_second() | -| yesterday | date | | yesterday | yesterday() | +## Scalar Functions +| Function | Return Type | Argument Types | Description | Usage | +| ----------------------- | ----------- | -------------- | ------------------------------------------------------------------------------------ | ------------------------------------- | +| first_day | date | date | first day of month | first_day(current_date) | +| last_day | date | date | last day of month | last_day(current_date) | +| to_datetime | timestamp | date, varchar | combine the two args | to_datetime(current_date, '23:59:59') | +| last_second | timestamp | date | last second of the date | last_second(current_date) | +| yesterday_last_second | timestamp | | last second of yesterday | yesterday_last_second() | +| yesterday | date | | yesterday | yesterday() | +| array_max_count_element | T | array(T) | Get maximum count element (null is not counting; if has multiple return one of them) | array_max_count_element(array['1']) | +## Aggregate Functions +| Function | Return Type | Argument Types | Description | Usage | +| ----------------- | ----------- | -------------- | ------------------------------------------------------------------------------------ | ----------------------- | +| max_count_element | VARCHAR | array(VARCHAR) | Get maximum count element (null is not counting; if has multiple return one of them) | max_count_element(name) | diff --git a/pom.xml b/pom.xml index e47ec80..a222700 100644 --- a/pom.xml +++ b/pom.xml @@ -4,24 +4,25 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.archon + com.github.archongum presto-udf - 2 + 3 - 305 + 318 1.8 1.8 3.8.0 - 26.0-jre + 2.9.9.3 + 5.4.2 - com.google.guava - guava - ${guava.verson} + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} @@ -32,21 +33,16 @@ - org.junit.platform - junit-platform-launcher - 1.3.1 - test + io.prestosql + presto-array + ${presto.version} + provided + org.junit.jupiter - junit-jupiter-engine - 5.3.1 - test - - - org.junit.vintage - junit-vintage-engine - 5.3.1 + junit-jupiter-api + ${junit.version} test @@ -61,7 +57,15 @@ utf-8 + + + maven-assembly-plugin + + + jar-with-dependencies + + + - diff --git a/src/main/java/com/archon/presto/UdfPlugin.java b/src/main/java/com/github/archongum/presto/UdfPlugin.java similarity index 54% rename from src/main/java/com/archon/presto/UdfPlugin.java rename to src/main/java/com/github/archongum/presto/UdfPlugin.java index f40e033..bdb4414 100644 --- a/src/main/java/com/archon/presto/UdfPlugin.java +++ b/src/main/java/com/github/archongum/presto/UdfPlugin.java @@ -13,13 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.archon.presto; +package com.github.archongum.presto; -import com.archon.presto.udf.scalar.CommonFunctions; -import com.archon.presto.udf.scalar.DateTimeFunctions; -import com.google.common.collect.ImmutableSet; +import com.github.archongum.presto.udf.aggregate.MaxCountElementAggregation; +import com.github.archongum.presto.udf.scalar.ArrayMaxCountElementFunction; +import com.github.archongum.presto.udf.scalar.CommonFunctions; +import com.github.archongum.presto.udf.scalar.DateTimeFunctions; import io.prestosql.spi.Plugin; +import java.util.HashSet; import java.util.Set; @@ -28,9 +30,11 @@ public class UdfPlugin implements Plugin @Override public Set> getFunctions() { - return ImmutableSet.>builder() - .add(DateTimeFunctions.class) - .add(CommonFunctions.class) - .build(); + Set> set = new HashSet<>(); + set.add(ArrayMaxCountElementFunction.class); + set.add(CommonFunctions.class); + set.add(DateTimeFunctions.class); + set.add(MaxCountElementAggregation.class); + return set; } } diff --git a/src/main/java/com/github/archongum/presto/udf/aggregate/MaxCountElementAggregation.java b/src/main/java/com/github/archongum/presto/udf/aggregate/MaxCountElementAggregation.java new file mode 100644 index 0000000..b7a7b9b --- /dev/null +++ b/src/main/java/com/github/archongum/presto/udf/aggregate/MaxCountElementAggregation.java @@ -0,0 +1,54 @@ +package com.github.archongum.presto.udf.aggregate; + +import com.github.archongum.presto.udf.aggregate.state.MapState; +import io.airlift.slice.Slice; +import io.airlift.slice.Slices; +import io.prestosql.spi.block.BlockBuilder; +import io.prestosql.spi.function.AggregationFunction; +import io.prestosql.spi.function.CombineFunction; +import io.prestosql.spi.function.Description; +import io.prestosql.spi.function.InputFunction; +import io.prestosql.spi.function.OutputFunction; +import io.prestosql.spi.function.SqlType; +import io.prestosql.spi.type.StandardTypes; + +import java.util.Map; +import java.util.Map.Entry; + +import static io.prestosql.spi.type.VarcharType.VARCHAR; + + +@AggregationFunction("max_count_element") +@Description("Get maximum count element (null is not counting; if has multiple return one of them)") +public class MaxCountElementAggregation +{ + @InputFunction + public static void input(MapState state, @SqlType(StandardTypes.VARCHAR) Slice value) + { + String v = value.toStringUtf8(); + Map map = state.getMap(); + Long cnt = map.get(v); + if (cnt == null) { + map.put(v, 1L); + } else { + map.put(v, cnt+1); + } + } + + @CombineFunction + public static void combine(MapState state, MapState otherState) + { + otherState.getMap().forEach((k, v) -> state.getMap().merge(k, v, Long::sum)); + } + + @OutputFunction(StandardTypes.VARCHAR) + public static void output(MapState state, BlockBuilder out) + { + if (state.getMap().isEmpty()) { + out.appendNull(); + } else { + VARCHAR.writeSlice(out, + Slices.utf8Slice(state.getMap().entrySet().stream().max(Entry.comparingByValue()).get().getKey())); + } + } +} diff --git a/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapState.java b/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapState.java new file mode 100644 index 0000000..7e4436f --- /dev/null +++ b/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapState.java @@ -0,0 +1,14 @@ +package com.github.archongum.presto.udf.aggregate.state; + +import io.prestosql.spi.function.AccumulatorState; +import io.prestosql.spi.function.AccumulatorStateMetadata; + +import java.util.Map; + + +@AccumulatorStateMetadata(stateSerializerClass = MapStateSerializer.class, stateFactoryClass = MapStateFactory.class) +public interface MapState extends AccumulatorState { + Map getMap(); + + void setMap(Map value); +} diff --git a/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateFactory.java b/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateFactory.java new file mode 100644 index 0000000..5bcb10c --- /dev/null +++ b/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateFactory.java @@ -0,0 +1,88 @@ +package com.github.archongum.presto.udf.aggregate.state; + +import io.prestosql.array.ObjectBigArray; +import io.prestosql.spi.function.AccumulatorStateFactory; +import io.prestosql.spi.function.GroupedAccumulatorState; + +import java.util.HashMap; +import java.util.Map; + + +/** + * @author Archon 8/30/19 + * @since + */ +public class MapStateFactory implements AccumulatorStateFactory { + + public static final class SingleMapState implements MapState { + + private Map map = new HashMap<>(); + + @Override + public Map getMap() { + return map; + } + + @Override + public void setMap(Map value) { + this.map = value; + } + + @Override + public long getEstimatedSize() { + return map.size(); + } + } + + public static class GroupedMapState implements GroupedAccumulatorState, MapState { + + private final ObjectBigArray> maps = new ObjectBigArray<>(); + private long groupId; + + @Override + public Map getMap() { + return maps.get(groupId); + } + + @Override + public void setMap(Map value) { + maps.set(groupId, value); + } + + @Override + public void setGroupId(long groupId) { + this.groupId = groupId; + } + + @Override + public void ensureCapacity(long size) { + maps.ensureCapacity(size); + } + + @Override + public long getEstimatedSize() { + return maps.sizeOf(); + } + } + + @Override + public MapState createSingleState() { + return new SingleMapState(); + } + + @Override + public Class getSingleStateClass() { + return SingleMapState.class; + } + + + @Override + public MapState createGroupedState() { + return new GroupedMapState(); + } + + @Override + public Class getGroupedStateClass() { + return GroupedMapState.class; + } +} diff --git a/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateSerializer.java b/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateSerializer.java new file mode 100644 index 0000000..d845c2d --- /dev/null +++ b/src/main/java/com/github/archongum/presto/udf/aggregate/state/MapStateSerializer.java @@ -0,0 +1,52 @@ +package com.github.archongum.presto.udf.aggregate.state; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.airlift.slice.Slices; +import io.prestosql.spi.block.Block; +import io.prestosql.spi.block.BlockBuilder; +import io.prestosql.spi.function.AccumulatorStateSerializer; +import io.prestosql.spi.type.Type; + +import java.io.IOException; +import java.util.HashMap; + +import static io.prestosql.spi.type.VarcharType.VARCHAR; + + +/** + * @author Archon 8/30/19 + * @since + */ +public class MapStateSerializer implements AccumulatorStateSerializer +{ + + private ObjectMapper mapper = new ObjectMapper(); + + @Override + public Type getSerializedType() { + return VARCHAR; + } + + @Override + public void serialize(MapState state, BlockBuilder out) { + try { + String jsonResult = mapper.writeValueAsString(state.getMap()); + VARCHAR.writeSlice(out, Slices.utf8Slice(jsonResult)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deserialize(Block block, int index, MapState state) { + try { + TypeReference> typeRef = new TypeReference>() {}; + state.setMap(mapper.readValue(VARCHAR.getSlice(block, index).toStringUtf8(), typeRef)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} + diff --git a/src/main/java/com/github/archongum/presto/udf/scalar/ArrayMaxCountElementFunction.java b/src/main/java/com/github/archongum/presto/udf/scalar/ArrayMaxCountElementFunction.java new file mode 100644 index 0000000..69e7841 --- /dev/null +++ b/src/main/java/com/github/archongum/presto/udf/scalar/ArrayMaxCountElementFunction.java @@ -0,0 +1,84 @@ +package com.github.archongum.presto.udf.scalar; + +import io.airlift.slice.Slice; +import io.prestosql.spi.block.Block; +import io.prestosql.spi.function.*; +import io.prestosql.spi.type.Type; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + + +@ScalarFunction("array_max_count_element") +@Description("Get maximum count element of array (null is not counting; if has multiple return one of them)") +public final class ArrayMaxCountElementFunction +{ + private ArrayMaxCountElementFunction() {} + + @TypeParameter("T") + @SqlType("T") + @SqlNullable + public static Slice sliceArrayMaxCountElement( + @TypeParameter("T") Type elementType, + @SqlType("array(T)") Block block + ) { + if (block.getPositionCount() == 0) { + return null; + } + + Map map = new HashMap<>(); + + for (int i = 0; i < block.getPositionCount(); i++) { + if (block.isNull(i)) { + continue; + } + Slice curElement = elementType.getSlice(block, i); + Long c = map.get(curElement); + if (c == null) { + map.put(curElement, 1L); + } else { + map.put(curElement, c+1); + } + } + + if (map.isEmpty()) { + return null; + } + + return map.entrySet().stream().max(Entry.comparingByValue()).get().getKey(); + } + + @TypeParameter("T") + @SqlType("T") + @SqlNullable + public static Long longArrayMaxCountElement( + @TypeParameter("T") Type elementType, + @SqlType("array(T)") Block block + ) { + if (block.getPositionCount() == 0) { + return null; + } + + Map map = new HashMap<>(); + + for (int i = 0; i < block.getPositionCount(); i++) { + if (block.isNull(i)) { + continue; + } + Long curElement = elementType.getLong(block, i); + Long c = map.get(curElement); + if (c == null) { + map.put(curElement, 1L); + } else { + map.put(curElement, c+1); + } + } + + if (map.isEmpty()) { + return null; + } + + return map.entrySet().stream().max(Entry.comparingByValue()).get().getKey(); + } +} diff --git a/src/main/java/com/archon/presto/udf/scalar/CommonFunctions.java b/src/main/java/com/github/archongum/presto/udf/scalar/CommonFunctions.java similarity index 89% rename from src/main/java/com/archon/presto/udf/scalar/CommonFunctions.java rename to src/main/java/com/github/archongum/presto/udf/scalar/CommonFunctions.java index ca93e16..2f3280b 100644 --- a/src/main/java/com/archon/presto/udf/scalar/CommonFunctions.java +++ b/src/main/java/com/github/archongum/presto/udf/scalar/CommonFunctions.java @@ -1,4 +1,4 @@ -package com.archon.presto.udf.scalar; +package com.github.archongum.presto.udf.scalar; import io.airlift.slice.Slice; import io.prestosql.spi.function.Description; diff --git a/src/main/java/com/archon/presto/udf/scalar/DateTimeFunctions.java b/src/main/java/com/github/archongum/presto/udf/scalar/DateTimeFunctions.java similarity index 91% rename from src/main/java/com/archon/presto/udf/scalar/DateTimeFunctions.java rename to src/main/java/com/github/archongum/presto/udf/scalar/DateTimeFunctions.java index 7abacac..56f50b7 100644 --- a/src/main/java/com/archon/presto/udf/scalar/DateTimeFunctions.java +++ b/src/main/java/com/github/archongum/presto/udf/scalar/DateTimeFunctions.java @@ -1,4 +1,4 @@ -package com.archon.presto.udf.scalar; +package com.github.archongum.presto.udf.scalar; import io.airlift.slice.Slice; import io.prestosql.spi.function.Description; @@ -9,7 +9,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import static com.archon.presto.udf.scalar.DateTimeUtils.OFFSET_MILLIS; +import static com.github.archongum.presto.udf.scalar.DateTimeUtils.OFFSET_MILLIS; import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.MILLISECONDS; diff --git a/src/main/java/com/archon/presto/udf/scalar/DateTimeUtils.java b/src/main/java/com/github/archongum/presto/udf/scalar/DateTimeUtils.java similarity index 95% rename from src/main/java/com/archon/presto/udf/scalar/DateTimeUtils.java rename to src/main/java/com/github/archongum/presto/udf/scalar/DateTimeUtils.java index a6ce20c..8169aae 100644 --- a/src/main/java/com/archon/presto/udf/scalar/DateTimeUtils.java +++ b/src/main/java/com/github/archongum/presto/udf/scalar/DateTimeUtils.java @@ -1,4 +1,4 @@ -package com.archon.presto.udf.scalar; +package com.github.archongum.presto.udf.scalar; import java.time.LocalDate; import java.time.LocalDateTime; diff --git a/src/main/resources/META-INF/services/io.prestosql.spi.Plugin b/src/main/resources/META-INF/services/io.prestosql.spi.Plugin index 68a5017..240cac7 100644 --- a/src/main/resources/META-INF/services/io.prestosql.spi.Plugin +++ b/src/main/resources/META-INF/services/io.prestosql.spi.Plugin @@ -1 +1 @@ -com.archon.presto.UdfPlugin +com.github.archongum.presto.UdfPlugin diff --git a/src/test/com/github/archongum/presto/udf/aggregate/TestAggreateFunctions.java b/src/test/com/github/archongum/presto/udf/aggregate/TestAggreateFunctions.java new file mode 100644 index 0000000..98462fe --- /dev/null +++ b/src/test/com/github/archongum/presto/udf/aggregate/TestAggreateFunctions.java @@ -0,0 +1,40 @@ +package com.github.archongum.presto.udf.aggregate; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + + +/** + * @author Archon 2019/8/29 + * @since + */ +class TestAggreateFunctions { + + @Test + void testTopN() { + List list = Arrays.asList( + "a", "a", "a", + "b", "b", + "c", + "a", "a" + ); + + Map map = new HashMap<>(); + + for (String curElement : list) { + Long c = map.get(curElement); + if (c == null) { + map.put(curElement, 1L); + } else { + map.put(curElement, c + 1); + } + } + + System.out.println(new HashMap().entrySet().stream().max(Entry.comparingByValue()).get()); + } +} diff --git a/src/test/com/archon/presto/udf/scalar/DateTimeFunctionsTest.java b/src/test/com/github/archongum/presto/udf/scalar/TestDateTimeFunctions.java similarity index 73% rename from src/test/com/archon/presto/udf/scalar/DateTimeFunctionsTest.java rename to src/test/com/github/archongum/presto/udf/scalar/TestDateTimeFunctions.java index 51a17fa..da1f612 100644 --- a/src/test/com/archon/presto/udf/scalar/DateTimeFunctionsTest.java +++ b/src/test/com/github/archongum/presto/udf/scalar/TestDateTimeFunctions.java @@ -1,6 +1,6 @@ -package com.archon.presto.udf.scalar; +package com.github.archongum.presto.udf.scalar; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -9,17 +9,17 @@ * @author Archon 2018/9/20 * @since */ -public class DateTimeFunctionsTest { +class TestDateTimeFunctions { @Test - public void lastDay() { + void testLastDay() { long millis = System.currentTimeMillis(); System.out.println(DateTimeFunctions.lastDay(DateTimeUtils.toDays(millis))); System.out.println(MILLISECONDS.toDays(millis)); } @Test - public void toDatetime() { + void testToDatetime() { long millis = System.currentTimeMillis(); long d1 = DateTimeUtils.toLocalDateTime(millis).toLocalDate().toEpochDay(); System.out.println(d1); @@ -27,18 +27,18 @@ public void toDatetime() { } @Test - public void lastSecond() { + void testLastSecond() { long millis = System.currentTimeMillis(); System.out.println(DateTimeFunctions.lastSecond(millis/86400000)); } @Test - public void yesterdayLastSecond() { + void testYesterdayLastSecond() { System.out.println(DateTimeFunctions.yesterdayLastSecond()); } @Test - public void yesterday() { + void testYesterday() { System.out.println(DateTimeFunctions.yesterday()); } }