Search in sources :

Example 11 with MemStorageEngine

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();
}
Also used : Statement(java.sql.Statement) MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) Test(org.junit.Test)

Example 12 with MemStorageEngine

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();
}
Also used : Statement(java.sql.Statement) MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) Test(org.junit.Test)

Example 13 with MemStorageEngine

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());
}
Also used : HashMap(java.util.HashMap) SidewinderDatabaseSchema(com.srotya.sidewinder.core.sql.calcite.SidewinderDatabaseSchema) Schema(org.apache.calcite.schema.Schema) MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) SidewinderDatabaseSchema(com.srotya.sidewinder.core.sql.calcite.SidewinderDatabaseSchema) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) Test(org.junit.Test)

Aggregations

MemStorageEngine (com.srotya.sidewinder.core.storage.mem.MemStorageEngine)13 Test (org.junit.Test)7 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)6 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 Statement (java.sql.Statement)4 BeforeClass (org.junit.BeforeClass)4 SidewinderDatabaseSchema (com.srotya.sidewinder.core.sql.calcite.SidewinderDatabaseSchema)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 SqlApi (com.srotya.sidewinder.core.api.SqlApi)1 Builder (com.srotya.sidewinder.core.rpc.Point.Builder)1 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)1 BackgrounThreadFactory (com.srotya.sidewinder.core.utils.BackgrounThreadFactory)1 File (java.io.File)1 IOException (java.io.IOException)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1