Skip to content

Commit

Permalink
Merge pull request #117 from cirnoooo123/main
Browse files Browse the repository at this point in the history
init spatialTestBench
  • Loading branch information
SongY123 authored Feb 27, 2023
2 parents 4f6f108 + 5dec0ed commit 71d4377
Show file tree
Hide file tree
Showing 15 changed files with 3,437 additions and 188 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.hufudb.openhufu.benchmark.enums;

import java.util.HashSet;
import java.util.Set;

/**
* @author yang.song
* @date 2/15/23 1:45 AM
*/
public enum SpatialTableName {
SPATIAL("spatial");
SpatialTableName(String name) {
this.name = name;
}
private final String name;
private static final Set<SpatialTableName> tableNameSet;

static {
tableNameSet = new HashSet<>();
tableNameSet.add(SPATIAL);
}

public String getName() {
return name;
}

public Set<SpatialTableName> getSpatialTableNames() {
return tableNameSet;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.hufudb.openhufu.benchmark;

import com.google.common.collect.ImmutableList;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.hufudb.openhufu.benchmark.enums.SpatialTableName;
import com.hufudb.openhufu.benchmark.enums.TPCHTableName;
import com.hufudb.openhufu.core.table.GlobalTableConfig;
import com.hufudb.openhufu.data.schema.Schema;
import com.hufudb.openhufu.data.storage.DataSet;
import com.hufudb.openhufu.data.storage.DataSetIterator;
import com.hufudb.openhufu.expression.AggFuncType;
import com.hufudb.openhufu.expression.ExpressionFactory;
import com.hufudb.openhufu.owner.user.OpenHuFuUser;
import com.hufudb.openhufu.plan.BinaryPlan;
import com.hufudb.openhufu.plan.LeafPlan;
import com.hufudb.openhufu.proto.OpenHuFuData.ColumnType;
import com.hufudb.openhufu.proto.OpenHuFuData.Modifier;
import com.hufudb.openhufu.proto.OpenHuFuPlan;
import com.hufudb.openhufu.proto.OpenHuFuPlan.Collation;
import com.hufudb.openhufu.proto.OpenHuFuPlan.JoinCondition;
import com.hufudb.openhufu.proto.OpenHuFuPlan.JoinType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class OpenHuFuSpatialBenchmarkTest {
private static final Logger LOG = LoggerFactory.getLogger(OpenHuFuBenchmark.class);
private static final OpenHuFuUser user = new OpenHuFuUser();

@BeforeClass
public static void setUp() throws IOException {

List<String> endpoints =
new Gson().fromJson(Files.newBufferedReader(
Path.of(OpenHuFuBenchmark.class.getClassLoader().getResource("spatialEndpoints.json")
.getPath())),
new TypeToken<ArrayList<String>>() {
}.getType());
List<GlobalTableConfig> globalTableConfigs =
new Gson().fromJson(Files.newBufferedReader(
Path.of(OpenHuFuBenchmark.class.getClassLoader().getResource("spatialTables.json")
.getPath())),
new TypeToken<ArrayList<GlobalTableConfig>>() {
}.getType());
LOG.info("Init benchmark of OpenHuFuSpatial...");
for (String endpoint : endpoints) {
user.addOwner(endpoint, null);
}

for (GlobalTableConfig config : globalTableConfigs) {
user.createOpenHuFuTable(config);
}
LOG.info("Init finish");
}

@Test
public void testSelect() {
String tableName = SpatialTableName.SPATIAL.getName();
LeafPlan plan = new LeafPlan();
plan.setTableName(tableName);
plan.setSelectExps(ExpressionFactory
.createInputRef(user.getOpenHuFuTableSchema(tableName).getSchema()));
DataSet dataset = user.executeQuery(plan);
DataSetIterator it = dataset.getIterator();
long count = 0;
while (it.next()) {
for (int i = 0; i < it.size(); i++) {
System.out.print(it.get(i) + "|");
}
System.out.println();
++count;
}
assertEquals(3000, count);
dataset.close();
}

}
5 changes: 5 additions & 0 deletions benchmark/src/test/resources/spatialEndpoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"localhost:12345",
"localhost:12346",
"localhost:12347"
]
19 changes: 19 additions & 0 deletions benchmark/src/test/resources/spatialTables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"tableName": "spatial",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "spatial"
},
{
"endpoint": "localhost:12346",
"localName": "spatial"
},
{
"endpoint": "localhost:12347",
"localName": "spatial"
}
]
}
]
Loading

0 comments on commit 71d4377

Please sign in to comment.