如何填充 OrientDB 时间序列?

How to populate an OrientDB Time Series?

我想创建一个OrientDB时间序列年-->月-->日-->时-->分-->秒

OrientDB wiki 上的示例仅显示了如何创建 类 以及如何管理搜索。

我尝试使用 this code, but this approach requires over 2 minutes if limited on hours, as another user said here 填充图表。以秒为单位,类似的方法需要大约 12 小时。

正常吗?有更好的方法吗? 谢谢大家回答我的问题。

PS:我已经读过the Milan 2014 slides,但它只解释了结构(我已经清楚)和检索数据的方法。

你能试试这个代码吗?

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;

public class TimesSeriesMain {

    public static void main(String[] args) {

        OServerAdmin serverAdmin;
        try {
            serverAdmin = new OServerAdmin("remote:localhost/myTimeSeries").connect("root", "root");
            if(!serverAdmin.existsDatabase()){ 

                serverAdmin.createDatabase("myTimeSeries", "graph", "plocal");

                OrientGraphNoTx graph_c=new OrientGraphNoTx("remote:localhost/myTimeSeries");

                OClass hour_c=graph_c.createVertexType("Hour", "V");
                hour_c.createProperty("value", OType.INTEGER);

                OClass day_c=graph_c.createVertexType("Day", "V");
                day_c.createProperty("hour", OType.LINKSET, hour_c);

                OClass month_c=graph_c.createVertexType("Month", "V");
                month_c.createProperty("day", OType.LINKMAP, day_c);

                OClass year_c=graph_c.createVertexType("Year", "V");
                year_c.createProperty("value", OType.INTEGER);
                year_c.createProperty("month", OType.LINKMAP, month_c);

                graph_c.shutdown();

                OrientGraph graph=new OrientGraph("remote:localhost/myTimeSeries"); 

                long start = System.currentTimeMillis();

                for (int yy = 2015; yy < 2016; yy++){           
                    Map<Integer, OrientVertex> months = new HashMap<>();
                    for (int mm = 0; mm < 12; mm++){
                        Map<Integer, OrientVertex> days = new HashMap<>();
                        for (int dd = 1; dd < 32; dd++){
                            List<OrientVertex> hours = new ArrayList<OrientVertex>();
                            for (int i = 0; i < 24; i++){
                                OrientVertex hour=graph.addVertex("class:Hour");
                                hour.setProperty("value",i);
                                hours.add(hour);
                            }
                            OrientVertex day=graph.addVertex("class:Day");
                            day.setProperties("hour",hours);
                            days.put(dd,day);
                        }
                        OrientVertex month=graph.addVertex("class:Month");
                        month.setProperties("day",days);
                        months.put(mm,month);
                    }
                    OrientVertex year=graph.addVertex("class:Year");
                    year.setProperties("value",yy);
                    year.setProperties("month",months);    
                }

                long end=System.currentTimeMillis();

                System.out.println(((end-start)) + " millisec") ;

                graph.shutdown();
            }
        }           
        catch(Exception e){
            System.out.println(e);
        }   
    }
}

希望对您有所帮助。