-
Notifications
You must be signed in to change notification settings - Fork 93
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
13337dc
commit 9b886af
Showing
70 changed files
with
6,237 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
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,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2023 Ant Group 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.antgroup.openspg.reasoner</groupId> | ||
<artifactId>reasoner-parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>reasoner-udf</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.antgroup.openspg.reasoner</groupId> | ||
<artifactId>reasoner-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.lukehutch</groupId> | ||
<artifactId>fast-classpath-scanner</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.geometry</groupId> | ||
<artifactId>s2-geometry</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geotools</groupId> | ||
<artifactId>gt-swing</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geotools</groupId> | ||
<artifactId>gt-epsg-hsql</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
104 changes: 104 additions & 0 deletions
104
reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/UdfMng.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,104 @@ | ||
/* | ||
* Copyright 2023 Ant Group 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. | ||
*/ | ||
|
||
/* | ||
* Ant Group | ||
* Copyright (c) 2004-2023 All Rights Reserved. | ||
*/ | ||
package com.antgroup.openspg.reasoner.udf; | ||
|
||
import com.antgroup.openspg.reasoner.common.types.KgType; | ||
import com.antgroup.openspg.reasoner.udf.model.IUdfMeta; | ||
import com.antgroup.openspg.reasoner.udf.model.RuntimeUdfMeta; | ||
import com.antgroup.openspg.reasoner.udf.model.UdafMeta; | ||
import com.antgroup.openspg.reasoner.udf.model.UdfParameterTypeHint; | ||
import com.antgroup.openspg.reasoner.udf.model.UdtfMeta; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface UdfMng { | ||
/** | ||
* Query UDF meta information, which can be used to determine whether UDF exists KgType is | ||
* compatible with java Object type | ||
* | ||
* <p>Query is inefficient, please cache for use | ||
* | ||
* @param name | ||
* @param paramTypeList | ||
* @return | ||
*/ | ||
IUdfMeta getUdfMeta(String name, List<KgType> paramTypeList); | ||
|
||
/** | ||
* use for querying the parameter list of the UDF can only be obtained on runtime | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
RuntimeUdfMeta getRuntimeUdfMeta(String name); | ||
|
||
/** | ||
* Query UDAF meta information | ||
* | ||
* <p>Query is inefficient, please cache for use | ||
* | ||
* @param name | ||
* @param rowDataType | ||
* @return | ||
*/ | ||
UdafMeta getUdafMeta(String name, KgType rowDataType); | ||
|
||
/** | ||
* Query UDTF meta information | ||
* | ||
* @param name | ||
* @param rowDataTypes | ||
* @return | ||
*/ | ||
UdtfMeta getUdtfMeta(String name, List<KgType> rowDataTypes); | ||
|
||
/** | ||
* get all udf meta information, for udf registration | ||
* | ||
* @return | ||
*/ | ||
List<IUdfMeta> getAllUdfMeta(); | ||
|
||
/** | ||
* get all runtime udf meta, for udf registration on QLExpress | ||
* | ||
* @return | ||
*/ | ||
List<RuntimeUdfMeta> getAllRuntimeUdfMeta(); | ||
|
||
/** | ||
* get all udaf for registration | ||
* | ||
* @return | ||
*/ | ||
List<UdafMeta> getAllUdafMeta(); | ||
|
||
/** | ||
* get all udtf meta for registration | ||
* | ||
* @return | ||
*/ | ||
List<UdtfMeta> getAllUdtfMeta(); | ||
|
||
/** | ||
* get udf type list hint | ||
* | ||
* <p>KTObject means support all kind types | ||
*/ | ||
Map<String, Map<String, UdfParameterTypeHint>> getUdfTypeHint(); | ||
} |
31 changes: 31 additions & 0 deletions
31
reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/UdfMngFactory.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,31 @@ | ||
/* | ||
* Copyright 2023 Ant Group 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. | ||
*/ | ||
|
||
/* | ||
* Ant Group | ||
* Copyright (c) 2004-2023 All Rights Reserved. | ||
*/ | ||
package com.antgroup.openspg.reasoner.udf; | ||
|
||
import com.antgroup.openspg.reasoner.udf.impl.UdfMngImpl; | ||
|
||
public class UdfMngFactory { | ||
/** | ||
* Factory mode | ||
* | ||
* @return | ||
*/ | ||
public static UdfMng getUdfMng() { | ||
return UdfMngImpl.getInstance(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/builtin/udaf/Avg.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,92 @@ | ||
/* | ||
* Copyright 2023 Ant Group 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. | ||
*/ | ||
|
||
/* | ||
* Ant Group | ||
* Copyright (c) 2004-2023 All Rights Reserved. | ||
*/ | ||
package com.antgroup.openspg.reasoner.udf.builtin.udaf; | ||
|
||
import com.antgroup.openspg.reasoner.common.types.KTDouble$; | ||
import com.antgroup.openspg.reasoner.common.types.KTInteger$; | ||
import com.antgroup.openspg.reasoner.common.types.KTLong$; | ||
import com.antgroup.openspg.reasoner.common.types.KTString$; | ||
import com.antgroup.openspg.reasoner.common.types.KgType; | ||
import com.antgroup.openspg.reasoner.udf.model.BaseUdaf; | ||
import com.antgroup.openspg.reasoner.udf.model.UdfDefine; | ||
|
||
public class Avg { | ||
|
||
/** avg double compute function */ | ||
@UdfDefine(name = "avg", compatibleName = "Avg") | ||
public static class AvgDouble implements BaseUdaf { | ||
private double sum = 0.0; | ||
private int count = 0; | ||
|
||
@Override | ||
public KgType getInputRowType() { | ||
return KTDouble$.MODULE$; | ||
} | ||
|
||
@Override | ||
public KgType getResultType() { | ||
return KTDouble$.MODULE$; | ||
} | ||
|
||
@Override | ||
public void initialize(Object... params) {} | ||
|
||
@Override | ||
public void update(Object row) { | ||
sum += ((Number) row).doubleValue(); | ||
count++; | ||
} | ||
|
||
@Override | ||
public void merge(BaseUdaf function) { | ||
AvgDouble other = (AvgDouble) function; | ||
this.sum += other.sum; | ||
this.count += other.count; | ||
} | ||
|
||
@Override | ||
public Object evaluate() { | ||
return this.sum / this.count; | ||
} | ||
} | ||
|
||
@UdfDefine(name = "avg", compatibleName = "Avg") | ||
public static class AvgInt extends AvgDouble { | ||
@Override | ||
public KgType getInputRowType() { | ||
return KTInteger$.MODULE$; | ||
} | ||
} | ||
|
||
@UdfDefine(name = "avg", compatibleName = "Avg") | ||
public static class AvgLong extends AvgDouble { | ||
@Override | ||
public KgType getInputRowType() { | ||
return KTLong$.MODULE$; | ||
} | ||
} | ||
|
||
/** avg string compute function */ | ||
@UdfDefine(name = "avg", compatibleName = "Avg") | ||
public static class AvgString extends AvgDouble { | ||
@Override | ||
public KgType getInputRowType() { | ||
return KTString$.MODULE$; | ||
} | ||
} | ||
} |
Oops, something went wrong.