Skip to content

Commit

Permalink
test-data-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
guxiaobo committed Feb 27, 2022
1 parent e0f4ca4 commit 7de9b8f
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 58 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ calcite-testing/.DS_Store
calcite-testing/.classpath
calcite-testing/.project

data-loader/.settings/
data-loader/target/
data-loader/.DS_Store
data-loader/.classpath
data-loader/.project


Binary file added calcite-testing/lib/data-loader-0.0.1.jar
Binary file not shown.
30 changes: 27 additions & 3 deletions calcite-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
<java.version>9</java.version>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
<log4j2.version>2.17.1</log4j2.version>
<drools.version>7.64.0.Final</drools.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>json-adapter</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -51,17 +58,34 @@
<artifactId>calcite-example-csv</artifactId>
<version>1.21.0</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>${drools.version}</version>
</dependency>

<!--
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.4</version><!--$NO-MVN-MAN-VER$-->
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>commons-compiler</artifactId>
<version>3.1.4</version><!--$NO-MVN-MAN-VER$-->
<version>3.1.4</version>
</dependency>

-->
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.xsmartware.common.calcite;

import java.sql.SQLException;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.tools.RelConversionException;
import org.apache.calcite.tools.ValidationException;

public class CalCiteDataQueryThread extends Thread{
DataHolder holder;
int loop;


public CalCiteDataQueryThread(DataHolder holder, int loop) {
this.holder = holder;
this.loop = loop;
}

@Override
public void run() {
try {
//Thread.currentThread().sleep(100);
System.out.println("Thread " + Thread.currentThread().getId() + " start .");
long t1 = System.currentTimeMillis();
for(int i = 0; i < loop ; i++) {
query();
}
long t2 = System.currentTimeMillis();
System.out.println("Thread " + Thread.currentThread().getId() + " finished in ms :" + (t2 - t1));
} catch (Exception e) {
e.printStackTrace();
}

}

private void query() throws SQLException, ValidationException, SqlParseException, RelConversionException{
String sql1 = "select count(*) from t1";
String sql2 = "select count(*) from js.t1";
System.out.println("sql1 result " + holder.db.exeGetLong(sql1));
System.out.println("sql2 result " + holder.db.exeGetLong(sql2));
System.out.println("c1 = " + holder.db.exeGetLong("select max(c1) from js.t1"));
System.out.println("c2 = " + holder.db.exeGetString( "select c2 from js.t1 limit 1"));
System.out.println("c3 = " + holder.db.exeGetBoolean( "select c3 from js.t1 limit 1"));
System.out.println("c4 = " + holder.db.exeGetDecimal( "select c4 from js.t1 limit 1"));
System.out.println("c5 = " + holder.db.exeGetDate( "select c5 from js.t1 limit 1"));
System.out.println("c6 = " + holder.db.exeGetTimestamp( "select c6 from js.t1 limit 1"));
System.out.println("c7 = " + holder.db.exeGetInteger( "select c7 from js.t1 limit 1"));
System.out.println("c8 as float = " + holder.db.exeGetFloat( "select c8 from js.t1 limit 1"));
System.out.println("c9 as float = " + holder.db.exeGetFloat( "select c9 from js.t1 limit 1"));
System.out.println("c8 as double = " + holder.db.exeGetDouble( "select c8 from js.t1 limit 1"));
System.out.println("c9 as double = " + holder.db.exeGetDouble( "select c9 from js.t1 limit 1"));
System.out.println("c10 = " +holder.db.exeGetTime( "select c10 from js.t1 limit 1"));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.xsmartware.common.calcite;

public class CalciteDataLoaderThread extends Thread{

DataHolder holder ;

public CalciteDataLoaderThread(DataHolder holder) {
this.holder = holder;
}

@Override
public void run() {
if(holder == null || holder.loader == null)
return;
try {
holder.db = holder.loader.loadData();
}catch(Throwable ex) {
ex.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.xsmartware.common.calcite;

public class DataHolder {
public DataLoader loader;
public CalciteDatabase db;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.xsmartware.common.calcite;

import java.sql.SQLException;

public interface DataLoader {

CalciteDatabase loadData()throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public DataObjSchema(DataObj[] data) {


@Test
public void Test1() throws SQLException, ValidationException,
public void test1() throws SQLException, ValidationException,
SqlParseException, RelConversionException {

Schema schema = new ReflectiveSchema(new DataObjSchema(data));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
package com.xsmartware.testing.calcite;

import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import org.junit.Test;
import com.xsmartware.common.calcite.CalCiteDataQueryThread;
import com.xsmartware.common.calcite.CalciteDataLoaderThread;
import com.xsmartware.common.calcite.DataHolder;
import com.xsmartware.common.calcite.DataLoader;


public class Test2 {


@Test
public void test2() {
DataHolder holder = new DataHolder();
DataLoader loader = null;
try {
loader = loadLoaderFromJar();
holder.loader = loader;

CalciteDataLoaderThread t1 = new CalciteDataLoaderThread(holder);
t1.start();
t1.join();
CalCiteDataQueryThread t2 = new CalCiteDataQueryThread(holder, 10);
t2.start();
t2.join();

}catch(Exception ex) {
ex.printStackTrace();
}


}


public DataLoader loadLoaderFromJar(){
String path = "lib" + File.separator + "data-loader-0.0.1.jar";
DataLoader loader = null;
try {
ClassLoader cl = URLClassLoader.newInstance(
new URL[] { new URL("jar:file:" + path + "!/") },
getClass().getClassLoader());
Class<?> clazz = Class.forName("com.xsmartware.testing.calcite.TestDataLoader", true, cl);
Class<? extends DataLoader> newClass = clazz.asSubclass(DataLoader.class);

Constructor<? extends DataLoader> constructor = newClass.getConstructor();
loader = (DataLoader) constructor.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return loader;
}

}
20 changes: 20 additions & 0 deletions data-loader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<!--
{% comment %}
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
-->
# testing code
67 changes: 67 additions & 0 deletions data-loader/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xsmartware</groupId>
<artifactId>data-loader</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>data-loader</name>
<description>data-loader</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<java.version>9</java.version>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.xsmartware</groupId>
<artifactId>calcite-testing</artifactId>
<version>0.0.1</version>
</dependency>

<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>json-adapter</artifactId>
<version>0.0.1</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>1.29.0</version>
</dependency>
<dependency>
<groupId>org.apache.calcite.avatica</groupId>
<artifactId>avatica-core</artifactId>
<version>1.20.0</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-file</artifactId>
<version>1.29.0</version>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-example-csv</artifactId>
<version>1.21.0</version>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 7de9b8f

Please sign in to comment.