forked from SQream/sqream-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjdbc.py
55 lines (46 loc) · 1.63 KB
/
jdbc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os, sys
from py4j.java_gateway import JavaGateway
from datetime import date, datetime
from time import time
# Load jvm connecting instance
jdbc_path = './target/SqreamJDBC.jar'
gateway = JavaGateway.launch_gateway(classpath=jdbc_path)
# Load SQream JDBC Driver
gateway.jvm.Class.forName("com.sqream.jdbc.SQDriver")
# Open a connection
jdbc_uri = 'jdbc:Sqream://127.0.0.1:5000/master;user=sqream;password=sqream'
# 'jdbc:Sqream://127.0.0.1:5000/master;user=sqream;password=sqream;cluster=false;ssl=false;service=bobo'
conn = gateway.jvm.java.sql.DriverManager.getConnection(jdbc_uri, "sqream", "sqream")
# Create table
sql = "create or replace table perf (bools bool, bytes tinyint, shorts smallint, ints int, bigints bigint, floats real, doubles double, strangs nvarchar(10))" #, dates date, dts datetime)"
stmt = conn.createStatement()
stmt.execute(sql)
stmt.close()
# Network insert 10 million rows
amount = 10**7
start = time()
sql = "insert into perf values (?, ?, ?, ?, ?, ?, ?, ?)"
ps = conn.prepareStatement(sql)
for _ in range(amount):
ps.setBoolean(1, True)
ps.setByte(2, 120)
ps.setShort(3, 1400)
ps.setInt(4, 140000)
ps.setLong(5, 5)
ps.setFloat(6, 56.0)
ps.setDouble(7, 57.0)
ps.setString(8, "bla")
# ps.setDate(9, date(2019, 11, 26))
# ps.setTimestamp(10, datetime(2019, 11, 26, 16, 45, 23, 45))
ps.addBatch()
ps.executeBatch()
ps.close()
print ("total network insert: ", (time() -start))
# Check amount inserted
sql = "select count(*) from perf"
stmt = conn.createStatement()
rs = stmt.executeQuery(sql)
while rs.next():
print("row count: ", rs.getLong(1))
rs.close()
stmt.close()