-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE-193] Support date type for dsl
- Loading branch information
pengzhiwei
authored
Oct 11, 2023
1 parent
dbf759d
commit 4288afa
Showing
13 changed files
with
238 additions
and
2 deletions.
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
41 changes: 41 additions & 0 deletions
41
...low/geaflow-common/src/main/java/com/antgroup/geaflow/common/type/primitive/DateType.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,41 @@ | ||
package com.antgroup.geaflow.common.type.primitive; | ||
|
||
import com.antgroup.geaflow.common.type.IType; | ||
import com.antgroup.geaflow.common.type.Types; | ||
import com.google.common.primitives.Longs; | ||
import java.sql.Date; | ||
|
||
public class DateType implements IType<Date> { | ||
|
||
public static final DateType INSTANCE = new DateType(); | ||
|
||
@Override | ||
public String getName() { | ||
return Types.TYPE_NAME_DATE; | ||
} | ||
|
||
@Override | ||
public Class<Date> getTypeClass() { | ||
return Date.class; | ||
} | ||
|
||
@Override | ||
public byte[] serialize(Date obj) { | ||
return Longs.toByteArray(obj.getTime()); | ||
} | ||
|
||
@Override | ||
public Date deserialize(byte[] bytes) { | ||
return new Date(Longs.fromByteArray(bytes)); | ||
} | ||
|
||
@Override | ||
public int compare(Date x, Date y) { | ||
return Long.compare(x.getTime(), y.getTime()); | ||
} | ||
|
||
@Override | ||
public boolean isPrimitive() { | ||
return true; | ||
} | ||
} |
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
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
33 changes: 33 additions & 0 deletions
33
...l/geaflow-dsl-runtime/src/test/java/com/antgroup/geaflow/dsl/runtime/query/TypesTest.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 com.antgroup.geaflow.dsl.runtime.query; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
public class TypesTest { | ||
|
||
@Test | ||
public void testBooleanType_001() throws Exception { | ||
QueryTester | ||
.build() | ||
.withQueryPath("/query/type_boolean_001.sql") | ||
.execute() | ||
.checkSinkResult(); | ||
} | ||
|
||
@Test | ||
public void testTimestampType_001() throws Exception { | ||
QueryTester | ||
.build() | ||
.withQueryPath("/query/type_timestamp_001.sql") | ||
.execute() | ||
.checkSinkResult(); | ||
} | ||
|
||
@Test | ||
public void testDateType_001() throws Exception { | ||
QueryTester | ||
.build() | ||
.withQueryPath("/query/type_date_001.sql") | ||
.execute() | ||
.checkSinkResult(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/data/users3.txt
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,14 @@ | ||
1489576693884, 10, 170.0, alex, true, 2023-10-10 | ||
1489576693883, 11, 175.0, Jane, true, 2023-10-01 | ||
1489576693822, 12, 170.0, jack, false, 2023-10-02 | ||
1489576693834, 13, 165.0, snow, false, 2023-10-03 | ||
1489576693834, 15, 170.0, one, false, 2023-10-02 | ||
1489576693834, 16, 160.0, sam, false, 2023-10-02 | ||
1489576693883, 17, 170.0, dog, false, 2023-10-03 | ||
1489576693844, 18, 180.0, mahone, false, 2023-10-04 | ||
1489576693854, 19, 170.0, tbeg, false, 2023-10-05 | ||
1489576693864, 31, 180.0, ok, false, 2023-10-05 | ||
1489576693874, 42, 190.0, good1, false, 2023-10-06 | ||
1489576693874, 40, 190.0, good2, false, 2023-10-07 | ||
1489576693874, 41, 190.0, good3, false, 2023-10-08 | ||
1489576693874, 43, 190.0, good4, false, 2023-10-08 |
2 changes: 2 additions & 0 deletions
2
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/expect/type_boolean_001.txt
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,2 @@ | ||
false,12 | ||
true,2 |
9 changes: 9 additions & 0 deletions
9
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/expect/type_date_001.txt
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 @@ | ||
2023-10-10,1 | ||
2023-10-05,2 | ||
2023-10-03,2 | ||
2023-10-08,2 | ||
2023-10-01,1 | ||
2023-10-06,1 | ||
2023-10-04,1 | ||
2023-10-07,1 | ||
2023-10-02,3 |
8 changes: 8 additions & 0 deletions
8
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/expect/type_timestamp_001.txt
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,8 @@ | ||
2017-03-15 19:18:13.883,2 | ||
2017-03-15 19:18:13.864,1 | ||
2017-03-15 19:18:13.822,1 | ||
2017-03-15 19:18:13.854,1 | ||
2017-03-15 19:18:13.884,1 | ||
2017-03-15 19:18:13.874,4 | ||
2017-03-15 19:18:13.844,1 | ||
2017-03-15 19:18:13.834,3 |
27 changes: 27 additions & 0 deletions
27
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/query/type_boolean_001.sql
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,27 @@ | ||
CREATE TABLE IF NOT EXISTS users3 ( | ||
rt bigint, | ||
f1 bigint, | ||
f2 double, | ||
f3 varchar, | ||
f4 boolean, | ||
f5 varchar | ||
) WITH ( | ||
type='file', | ||
geaflow.dsl.file.path = 'resource:///data/users3.txt' | ||
); | ||
|
||
CREATE TABLE console( | ||
f4 boolean, | ||
cnt bigint | ||
) WITH ( | ||
type='file', | ||
geaflow.dsl.file.path='${target}' | ||
); | ||
|
||
INSERT INTO console | ||
SELECT | ||
f4, | ||
count(f1) | ||
FROM users3 | ||
group by f4 | ||
; |
27 changes: 27 additions & 0 deletions
27
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/query/type_date_001.sql
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,27 @@ | ||
CREATE TABLE IF NOT EXISTS users3 ( | ||
rt TIMESTAMP, | ||
f1 bigint, | ||
f2 double, | ||
f3 varchar, | ||
f4 boolean, | ||
f5 date | ||
) WITH ( | ||
type='file', | ||
geaflow.dsl.file.path = 'resource:///data/users3.txt' | ||
); | ||
|
||
CREATE TABLE console( | ||
f5 date, | ||
cnt bigint | ||
) WITH ( | ||
type='file', | ||
geaflow.dsl.file.path='${target}' | ||
); | ||
|
||
INSERT INTO console | ||
SELECT | ||
f5, | ||
count(f1) | ||
FROM users3 | ||
group by f5 | ||
; |
27 changes: 27 additions & 0 deletions
27
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/query/type_timestamp_001.sql
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,27 @@ | ||
CREATE TABLE IF NOT EXISTS users3 ( | ||
rt TIMESTAMP, | ||
f1 bigint, | ||
f2 double, | ||
f3 varchar, | ||
f4 boolean, | ||
f5 varchar | ||
) WITH ( | ||
type='file', | ||
geaflow.dsl.file.path = 'resource:///data/users3.txt' | ||
); | ||
|
||
CREATE TABLE console( | ||
rt TIMESTAMP, | ||
cnt bigint | ||
) WITH ( | ||
type='file', | ||
geaflow.dsl.file.path='${target}' | ||
); | ||
|
||
INSERT INTO console | ||
SELECT | ||
rt, | ||
count(f1) | ||
FROM users3 | ||
group by rt | ||
; |