Skip to content

Commit 10f41e8

Browse files
authored
Merge pull request #118 from SongY123/main
support spatial query
2 parents 71d4377 + 6bcc126 commit 10f41e8

File tree

15 files changed

+244
-270
lines changed

15 files changed

+244
-270
lines changed

benchmark/src/test/java/com/hufudb/openhufu/benchmark/OpenHuFuSpatialBenchmarkTest.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,15 @@
44
import com.google.common.reflect.TypeToken;
55
import com.google.gson.Gson;
66
import com.hufudb.openhufu.benchmark.enums.SpatialTableName;
7-
import com.hufudb.openhufu.benchmark.enums.TPCHTableName;
87
import com.hufudb.openhufu.core.table.GlobalTableConfig;
9-
import com.hufudb.openhufu.data.schema.Schema;
108
import com.hufudb.openhufu.data.storage.DataSet;
119
import com.hufudb.openhufu.data.storage.DataSetIterator;
12-
import com.hufudb.openhufu.expression.AggFuncType;
1310
import com.hufudb.openhufu.expression.ExpressionFactory;
1411
import com.hufudb.openhufu.owner.user.OpenHuFuUser;
15-
import com.hufudb.openhufu.plan.BinaryPlan;
1612
import com.hufudb.openhufu.plan.LeafPlan;
1713
import com.hufudb.openhufu.proto.OpenHuFuData.ColumnType;
1814
import com.hufudb.openhufu.proto.OpenHuFuData.Modifier;
19-
import com.hufudb.openhufu.proto.OpenHuFuPlan;
20-
import com.hufudb.openhufu.proto.OpenHuFuPlan.Collation;
21-
import com.hufudb.openhufu.proto.OpenHuFuPlan.JoinCondition;
22-
import com.hufudb.openhufu.proto.OpenHuFuPlan.JoinType;
15+
import com.hufudb.openhufu.proto.OpenHuFuPlan.Expression;
2316
import org.junit.BeforeClass;
2417
import org.junit.Test;
2518
import org.slf4j.Logger;
@@ -42,13 +35,13 @@ public static void setUp() throws IOException {
4235

4336
List<String> endpoints =
4437
new Gson().fromJson(Files.newBufferedReader(
45-
Path.of(OpenHuFuBenchmark.class.getClassLoader().getResource("spatialEndpoints.json")
38+
Path.of(OpenHuFuBenchmark.class.getClassLoader().getResource("spatial-endpoints.json")
4639
.getPath())),
4740
new TypeToken<ArrayList<String>>() {
4841
}.getType());
4942
List<GlobalTableConfig> globalTableConfigs =
5043
new Gson().fromJson(Files.newBufferedReader(
51-
Path.of(OpenHuFuBenchmark.class.getClassLoader().getResource("spatialTables.json")
44+
Path.of(OpenHuFuBenchmark.class.getClassLoader().getResource("spatial-tables.json")
5245
.getPath())),
5346
new TypeToken<ArrayList<GlobalTableConfig>>() {
5447
}.getType());
@@ -84,4 +77,31 @@ public void testSelect() {
8477
dataset.close();
8578
}
8679

80+
@Test
81+
public void testSpatialDistance() {
82+
String tableName = SpatialTableName.SPATIAL.getName();
83+
LeafPlan plan = new LeafPlan();
84+
plan.setTableName(tableName);
85+
plan.setSelectExps(ExpressionFactory.createInputRef(user.getOpenHuFuTableSchema(tableName).getSchema()));
86+
// select * from spatial where DWithin(S_POINT, Point(1404050.076199729, -4762163.267865509), 0.1);
87+
Expression pointFunc =
88+
ExpressionFactory.createScalarFunc(ColumnType.POINT, "Point",
89+
ImmutableList.of(ExpressionFactory.createLiteral(ColumnType.DOUBLE, 1404050.076199729),
90+
ExpressionFactory.createLiteral(ColumnType.DOUBLE, -4762163.267865509)));
91+
Expression dwithinFunc =
92+
ExpressionFactory.createScalarFunc(ColumnType.BOOLEAN, "DWithin",
93+
ImmutableList.of(ExpressionFactory.createInputRef(1, ColumnType.POINT, Modifier.PUBLIC),
94+
pointFunc, ExpressionFactory.createLiteral(ColumnType.DOUBLE, 0.1)));
95+
plan.setWhereExps(ImmutableList.of(dwithinFunc));
96+
DataSet dataset = user.executeQuery(plan);
97+
DataSetIterator it = dataset.getIterator();
98+
int count = 0;
99+
assertEquals(2, it.size());
100+
while (it.next()) {
101+
assertEquals(0L, it.get(0));
102+
count++;
103+
}
104+
assertEquals(1, count);
105+
}
106+
87107
}

plan/src/main/java/com/hufudb/openhufu/expression/BasicTranslator.java

Lines changed: 0 additions & 233 deletions
This file was deleted.

plan/src/main/java/com/hufudb/openhufu/expression/Translator.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

plan/src/main/java/com/hufudb/openhufu/udf/ScalarUDF.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ public interface ScalarUDF {
1111
String getName();
1212
ColumnType getOutType(List<ColumnType> inTypes);
1313
Object implement(List<Object> inputs);
14-
String translate(String dataSource, List<String> inputs);
1514
}

plan/src/main/java/com/hufudb/openhufu/udf/UDFLoader.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ private UDFLoader() {}
3232

3333
public static Map<String, ScalarUDF> loadScalarUDF(String scalarUDFDirectory) {
3434
LOG.info("Load scalar udf from {}", scalarUDFDirectory);
35-
File udfs[] = new File(scalarUDFDirectory).listFiles(new FileFilter() {
36-
@Override
37-
public boolean accept(File file) {
38-
return file.getName().endsWith(".jar");
39-
}
40-
});
35+
File udfs[] = new File(scalarUDFDirectory).listFiles(file -> file.getName().endsWith(".jar"));
4136
List<URL> udfURLs = new ArrayList<>(udfs.length);
4237
for (File udf : udfs) {
4338
try {
@@ -65,14 +60,6 @@ public static Object implementScalar(String funcName, List<Object> inputs) {
6560
return UDFLoader.scalarUDFs.get(funcName).implement(inputs);
6661
}
6762

68-
public static String translateScalar(String funcName, String dataSource, List<String> inputs) {
69-
if (!UDFLoader.scalarUDFs.containsKey(funcName)) {
70-
LOG.error("Unsupported scalar UDF {}", funcName);
71-
throw new RuntimeException("Unsupported scalar UDF");
72-
}
73-
return UDFLoader.scalarUDFs.get(funcName).translate(dataSource, inputs);
74-
}
75-
7663
public static ColumnType getScalarOutType(String funcName, List<Expression> inputs) {
7764
return UDFLoader.scalarUDFs.get(funcName)
7865
.getOutType(inputs.stream().map(in -> in.getOutType()).collect(Collectors.toList()));

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<module>platform</module>
2424
<module>proto</module>
2525
<module>rpc</module>
26+
<module>udf</module>
2627
</modules>
2728

2829
<properties>

scripts/build/package.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ if [ $# -eq 0 ]; then
88
mvn clean install -T ${thread} -Dmaven.test.skip=true
99
mkdir -p ./release/bin
1010
mkdir -p ./release/adapter
11+
mkdir -p ./release/udf/scalar
1112
cp owner/target/*-with-dependencies.jar ./release/bin/owner_server.jar
1213
cp adapter/adapter-csv/target/*-with-dependencies.jar ./release/adapter/adapter_csv.jar
14+
cp udf/spatial-udf/target/*-with-dependencies.jar ./release/udf/scalar/spatial_udf.jar
1315
elif [ $1 == "owner" ]; then
1416
mvn install -T ${thread} -Dmaven.test.skip=true -pl $1
1517
cp owner/target/*-with-dependencies.jar ./release/bin/onedb_owner_server.jar
1618
elif [ $1 == "adapter" ]; then
1719
mvn install -T ${thread} -Dmaven.test.skip=true -pl $1
1820
cp adapter/adapter-csv/target/*-with-dependencies.jar ./release/adapter/adapter_csv.jar
21+
elif [ $1 == "udf" ]; then
22+
mvn install -T ${thread} -Dmaven.test.skip=true -pl $1
23+
cp udf/spatial-udf/target/*-with-dependencies.jar ./release/udf/scalar/spatial_udf.jar
1924
elif [ $1 == "benchmark" ]; then
2025
mvn install -T ${thread} -Dmaven.test.skip=true -pl $1
2126
else

0 commit comments

Comments
 (0)