-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
318 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
calcite-testing/src/main/java/com/xsmartware/common/calcite/CalCiteDataQueryThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
|
||
} |
54 changes: 0 additions & 54 deletions
54
calcite-testing/src/main/java/com/xsmartware/common/calcite/CalCiteTestThread.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
calcite-testing/src/main/java/com/xsmartware/common/calcite/CalciteDataLoaderThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
calcite-testing/src/main/java/com/xsmartware/common/calcite/DataHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
calcite-testing/src/main/java/com/xsmartware/common/calcite/DataLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
calcite-testing/src/test/java/com/xsmartware/testing/calcite/Test2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.