Skip to content

Commit 1afb77d

Browse files
committed
WIP Convex SQL baseline
1 parent 32e304c commit 1afb77d

File tree

7 files changed

+174
-11
lines changed

7 files changed

+174
-11
lines changed

convex-peer/src/main/java/convex/peer/Server.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ private Server(HashMap<Keyword, Object> config) throws ConfigException {
147147
}
148148

149149
}
150+
151+
/**
152+
* Creates a new (unlaunched) Server with a given config.
153+
*
154+
* @param config Server configuration map. Will be defensively copied.
155+
*
156+
* @return New Server instance
157+
* @throws ConfigException If Peer configuration failed, possible multiple causes
158+
*/
159+
public static Server create(HashMap<Keyword, Object> config) throws ConfigException {
160+
return new Server(new HashMap<>(config));
161+
}
150162

151163
// This doesn't actually do anything useful? Do we need this?
152164
// /**
@@ -294,17 +306,7 @@ private long establishTimeout() {
294306
return Utils.toInt(maybeTimeout);
295307
}
296308

297-
/**
298-
* Creates a new (unlaunched) Server with a given config.
299-
*
300-
* @param config Server configuration map. Will be defensively copied.
301-
*
302-
* @return New Server instance
303-
* @throws ConfigException If Peer configuration failed, possible multiple causes
304-
*/
305-
public static Server create(HashMap<Keyword, Object> config) throws ConfigException {
306-
return new Server(new HashMap<>(config));
307-
}
309+
308310

309311
private void observeMessageReceived(Message m) {
310312
Consumer<Message> obs=messageReceiveObserver;

convex-sql/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>world.convex</groupId>
7+
<artifactId>convex</artifactId>
8+
<version>0.8.2-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>convex-sql</artifactId>
11+
<name>Convex SQL</name>
12+
<description>An SQL database implementation based on lattice technology</description>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.apache.calcite</groupId>
17+
<artifactId>calcite-core</artifactId>
18+
<version>1.41.0</version>
19+
</dependency>
20+
21+
22+
<dependency>
23+
<groupId>world.convex</groupId>
24+
<artifactId>convex-core</artifactId>
25+
<version>${convex.version}</version>
26+
<scope>compile</scope>
27+
</dependency>
28+
29+
<!-- Testing -->
30+
<dependency>
31+
<groupId>org.slf4j</groupId>
32+
<artifactId>slf4j-simple</artifactId>
33+
<version>${slf4j.version}</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.slf4j</groupId>
38+
<artifactId>slf4j-api</artifactId>
39+
<version>${slf4j.version}</version>
40+
</dependency>
41+
42+
<!-- Testing -->
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-engine</artifactId>
46+
<version>${junit.version}</version>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter-api</artifactId>
52+
<version>${junit.version}</version>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package convex.sql;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.ResultSet;
6+
import java.sql.Statement;
7+
import java.util.Properties;
8+
9+
import org.apache.calcite.jdbc.CalciteConnection;
10+
import org.apache.calcite.schema.Schema;
11+
import org.apache.calcite.schema.SchemaPlus;
12+
13+
import convex.sql.adapater.ConvexSchema;
14+
15+
public class Demo {
16+
17+
@SuppressWarnings("null")
18+
public static void main(String[] args) throws Exception {
19+
Class.forName("org.apache.calcite.jdbc.Driver");
20+
21+
Properties info = new Properties();
22+
info.setProperty("lex", "JAVA");
23+
Connection connection =
24+
DriverManager.getConnection("jdbc:calcite:", info);
25+
CalciteConnection calciteConnection =
26+
connection.unwrap(CalciteConnection.class);
27+
SchemaPlus rootSchema = calciteConnection.getRootSchema();
28+
Schema schema = new ConvexSchema();
29+
rootSchema.add("convex", schema);
30+
// Schema schema = new ReflectiveSchema(new HrSchema());
31+
32+
Statement statement = calciteConnection.createStatement();
33+
// ResultSet resultSet = statement.executeQuery("select * from convex.table1");
34+
35+
//System.out.println(resultSet);
36+
System.out.println("Done");
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package convex.sql.adapater;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.apache.calcite.schema.Table;
7+
import org.apache.calcite.schema.impl.AbstractSchema;
8+
9+
public class ConvexSchema extends AbstractSchema {
10+
11+
private Map<String, Table> tableMap;
12+
13+
@Override protected Map<String, Table> getTableMap() {
14+
if (tableMap == null) {
15+
tableMap = createTableMap();
16+
}
17+
return tableMap;
18+
}
19+
20+
private Map<String, Table> createTableMap() {
21+
HashMap<String,Table> m=new HashMap<>();
22+
m.put("table1", new ConvexTable());
23+
return m;
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package convex.sql.adapater;
2+
3+
import java.util.Map;
4+
5+
import org.apache.calcite.schema.Schema;
6+
import org.apache.calcite.schema.SchemaFactory;
7+
import org.apache.calcite.schema.SchemaPlus;
8+
9+
public class ConvexSchemaFactory implements SchemaFactory {
10+
11+
public static final ConvexSchemaFactory INSTANCE = new ConvexSchemaFactory();
12+
13+
private ConvexSchemaFactory() {
14+
15+
}
16+
17+
@Override
18+
public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) {
19+
20+
21+
return new ConvexSchema();
22+
}
23+
24+
25+
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package convex.sql.adapater;
2+
3+
import org.apache.calcite.rel.type.RelDataType;
4+
import org.apache.calcite.rel.type.RelDataTypeFactory;
5+
import org.apache.calcite.schema.impl.AbstractTable;
6+
7+
public class ConvexTable extends AbstractTable {
8+
9+
@Override
10+
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
11+
// TODO Auto-generated method stub
12+
return null;
13+
}
14+
15+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<module>convex-java</module>
2222
<module>convex-restapi</module>
2323
<module>convex-integration</module>
24+
<module>convex-sql</module>
2425
</modules>
2526

2627
<properties>

0 commit comments

Comments
 (0)