-
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.
- Loading branch information
1 parent
5efe697
commit a52d823
Showing
8 changed files
with
178 additions
and
0 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
64 changes: 64 additions & 0 deletions
64
...sl/geaflow-dsl-plan/src/main/java/com/antgroup/geaflow/dsl/udf/table/other/IsDecimal.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,64 @@ | ||
/* | ||
* Copyright 2023 AntGroup CO., Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
*/ | ||
|
||
package com.antgroup.geaflow.dsl.udf.table.other; | ||
|
||
import com.antgroup.geaflow.dsl.common.function.Description; | ||
import com.antgroup.geaflow.dsl.common.function.UDF; | ||
|
||
@Description(name = "is_decimal", description = "Returns true if only contains digits and is " | ||
+ "non-null, otherwise return false.") | ||
public class IsDecimal extends UDF { | ||
|
||
public boolean eval(String s) { | ||
if (s == null) { | ||
return false; | ||
} | ||
if (isInteger(s) || isLong(s) || isDouble(s)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
private boolean isInteger(String s) { | ||
boolean flag = true; | ||
try { | ||
Integer.parseInt(s); | ||
} catch (NumberFormatException e) { | ||
flag = false; | ||
} | ||
return flag; | ||
} | ||
|
||
private boolean isLong(String s) { | ||
boolean flag = true; | ||
try { | ||
Long.parseLong(s); | ||
} catch (NumberFormatException e) { | ||
flag = false; | ||
} | ||
return flag; | ||
} | ||
|
||
private boolean isDouble(String s) { | ||
boolean flag = true; | ||
try { | ||
Double.parseDouble(s); | ||
} catch (NumberFormatException e) { | ||
flag = false; | ||
} | ||
return flag; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/data/loop.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,15 @@ | ||
. 1,jim | ||
. 2,kate | ||
. 3,lily | ||
. 4,lucy | ||
. 5,brown | ||
. 6,jack | ||
. 7,jackson | ||
- 1,2,0.2 | ||
- 2,3,0.3 | ||
- 3,4,0.2 | ||
- 4,1,0.1 | ||
- 4,5,0.1 | ||
- 5,1,0.2 | ||
- 5,6,0.1 | ||
- 6,7,0.1 |
4 changes: 4 additions & 0 deletions
4
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/expect/find_loop.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,4 @@ | ||
2,3,4,1,2 | ||
4,1,2,3,4 | ||
3,4,1,2,3 | ||
1,2,3,4,1 |
76 changes: 76 additions & 0 deletions
76
geaflow/geaflow-dsl/geaflow-dsl-runtime/src/test/resources/query/find_loop.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,76 @@ | ||
set geaflow.dsl.window.size = 1; | ||
set geaflow.dsl.ignore.exception = true; | ||
|
||
CREATE GRAPH IF NOT EXISTS dy_modern ( | ||
Vertex person ( | ||
id bigint ID, | ||
name varchar | ||
), | ||
Edge knows ( | ||
srcId bigint SOURCE ID, | ||
targetId bigint DESTINATION ID, | ||
weight double | ||
) | ||
) WITH ( | ||
storeType='rocksdb', | ||
shardCount = 1 | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS tbl_source ( | ||
text varchar | ||
) WITH ( | ||
type='file', | ||
`geaflow.dsl.column.separator` = '#', | ||
geaflow.dsl.file.path = 'resource:///data/loop.txt' | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS tbl_result ( | ||
a_id bigint, | ||
b_id bigint, | ||
c_id bigint, | ||
d_id bigint, | ||
a1_id bigint | ||
) WITH ( | ||
type='file', | ||
geaflow.dsl.file.path = '${target}' | ||
); | ||
|
||
USE GRAPH dy_modern; | ||
|
||
INSERT INTO dy_modern.person(id, name) | ||
SELECT | ||
cast(trim(split_ex(t1, ',', 0)) as bigint), | ||
split_ex(trim(t1), ',', 1) | ||
FROM ( | ||
Select trim(substr(text, 2)) as t1 | ||
FROM tbl_source | ||
WHERE substr(text, 1, 1) = '.' | ||
AND is_decimal(trim(split_ex(trim(substr(text, 2)), ',', 0))) | ||
); | ||
|
||
INSERT INTO dy_modern.knows | ||
SELECT | ||
cast(split_ex(t1, ',', 0) as bigint), | ||
cast(split_ex(t1, ',', 1) as bigint), | ||
cast(split_ex(t1, ',', 2) as double) | ||
FROM ( | ||
Select trim(substr(text, 2)) as t1 | ||
FROM tbl_source | ||
WHERE substr(text, 1, 1) = '-' | ||
AND is_decimal(split_ex(trim(substr(text, 2)), ',', 0)) | ||
AND is_decimal(split_ex(trim(substr(text, 2)), ',', 1)) | ||
AND is_decimal(split_ex(trim(substr(text, 2)), ',', 2)) | ||
); | ||
|
||
INSERT INTO tbl_result | ||
SELECT DISTINCT | ||
a_id, | ||
b_id, | ||
c_id, | ||
d_id, | ||
a1_id | ||
FROM ( | ||
MATCH (a:person) -[:knows]->(b:person) -[:knows]-> (c:person) | ||
-[:knows]-> (d:person) -> (a:person) | ||
RETURN a.id as a_id, b.id as b_id, c.id as c_id, d.id as d_id, a.id as a1_id | ||
); |
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