Skip to content

Commit

Permalink
Merge pull request #279 from ddf-project/feature/datetime_extract_udf…
Browse files Browse the repository at this point in the history
…_support_date_timestamp

remove dayofmonth UDF; remove println statements
  • Loading branch information
hai-adatao committed Mar 8, 2016
2 parents ad8d9b4 + 1c38c95 commit eed65bf
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ object DateTimeExtractUDF {
case "weekyear" => DateUDF.parseWeekYear(obj)
case "weekofyear" => DateUDF.parseWeekOfYear(obj)
case "day" => DateUDF.parseDay(obj)
case "dayofmonth" => DateUDF.parseDay(obj)
case "dayofweek" => DateUDF.parseDayOfWeek(obj)
case "dayofyear" => DateUDF.parseDayOfYear(obj)
case "hour" => DateUDF.parseHour(obj)
Expand Down
1 change: 0 additions & 1 deletion spark/src/main/scala/io/ddf/spark/etl/DateUDFs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ object DateUDF {
sQLContext.udf.register("weekyear", parseWeekYear)
sQLContext.udf.register("weekofyear", parseWeekOfYear)
sQLContext.udf.register("day", parseDay)
sQLContext.udf.register("dayofmonth", parseDay)
sQLContext.udf.register("dayofweek", parseDayOfWeek)
sQLContext.udf.register("dayofweek_text", parseDayOfWeekAsText)
sQLContext.udf.register("dayofyear", parseDayOfYear)
Expand Down
28 changes: 0 additions & 28 deletions spark/src/test/java/io/ddf/spark/etl/UDFTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ public void testDateTimeExtract() throws DDFException {
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select extract('2015-01-22 20:23 +0000', 'dayofmonth') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select extract('2015-01-22 20:23 +0000', 'dayofweek') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfWeek());
Expand Down Expand Up @@ -197,10 +193,6 @@ public void testDateTimeExtract() throws DDFException {
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select extract(1433386800, 'dayofmonth') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select extract(1433386800, 'dayofweek') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfWeek());
Expand Down Expand Up @@ -251,10 +243,6 @@ public void testDateTimeExtract() throws DDFException {
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select extract(4147483647, 'dayofmonth') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select extract(4147483647, 'dayofweek') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfWeek());
Expand All @@ -281,7 +269,6 @@ public void testDateTimeExtract() throws DDFException {

// Support date type
dt = new DateTime(new java.sql.Date(1433386800 * 1000L));
System.out.println(dt.toString("yyyy-MM-dd HH:mm:ss"));
ddf3 = ddf.sql2ddf("select extract(to_date(from_unixtime(1433386800)), 'year') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getYear());
Expand Down Expand Up @@ -316,7 +303,6 @@ public void testDateTimeExtract() throws DDFException {

ddf3 = ddf.sql2ddf("select extract(to_date(from_unixtime(1433386800)), 'hour') from @this");
rows = ddf3.VIEWS.head(1);
System.out.println(rows.get(0));
Assert.assertTrue(Integer.parseInt(rows.get(0))== 0);

ddf3 = ddf.sql2ddf("select extract(to_date(from_unixtime(1433386800)), 'minute') from @this");
Expand Down Expand Up @@ -425,10 +411,6 @@ public void testIndividualDateTimeExtractUDFs() throws DDFException {
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0)) == dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select dayofmonth('2015-01-22 20:23 +0000') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0)) == dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select dayofweek('2015-01-22 20:23 +0000') from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0)) == dt.getDayOfWeek());
Expand Down Expand Up @@ -515,10 +497,6 @@ public void testIndividualDateTimeExtractUDFs() throws DDFException {
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(rows.get(0).equalsIgnoreCase(dt.dayOfWeek().getAsShortText()));

ddf3 = ddf.sql2ddf("select dayofmonth(1433386800) from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select dayofweek(1433386800) from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfWeek());
Expand Down Expand Up @@ -581,10 +559,6 @@ public void testIndividualDateTimeExtractUDFs() throws DDFException {
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select dayofmonth(4147483647) from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfMonth());

ddf3 = ddf.sql2ddf("select dayofweek(4147483647) from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getDayOfWeek());
Expand Down Expand Up @@ -623,7 +597,6 @@ public void testIndividualDateTimeExtractUDFs() throws DDFException {

// Support date type
dt = new DateTime(new java.sql.Date(1433386800 * 1000L));
System.out.println(dt.toString("yyyy-MM-dd HH:mm:ss"));
ddf3 = ddf.sql2ddf("select year(to_date(from_unixtime(1433386800))) from @this");
rows = ddf3.VIEWS.head(1);
Assert.assertTrue(Integer.parseInt(rows.get(0))== dt.getYear());
Expand Down Expand Up @@ -682,7 +655,6 @@ public void testIndividualDateTimeExtractUDFs() throws DDFException {

ddf3 = ddf.sql2ddf("select hour(to_date(from_unixtime(1433386800))) from @this");
rows = ddf3.VIEWS.head(1);
System.out.println(rows.get(0));
Assert.assertTrue(Integer.parseInt(rows.get(0))== 0);

ddf3 = ddf.sql2ddf("select minute(to_date(from_unixtime(1433386800))) from @this");
Expand Down

0 comments on commit eed65bf

Please sign in to comment.