Skip to content

Commit

Permalink
move test dataset and fix junit test
Browse files Browse the repository at this point in the history
  • Loading branch information
SongY123 committed Feb 24, 2023
1 parent 5ab2dfc commit fd569a6
Show file tree
Hide file tree
Showing 29 changed files with 555 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -42,7 +40,7 @@ public class CsvAdapterTest {

@Test
public void testLoadSingleFile() {
URL source = CsvAdapterTest.class.getClassLoader().getResource("data/test1.csv");
URL source = CsvAdapterTest.class.getClassLoader().getResource("data");
CsvAdapterFactory factory = new CsvAdapterFactory();
AdapterConfig config = new AdapterConfig();
config.url = source.getPath();
Expand All @@ -51,8 +49,14 @@ public void testLoadSingleFile() {
Adapter adapter = factory.create(config);
SchemaManager manager = adapter.getSchemaManager();
List<TableSchema> schemas = manager.getAllLocalTable();
assertEquals(1, schemas.size());
assertEquals("test1", schemas.get(0).getName());
assertEquals(4, schemas.size());
assertEquals(new HashSet<>() {{
add("test1");
add("test2");
add("test3");
add("test4");
}},
schemas.stream().map(TableSchema::getName).collect(Collectors.toSet()));
}

@Test
Expand Down Expand Up @@ -92,8 +96,8 @@ public void testQuery() {
t4.setActualName("test4");
t4.setPublishedName("traffic");
t4.setPublishedColumns(ImmutableList.of(
new PojoColumnDesc("id", ColumnTypeWrapper.INT, ModifierWrapper.PUBLIC, 0),
new PojoColumnDesc("location", ColumnTypeWrapper.POINT, ModifierWrapper.PUBLIC, 1)));
new PojoColumnDesc("id", ColumnTypeWrapper.INT, ModifierWrapper.PUBLIC, 0),
new PojoColumnDesc("location", ColumnTypeWrapper.POINT, ModifierWrapper.PUBLIC, 1)));
manager.addPublishedTable(t1);
manager.addPublishedTable(t2);
manager.addPublishedTable(t3);
Expand Down Expand Up @@ -198,7 +202,7 @@ public void testQuery() {
date.set(Calendar.YEAR, 2018);
date.set(Calendar.MONTH, 8); // Note: calendar month starts with 0
date.set(Calendar.DAY_OF_MONTH, 1);
Expression dateCmp = ExpressionFactory.createBinaryOperator(OperatorType.LT, ColumnType.BOOLEAN,
Expression dateCmp = ExpressionFactory.createBinaryOperator(OperatorType.LT, ColumnType.BOOLEAN,
ExpressionFactory.createInputRef(1, ColumnType.DATE, Modifier.PUBLIC),
ExpressionFactory.createLiteral(ColumnType.DATE, date));
plan.setWhereExps(ImmutableList.of(dateCmp));
Expand All @@ -218,7 +222,7 @@ public void testQuery() {
time.set(Calendar.HOUR_OF_DAY, 10);
time.set(Calendar.MINUTE, 14);
time.set(Calendar.SECOND, 45);
Expression timeCmp = ExpressionFactory.createBinaryOperator(OperatorType.LT, ColumnType.BOOLEAN,
Expression timeCmp = ExpressionFactory.createBinaryOperator(OperatorType.LT, ColumnType.BOOLEAN,
ExpressionFactory.createInputRef(2, ColumnType.TIME, Modifier.PUBLIC),
ExpressionFactory.createLiteral(ColumnType.TIME, time));
plan.setWhereExps(ImmutableList.of(timeCmp));
Expand All @@ -241,9 +245,9 @@ public void testQuery() {
ts.set(Calendar.HOUR_OF_DAY, 9);
ts.set(Calendar.MINUTE, 5);
ts.set(Calendar.SECOND, 10);
Expression tsCmp = ExpressionFactory.createBinaryOperator(OperatorType.GE, ColumnType.BOOLEAN,
ExpressionFactory.createInputRef(3, ColumnType.TIMESTAMP, Modifier.PUBLIC),
ExpressionFactory.createLiteral(ColumnType.TIMESTAMP, ts));
Expression tsCmp = ExpressionFactory.createBinaryOperator(OperatorType.GE, ColumnType.BOOLEAN,
ExpressionFactory.createInputRef(3, ColumnType.TIMESTAMP, Modifier.PUBLIC),
ExpressionFactory.createLiteral(ColumnType.TIMESTAMP, ts));
plan.setWhereExps(ImmutableList.of(tsCmp));
result = adapter.query(plan);
it = result.getIterator();
Expand Down Expand Up @@ -273,28 +277,4 @@ public void testQuery() {
assertFalse(it.next());
result.close();
}

@Test
public void testLoadDir() {
Set<String> tableNames = new HashSet<>(){{
add("customer");
add("lineitem");
add("nation");
add("orders");
add("part");
add("partsupp");
add("region");
add("supplier");
}};
URL source = CsvAdapterTest.class.getClassLoader().getResource("tpc-h");
CsvAdapterFactory factory = new CsvAdapterFactory();
AdapterConfig config = new AdapterConfig();
config.url = source.getPath();
config.datasource = DataSourceType.CSV;
config.delimiter = "|";
Adapter adapter = factory.create(config);
SchemaManager manager = adapter.getSchemaManager();
List<TableSchema> schemas = manager.getAllLocalTable();
assertEquals(tableNames, schemas.stream().map(TableSchema::getName).collect(Collectors.toSet()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
public class CsvTableTest {
@Test
public void testScanWithSchema() throws IOException {
URL source = CsvTableTest.class.getClassLoader().getResource("data/test2.csv");
CsvTable table = new CsvTable("test2", null, Paths.get(source.getPath()), ",");
URL data = CsvTableTest.class.getClassLoader().getResource("data/test2.csv");
URL schema = CsvTableTest.class.getClassLoader().getResource("data/test2.scm");
CsvTable table = new CsvTable("test2", Paths.get(schema.getPath()), Paths.get(data.getPath()), ",");
Schema.Builder builder = Schema.newBuilder();
builder.add("Department", ColumnType.STRING, Modifier.PUBLIC);
builder.add("Name", ColumnType.STRING, Modifier.PUBLIC);
Expand Down
2 changes: 2 additions & 0 deletions adapter/adapter-csv/src/test/resources/data/test1.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
age, workclass, fnlwgt, education, education-num, marital-status, occupation, relationship, race, sex, capital-gain, capital-loss, hours-per-week, native-country, income
INT, STRING, LONG, STRING, INT, STRING, STRING, STRING, STRING, STRING, INT, INT, INT, STRING, STRING
2 changes: 2 additions & 0 deletions adapter/adapter-csv/src/test/resources/data/test2.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name, age, score, dept_name, weight
STRING, INT, INT, STRING, DOUBLE
2 changes: 2 additions & 0 deletions adapter/adapter-csv/src/test/resources/data/test3.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
license, cur_date, cur_time, time_stamp
LONG, DATE, TIME, TIMESTAMP
2 changes: 2 additions & 0 deletions adapter/adapter-csv/src/test/resources/data/test4.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,location
INT, POINT
119 changes: 119 additions & 0 deletions benchmark/src/main/resources/tables.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
[
{
"tableName": "customer",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "customer"
},
{
"endpoint": "localhost:12346",
"localName": "customer"
},
{
"endpoint": "localhost:12347",
"localName": "customer"
}
]
},
{
"tableName": "lineitem",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "lineitem"
},
{
"endpoint": "localhost:12346",
"localName": "lineitem"
},
{
"endpoint": "localhost:12347",
"localName": "lineitem"
}
]
},
{
"tableName": "nation",
"localTables": [
Expand All @@ -15,5 +49,90 @@
"localName": "nation"
}
]
},
{
"tableName": "orders",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "orders"
},
{
"endpoint": "localhost:12346",
"localName": "orders"
},
{
"endpoint": "localhost:12347",
"localName": "orders"
}
]
},
{
"tableName": "part",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "part"
},
{
"endpoint": "localhost:12346",
"localName": "part"
},
{
"endpoint": "localhost:12347",
"localName": "part"
}
]
},
{
"tableName": "partsupp",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "partsupp"
},
{
"endpoint": "localhost:12346",
"localName": "partsupp"
},
{
"endpoint": "localhost:12347",
"localName": "partsupp"
}
]
},
{
"tableName": "region",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "region"
},
{
"endpoint": "localhost:12346",
"localName": "region"
},
{
"endpoint": "localhost:12347",
"localName": "region"
}
]
},
{
"tableName": "supplier",
"localTables": [
{
"endpoint": "localhost:12345",
"localName": "supplier"
},
{
"endpoint": "localhost:12346",
"localName": "supplier"
},
{
"endpoint": "localhost:12347",
"localName": "supplier"
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ public enum ErrorCode implements BaseErrorCode {
INTERNAL_SERVER_ERROR(10001),

// config error
IMPLEMENTOR_CONFIG_MISSING(20001),
IMPLEMENTOR_CLASS_NOT_FOUND(20002),
IMPLEMENTOR_CONSTRUCTOR_NOT_FOUND(20003),
IMPLEMENTOR_CREATE_FAILED(20004),

CSV_URL_NOT_EXISTS(20005),
CSV_URL_IS_NOT_FOLDER(20006),
OPENHUFU_ROOT_ENV_NOT_SET(20001),
ADAPTER_FOLDER_NOT_FOUND(20001),
IMPLEMENTOR_CONFIG_MISSING(20031),
IMPLEMENTOR_CLASS_NOT_FOUND(20032),
IMPLEMENTOR_CONSTRUCTOR_NOT_FOUND(20033),
IMPLEMENTOR_CREATE_FAILED(20034),
CSV_URL_NOT_EXISTS(20035),
CSV_URL_IS_NOT_FOLDER(20036),

// udf error
UDF_LOAD_FAILED(30001),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hufudb.openhufu.owner.config;

import com.hufudb.openhufu.common.enums.DataSourceType;
import com.hufudb.openhufu.common.exception.ErrorCode;
import com.hufudb.openhufu.common.exception.OpenHuFuException;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -55,7 +57,14 @@ public OwnerConfigFile(int id, int port, int threadnum, String hostname, String
public OwnerConfigFile() {}

public static Adapter getAdapter(AdapterConfig config) {
Path adapterDir = Paths.get(System.getenv("OPENHUFU_ROOT"), "adapter");
String openHuFuRoot = System.getenv("OPENHUFU_ROOT");
if (null == openHuFuRoot || openHuFuRoot.length() == 0) {
throw new OpenHuFuException(ErrorCode.OPENHUFU_ROOT_ENV_NOT_SET);
}
Path adapterDir = Paths.get(openHuFuRoot, "adapter");
if (!adapterDir.toFile().exists()) {
throw new OpenHuFuException(ErrorCode.ADAPTER_FOLDER_NOT_FOUND);
}
Map<DataSourceType, AdapterFactory> adapterFactories =
AdapterLoader.loadAdapters(adapterDir.toString());
AdapterFactory factory = adapterFactories.get(config.datasource);
Expand Down
Loading

0 comments on commit fd569a6

Please sign in to comment.