Search in sources :

Example 1 with MemStorageEngine

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);
}
Also used : SqlApi(com.srotya.sidewinder.core.api.SqlApi) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BackgrounThreadFactory(com.srotya.sidewinder.core.utils.BackgrounThreadFactory) TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine)

Example 2 with MemStorageEngine

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();
}
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 3 with MemStorageEngine

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();
}
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) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 4 with MemStorageEngine

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));
}
Also used : MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) BeforeClass(org.junit.BeforeClass)

Example 5 with MemStorageEngine

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();
}
Also used : MemStorageEngine(com.srotya.sidewinder.core.storage.mem.MemStorageEngine) File(java.io.File) Before(org.junit.Before)

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