Search in sources :

Example 6 with GraknClient

use of ai.grakn.client.GraknClient in project grakn by graknlabs.

the class Migrator method load.

/**
 * Migrate data constrained by this migrator using a loader configured
 * by the provided parameters.
 *
 * @param template Template used to extract the data
 * @param data Data being migrated
 */
public void load(String template, Stream<Map<String, Object>> data) {
    GraknClient graknClient = GraknClient.of(uri);
    AtomicInteger queriesExecuted = new AtomicInteger(0);
    try (BatchExecutorClient loader = BatchExecutorClient.newBuilder().taskClient(graknClient).maxRetries(retries).maxDelay(maxDelayMs).metricRegistry(metricRegistry).build()) {
        checkKeyspace(graknClient);
        Stream<Query> queryStream = data.flatMap(d -> template(template, d, failFast));
        if (maxLines > -1) {
            queryStream = queryStream.limit(maxLines);
        }
        queryStream.forEach(q -> {
            LOG.trace("Adding query {}", q);
            totalMeter.mark();
            // We add get a hot observable. It starts immediately
            Observable<QueryResponse> observable = loader.add(q, keyspace, failFast);
            subscribeToReportOutcome(failFast, observable, queriesExecuted);
        });
    }
    System.out.println("Loaded " + queriesExecuted + " statements");
}
Also used : Query(ai.grakn.graql.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraknClient(ai.grakn.client.GraknClient) QueryResponse(ai.grakn.client.QueryResponse) BatchExecutorClient(ai.grakn.client.BatchExecutorClient)

Aggregations

GraknClient (ai.grakn.client.GraknClient)6 BatchExecutorClient (ai.grakn.client.BatchExecutorClient)3 Role (ai.grakn.concept.Role)3 Grakn (ai.grakn.Grakn)2 GraknSession (ai.grakn.GraknSession)2 GraknSystemProperty (ai.grakn.GraknSystemProperty)2 GraknTx (ai.grakn.GraknTx)2 GraknTxType (ai.grakn.GraknTxType)2 Keyspace (ai.grakn.Keyspace)2 AttributeType (ai.grakn.concept.AttributeType)2 ConceptId (ai.grakn.concept.ConceptId)2 RelationshipType (ai.grakn.concept.RelationshipType)2 GetQuery (ai.grakn.graql.GetQuery)2 Graql (ai.grakn.graql.Graql)2 Graql.var (ai.grakn.graql.Graql.var)2 InsertQuery (ai.grakn.graql.InsertQuery)2 Pattern (ai.grakn.graql.Pattern)2 Var (ai.grakn.graql.Var)2 VarPattern (ai.grakn.graql.VarPattern)2 Answer (ai.grakn.graql.admin.Answer)2