Skip to content

Commit f4fdb61

Browse files
zaiyuan-ljwabovzvChao Liangjimojimolonely
authored
迁移代码 (#18)
* rebase * 解决包名问题 * resolve the problems of packages'name * test for git (#20) * fix pom error * add test resource && mini hbase cluster for unit test * add mysql test server * refactor module; add test module; init hbase and mysql instance * add pom * mysql first * Update pom.xml * add maven exec build * add mysql dependency * Create ddl.sql * Delete test/embedded-mysql/src/main/java/resources directory * Create ddl.sql * use mysql image; build hbase image * fix pom * fix mysql hostname * fix mysql hostname * fix ci yml * fix mysql url * fix mysql init * fix ci yml * fix ci yml * build hbase docker image * init hbase each time * fix jdbc url * remove extra ddl.sql * fix assert * add unique index to ddl.sql add md5 to password remove prefix index of mysql Co-authored-by: zaiyuan49 <zhugeliang0511> Co-authored-by: 阿超stan <[email protected]> Co-authored-by: Chao Liang <[email protected]> Co-authored-by: jimo <[email protected]> Co-authored-by: jackpler <[email protected]> Co-authored-by: Leo <[email protected]>
1 parent 55b4ec2 commit f4fdb61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2211
-9
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ jobs:
1717
# The type of runner that the job will run on
1818
runs-on: ubuntu-20.04
1919

20+
services:
21+
mysql:
22+
image: mysql:5.7
23+
env:
24+
MYSQL_ROOT_PASSWORD: start_db
25+
MYSQL_USER: start_db
26+
MYSQL_PASSWORD: start_db
27+
MYSQL_DATABASE: meta_data
28+
ports:
29+
- 3306:3306
2030
# Steps represent a sequence of tasks that will be executed as part of the job
2131
steps:
2232
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
@@ -29,6 +39,11 @@ jobs:
2939
java-version: '8'
3040
cache: maven
3141
distribution: 'adopt'
42+
- name: init mysql schema
43+
run: mvn test exec:java -f test/embedded-mysql/pom.xml
44+
# - name: init hbase data
45+
# run:
46+
3247
# Runs a set of commands using the runners shell
3348
- name: build and test with maven
3449
run: |

core/pom.xml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>start-db</artifactId>
7+
<groupId>org.urbcomp</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>core</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>8</maven.compiler.source>
16+
<maven.compiler.target>8</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.apache.calcite</groupId>
22+
<artifactId>calcite-core</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.alibaba</groupId>
26+
<artifactId>fastjson</artifactId>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>com.google.guava</groupId>
31+
<artifactId>guava</artifactId>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.slf4j</groupId>
36+
<artifactId>slf4j-log4j12</artifactId>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.scalatest</groupId>
41+
<artifactId>scalatest_${scala.binary.version}</artifactId>
42+
<version>${scalatest.version}</version>
43+
<scope>test</scope>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.apache.hbase</groupId>
48+
<artifactId>hbase-client</artifactId>
49+
<version>${hbase.version}</version>
50+
<exclusions>
51+
<exclusion>
52+
<artifactId>protobuf-java</artifactId>
53+
<groupId>com.google.protobuf</groupId>
54+
</exclusion>
55+
<exclusion>
56+
<groupId>org.apache.curator</groupId>
57+
<artifactId>curator-framework</artifactId>
58+
</exclusion>
59+
<exclusion>
60+
<groupId>org.apache.curator</groupId>
61+
<artifactId>curator-recipes</artifactId>
62+
</exclusion>
63+
<exclusion>
64+
<groupId>org.apache.curator</groupId>
65+
<artifactId>curator-client</artifactId>
66+
</exclusion>
67+
</exclusions>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>org.apache.curator</groupId>
72+
<artifactId>curator-framework</artifactId>
73+
<version>${curator.version}</version>
74+
</dependency>
75+
76+
<!-- Geomesa Dependency -->
77+
<dependency>
78+
<groupId>org.locationtech.geomesa</groupId>
79+
<artifactId>geomesa-hbase-datastore_${scala.binary.version}</artifactId>
80+
<version>${geomesa.version}</version>
81+
<exclusions>
82+
<exclusion>
83+
<artifactId>protobuf-java</artifactId>
84+
<groupId>com.google.protobuf</groupId>
85+
</exclusion>
86+
</exclusions>
87+
</dependency>
88+
<dependency>
89+
<groupId>org.locationtech.geomesa</groupId>
90+
<artifactId>geomesa-filter_${scala.binary.version}</artifactId>
91+
<version>${geomesa.version}</version>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.locationtech.geomesa</groupId>
95+
<artifactId>geomesa-utils_${scala.binary.version}</artifactId>
96+
<version>${geomesa.version}</version>
97+
</dependency>
98+
<!-- Mybatis Core -->
99+
<dependency>
100+
<groupId>org.mybatis</groupId>
101+
<artifactId>mybatis</artifactId>
102+
<version>${mybatis.version}</version>
103+
</dependency>
104+
<!-- MySQL Driver -->
105+
<dependency>
106+
<groupId>mysql</groupId>
107+
<artifactId>mysql-connector-java</artifactId>
108+
<version>${mysql.connection.version}</version>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.locationtech.jts</groupId>
112+
<artifactId>jts-core</artifactId>
113+
<version>${jts.version}</version>
114+
</dependency>
115+
<dependency>
116+
<groupId>org.projectlombok</groupId>
117+
<artifactId>lombok</artifactId>
118+
<version>${lombok.version}</version>
119+
<scope>compile</scope>
120+
</dependency>
121+
<dependency>
122+
<groupId>junit</groupId>
123+
<artifactId>junit</artifactId>
124+
<version>${junit.version}</version>
125+
<scope>test</scope>
126+
</dependency>
127+
128+
<dependency>
129+
<groupId>org.apache.hbase</groupId>
130+
<artifactId>hbase-testing-util</artifactId>
131+
<version>2.2.2</version>
132+
</dependency>
133+
</dependencies>
134+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.urbcomp.start.db.constant;
2+
3+
/**
4+
* This is a constant class for config file
5+
*
6+
* @author zaiyuan
7+
* @date 2022-05-01 15:17:07
8+
*/
9+
public class ConfigFileConstant {
10+
public static final String MYBATIS_CONFIG_PATH = "mybatis-config.xml";
11+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.urbcomp.start.db.core.geomesa.model;
2+
3+
import org.apache.calcite.linq4j.tree.ConstantExpression;
4+
import org.apache.calcite.linq4j.tree.Primitive;
5+
import org.apache.calcite.plan.RelOptTable;
6+
import org.opengis.filter.Filter;
7+
8+
import java.lang.reflect.Type;
9+
10+
/**
11+
* This class is different from the native implementation of geotools, because the
12+
* native implementation of GeoTools does not java basic data types, so it cannot
13+
* be recognized in the expression parsing of linq4j.
14+
* @see ConstantExpression#ConstantExpression(Type, Object)
15+
* @see Primitive
16+
*
17+
* Therefore, we need to re encapsulate the query object of geotools. When we need
18+
* this information, we need to present it in the form of basic data types.
19+
*
20+
* @author zaiyuan
21+
* @date 2022-05-01 15:17:07
22+
*/
23+
public class GeomesaQuery {
24+
25+
/**
26+
* GeoTools Filter
27+
*/
28+
private Filter filter = Filter.INCLUDE;
29+
30+
/**
31+
* user name
32+
*/
33+
private String userName;
34+
35+
/**
36+
* db name
37+
*/
38+
private String dbName;
39+
40+
/**
41+
* table name
42+
*/
43+
private String tableName;
44+
45+
/**
46+
* RelNode Option of Table
47+
*/
48+
private RelOptTable relOptTable;
49+
50+
public Filter getFilter() {
51+
return filter;
52+
}
53+
54+
public void setFilter(Filter filter) {
55+
this.filter = filter;
56+
}
57+
58+
public String getUserName() {
59+
return userName;
60+
}
61+
62+
public void setUserName(String userName) {
63+
this.userName = userName;
64+
}
65+
66+
public String getDbName() {
67+
return dbName;
68+
}
69+
70+
public void setDbName(String dbName) {
71+
this.dbName = dbName;
72+
}
73+
74+
public RelOptTable getRelOptTable() {
75+
return relOptTable;
76+
}
77+
78+
public void setRelOptTable(RelOptTable relOptTable) {
79+
this.relOptTable = relOptTable;
80+
}
81+
82+
public String getTableName() {
83+
return tableName;
84+
}
85+
86+
public void setTableName(String tableName) {
87+
this.tableName = tableName;
88+
}
89+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.urbcomp.start.db.core.geomesa.rules;
2+
3+
import org.apache.calcite.plan.Convention;
4+
import org.apache.calcite.plan.RelOptRuleCall;
5+
import org.apache.calcite.plan.RelRule;
6+
import org.apache.calcite.plan.RelTraitSet;
7+
import org.apache.calcite.rel.logical.LogicalFilter;
8+
import org.urbcomp.start.db.geomesa.GeomesaConstant;
9+
import org.urbcomp.start.db.geomesa.rel.GeomesaFilter;
10+
import org.urbcomp.start.db.geomesa.rel.GeomesaTableScan;
11+
12+
/**
13+
* This class is used to match the specified filter rules, convert the original
14+
* query criteria into the filter object of geotools, and push down.
15+
*
16+
* @author zaiyuan
17+
* @date 2022-05-01 15:17:07
18+
*/
19+
public class GeomesaFilterRule extends RelRule<GeomesaFilterRule.Config> {
20+
21+
/**
22+
* Construct Function with One Parameter which is extended from super class.
23+
*/
24+
protected GeomesaFilterRule(Config config) {
25+
super(config);
26+
}
27+
28+
/**
29+
* Configuration of Filter Push Down Rule.
30+
*/
31+
public interface Config extends RelRule.Config {
32+
Config DEFAULT = EMPTY
33+
.withOperandSupplier(b0 ->
34+
b0.operand(LogicalFilter.class)
35+
.oneInput(b1 -> b1.operand(GeomesaTableScan.class)
36+
.noInputs()))
37+
.as(Config.class);
38+
39+
/**
40+
* Creates a rule that uses this configuration.
41+
*
42+
* @return GeomesaFilterRule Instance
43+
*/
44+
@Override
45+
default GeomesaFilterRule toRule() {
46+
return new GeomesaFilterRule(this);
47+
}
48+
}
49+
50+
/**
51+
* <p>Typically a rule would check that the nodes are registered and convert
52+
* calcite RexNode to Filter, creates a new expression.</p>
53+
*
54+
* @param call Rule call
55+
* @see #matches(RelOptRuleCall)
56+
*/
57+
@Override
58+
public void onMatch(RelOptRuleCall call) {
59+
LogicalFilter filter = call.rel(0);
60+
if (filter.getTraitSet().contains(Convention.NONE)) {
61+
RelTraitSet traits = filter.getTraitSet().replace(GeomesaConstant.CONVENTION());
62+
call.transformTo(new GeomesaFilter(filter.getCluster(),
63+
traits, convert(filter.getInput(), GeomesaConstant.CONVENTION()),
64+
filter.getRowType(),
65+
filter.getCondition()));
66+
}
67+
}
68+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.urbcomp.start.db.core.geomesa.rules;
2+
3+
import org.apache.calcite.adapter.enumerable.EnumerableConvention;
4+
import org.apache.calcite.plan.RelTraitSet;
5+
import org.apache.calcite.rel.RelNode;
6+
import org.apache.calcite.rel.convert.ConverterRule;
7+
import org.apache.calcite.rel.core.RelFactories;
8+
import org.apache.calcite.tools.RelBuilderFactory;
9+
import org.urbcomp.start.db.geomesa.GeomesaConstant;
10+
import org.urbcomp.start.db.geomesa.GeomesaToEnumeratorConverter;
11+
12+
import java.util.function.Predicate;
13+
14+
/**
15+
* This Rule is used to convert Geomesa Logic to Linq4J Enumerable
16+
*
17+
* @author zaiyuan
18+
* @date 2022-05-01 15:17:07
19+
*/
20+
public class GeomesaToEnumerableConverterRule extends ConverterRule {
21+
22+
/**
23+
* ConverterRule Instance
24+
*/
25+
public static final ConverterRule INSTANCE =
26+
new GeomesaToEnumerableConverterRule(RelFactories.LOGICAL_BUILDER);
27+
28+
/**
29+
* Construct Function with only One Parameter
30+
*
31+
* @param relBuilderFactory RelNoade Factory
32+
*/
33+
public GeomesaToEnumerableConverterRule(RelBuilderFactory relBuilderFactory) {
34+
super(RelNode.class, (Predicate<? super RelNode>) relNode -> true, GeomesaConstant.CONVENTION(),
35+
EnumerableConvention.INSTANCE, relBuilderFactory,
36+
"GeomesaToEnumerableConverterRule");
37+
}
38+
39+
/**
40+
* Convert RelNode to GeomesaToEnumeratorConverter
41+
*
42+
* @param rel RelNode
43+
* @return GeomesaToEnumeratorConverter
44+
*/
45+
@Override
46+
public RelNode convert(RelNode rel) {
47+
RelTraitSet newTraitSet = rel.getTraitSet().replace(getOutConvention());
48+
return new GeomesaToEnumeratorConverter(rel.getCluster(), newTraitSet, rel);
49+
}
50+
}

0 commit comments

Comments
 (0)