use of com.srotya.sidewinder.core.storage.mem.MemStorageEngine in project sidewinder by srotya.
the class CalciteTest method main.
public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
ScheduledExecutorService bgt = Executors.newScheduledThreadPool(1, new BackgrounThreadFactory("sidewinderbg-tasks"));
MemStorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), bgt);
SqlApi api = new SqlApi(engine);
api.initCalcite();
long ts = System.currentTimeMillis();
TimeSeries s = engine.getOrCreateTimeSeries("db1", "m1", "v1", Arrays.asList("t=1", "p=2"), 1024, false);
for (int i = 0; i < 100; i++) {
s.addDataPoint(TimeUnit.MILLISECONDS, ts + i * 1000, i);
}
String queryResults = api.queryResults("db1", "select * from db1.m1 where time_stamp>1519945488603");
System.out.println(queryResults);
}
use of com.srotya.sidewinder.core.storage.mem.MemStorageEngine in project sidewinder by srotya.
the class TestSchemaAndBasicQueries method testCalciteLocalSelect.
@Test
public void testCalciteLocalSelect() throws Exception {
StorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), null);
long ts = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
engine.writeDataPointWithLock(MiscUtils.buildDataPoint("db12", "m12", "v1", Arrays.asList(Tag.newBuilder().setTagKey("k1").setTagValue("v1").build()), ts + i * 100, i), true);
}
SidewinderServer.setStorageEngine(engine);
Connection connection = DriverManager.getConnection("jdbc:calcite:schemaFactory=com.srotya.sidewinder.core.sql.calcite.SidewinderSchemaFactory");
Statement st = connection.createStatement();
ResultSet rset = st.executeQuery("select * from db12.m12");
int c = 0;
assertEquals(3, rset.getMetaData().getColumnCount());
while (rset.next()) {
assertEquals(ts + c * 100, rset.getLong(1));
assertEquals(c, rset.getLong(2));
c++;
}
assertEquals(100, c);
rset.close();
rset = st.executeQuery("select count(*) from db12.m12");
assertTrue(rset.next());
assertEquals(100, rset.getLong(1));
rset.close();
rset = st.executeQuery("select v1, ts from db12.m12");
assertEquals(2, rset.getMetaData().getColumnCount());
c = 0;
while (rset.next()) {
assertEquals(ts + c * 100, rset.getLong(2));
assertEquals(c, rset.getLong(1));
c++;
}
rset.close();
rset = st.executeQuery("select ts,v1,k1 from db12.m12");
assertEquals(3, rset.getMetaData().getColumnCount());
c = 0;
while (rset.next()) {
assertEquals(ts + c * 100, rset.getLong(1));
assertEquals(c, rset.getLong(2));
assertEquals("v1", rset.getString(3));
c++;
}
rset.close();
st.close();
connection.close();
}
use of com.srotya.sidewinder.core.storage.mem.MemStorageEngine in project sidewinder by srotya.
the class TestSchemaAndBasicQueries method testCalciteLocalConnection.
@Test
public void testCalciteLocalConnection() throws SQLException, IOException, InterruptedException {
StorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), null);
engine.getOrCreateMeasurement("db1", "m1");
SidewinderServer.setStorageEngine(engine);
Connection connection = DriverManager.getConnection("jdbc:calcite:schemaFactory=com.srotya.sidewinder.core.sql.calcite.SidewinderSchemaFactory");
Statement st = connection.createStatement();
st.executeQuery("select * from DB1.M1");
// query must succeed without any failures
st.close();
DatabaseMetaData metaData = connection.getMetaData();
ResultSet rs = metaData.getTables(null, null, "%", null);
int c = 0;
while (rs.next()) {
if (!rs.getString(2).equalsIgnoreCase("metadata") && !rs.getString(2).equalsIgnoreCase("_internal")) {
assertEquals("DB1", rs.getString(2));
assertEquals("M1", rs.getString(3));
c++;
}
}
assertEquals(1, c);
connection.close();
engine.getOrCreateMeasurement("db1", "m2");
connection = DriverManager.getConnection("jdbc:calcite:schemaFactory=com.srotya.sidewinder.core.sql.calcite.SidewinderSchemaFactory");
metaData = connection.getMetaData();
rs = metaData.getTables(null, null, "%", null);
c = 0;
while (rs.next()) {
if (!rs.getString(2).equalsIgnoreCase("metadata") && !rs.getString(2).equalsIgnoreCase("_internal")) {
c++;
}
}
assertEquals(2, c);
connection.close();
}
use of com.srotya.sidewinder.core.storage.mem.MemStorageEngine in project sidewinder by srotya.
the class TestMappedSetTagIndex method before.
@BeforeClass
public static void before() throws IOException {
engine = new MemStorageEngine();
engine.configure(new HashMap<>(), Executors.newScheduledThreadPool(1));
}
use of com.srotya.sidewinder.core.storage.mem.MemStorageEngine in project sidewinder by srotya.
the class TestMeasurement method before.
@Before
public void before() throws InstantiationException, IllegalAccessException, IOException {
MiscUtils.delete(new File("target/measurement-common"));
engine = new MemStorageEngine();
engine.configure(new HashMap<>(), bgTaskPool);
dataDir = "target/measurement-common/data";
indexDir = "target/measurement-common/index";
measurement = clazz.newInstance();
}
Aggregations