use of com.srotya.sidewinder.core.storage.mem.MemStorageEngine in project sidewinder by srotya.
the class TestSchemaAndBasicQueries method testCalciteLocalParameters.
@Test
public void testCalciteLocalParameters() throws Exception {
StorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), null);
long ts = System.currentTimeMillis();
for (int i = 0; i < 10000; 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;schema.maxResult=500");
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(500, c);
st.close();
connection.close();
connection = DriverManager.getConnection("jdbc:calcite:schemaFactory=com.srotya.sidewinder.core.sql.calcite.SidewinderSchemaFactory");
st = connection.createStatement();
rset = st.executeQuery("select * from db12.m12");
c = 0;
assertEquals(3, rset.getMetaData().getColumnCount());
while (rset.next()) {
assertEquals(ts + c * 100, rset.getLong(1));
assertEquals(c, rset.getLong(2));
c++;
}
assertEquals(1000, c);
st.close();
connection.close();
}
use of com.srotya.sidewinder.core.storage.mem.MemStorageEngine in project sidewinder by srotya.
the class TestSchemaAndBasicQueries method testFunctions.
@Test
public void testFunctions() throws Exception {
StorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), null);
long ts = System.currentTimeMillis();
for (int i = 0; i < 10000; 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 totime(ts) from db12.m12");
int c = 0;
while (rset.next()) {
assertEquals(Timestamp.from(Instant.ofEpochMilli(ts + c * 100)), rset.getTimestamp(1));
c++;
}
rset.close();
rset = st.executeQuery("select tolong(totime(ts)) from db12.m12");
c = 0;
while (rset.next()) {
assertEquals(ts + c * 100, rset.getLong(1));
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 testDatabaseSchema.
@Test
public void testDatabaseSchema() throws Exception {
Map<String, Schema> map = new HashMap<>();
when(parent.add(Matchers.anyString(), Matchers.any(Schema.class))).then(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
map.put(invocation.getArgument(0), invocation.getArgument(1));
return null;
}
});
StorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), null);
engine.getOrCreateMeasurement("db1", "m1");
SidewinderDatabaseSchema schema = new SidewinderDatabaseSchema(engine, parent, 100);
assertEquals(0, schema.getTableNames().size());
assertEquals(1, map.size());
assertEquals("DB1", map.keySet().iterator().next());
Schema next = map.values().iterator().next();
Set<String> tableNames = next.getTableNames();
assertEquals(1, tableNames.size());
assertEquals("M1", tableNames.iterator().next());
}
Aggregations