Skip to content

Commit

Permalink
- updated to 2.0.1 and client 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hkuich committed Apr 8, 2021
1 parent f262cc1 commit 8478839
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 127 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.github.bayer-science-for-a-better-life'
version '0.1.0-alpha-12'
version '0.1.0'

repositories {
mavenCentral()
Expand All @@ -15,7 +15,7 @@ repositories {
}

dependencies {
compile group: 'io.grakn.client', name: 'grakn-client', version: '2.0.0-alpha-12'
compile group: 'io.grakn.client', name: 'grakn-client', version: '2.0.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.code.gson:gson:2.8.6'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/generator/GeneratorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ public static Thing addAttributeOfColumnType(Thing statement,
try {
statement = statement.has(conceptType, Integer.parseInt(cleanedValue));
} catch (NumberFormatException numberFormatException) {
dataLogger.warn("current row has column of type <long> with non-<long> value - skipping column");
dataLogger.warn(String.format("current row has column of type <long> for variable < %s > with non-<long> value - skipping column", conceptType));
dataLogger.warn(numberFormatException.getMessage());
}
break;
case "double":
try {
statement = statement.has(conceptType, Double.parseDouble(cleanedValue));
} catch (NumberFormatException numberFormatException) {
dataLogger.warn("current row has column of type <double> with non-<double> value - skipping column");
dataLogger.warn(String.format("current row has column of type <double> for variable < %s > with non-<double> value - skipping column", conceptType));
dataLogger.warn(numberFormatException.getMessage());
}
break;
Expand All @@ -261,7 +261,7 @@ public static Thing addAttributeOfColumnType(Thing statement,
} else if (cleanedValue.toLowerCase().equals("false")) {
statement = statement.has(conceptType, false);
} else {
dataLogger.warn("current row has column of type <boolean> with non-<boolean> value - skipping column");
dataLogger.warn(String.format("current row has column of type <boolean> for variable < %s > with non-<boolean> value - skipping column", conceptType));
}
break;
case "datetime":
Expand All @@ -278,7 +278,7 @@ public static Thing addAttributeOfColumnType(Thing statement,
statement = statement.has(conceptType, dateTime);
}
} catch (DateTimeException dateTimeException) {
dataLogger.warn("current row has column of type <datetime> with non-<ISO 8601 format> datetime value: ");
dataLogger.warn(String.format("current row has column of type <datetime> for variable < %s > with non-<ISO 8601 format> datetime value: ", conceptType));
dataLogger.warn(dateTimeException.getMessage());
}
break;
Expand Down Expand Up @@ -306,15 +306,15 @@ public static Relation addAttributeOfColumnType(Relation statement,
try {
statement = statement.has(conceptType, Integer.parseInt(cleanedValue));
} catch (NumberFormatException numberFormatException) {
dataLogger.warn("current row has column of type <long> with non-<long> value - skipping column");
dataLogger.warn(String.format("current row has column of type <long> for variable < %s > with non-<long> value - skipping column", conceptType));
dataLogger.warn(numberFormatException.getMessage());
}
break;
case "double":
try {
statement = statement.has(conceptType, Double.parseDouble(cleanedValue));
} catch (NumberFormatException numberFormatException) {
dataLogger.warn("current row has column of type <double> with non-<double> value - skipping column");
dataLogger.warn(String.format("current row has column of type <double> for variable < %s > with non-<double> value - skipping column", conceptType));
dataLogger.warn(numberFormatException.getMessage());
}
break;
Expand All @@ -324,7 +324,7 @@ public static Relation addAttributeOfColumnType(Relation statement,
} else if (cleanedValue.toLowerCase().equals("false")) {
statement = statement.has(conceptType, false);
} else {
dataLogger.warn("current row has column of type <boolean> with non-<boolean> value - skipping column");
dataLogger.warn(String.format("current row has column of type <boolean> for variable < %s > with non-<boolean> value - skipping column", conceptType));
}
break;
case "datetime":
Expand All @@ -341,7 +341,7 @@ public static Relation addAttributeOfColumnType(Relation statement,
statement = statement.has(conceptType, dateTime);
}
} catch (DateTimeException dateTimeException) {
dataLogger.warn("current row has column of type <datetime> with non-<ISO 8601 format> datetime value: ");
dataLogger.warn(String.format("current row has column of type <datetime> for variable < %s > with non-<ISO 8601 format> datetime value: ", conceptType));
dataLogger.warn(dateTimeException.getMessage());
}
break;
Expand Down Expand Up @@ -371,15 +371,15 @@ public static Thing addAttributeOfColumnType(UnboundVariable statement,
try {
returnThing = statement.has(conceptType, Integer.parseInt(cleanedValue));
} catch (NumberFormatException numberFormatException) {
dataLogger.warn("current row has column of type <long> with non-<long> value - skipping column");
dataLogger.warn(String.format("current row has column of type <long> for variable < %s > with non-<long> value - skipping column", conceptType));
dataLogger.warn(numberFormatException.getMessage());
}
break;
case "double":
try {
returnThing = statement.has(conceptType, Double.parseDouble(cleanedValue));
} catch (NumberFormatException numberFormatException) {
dataLogger.warn("current row has column of type <double> with non-<double> value - skipping column");
dataLogger.warn(String.format("current row has column of type <double> for variable < %s > with non-<double> value - skipping column", conceptType));
dataLogger.warn(numberFormatException.getMessage());
}
break;
Expand All @@ -389,7 +389,7 @@ public static Thing addAttributeOfColumnType(UnboundVariable statement,
} else if (cleanedValue.toLowerCase().equals("false")) {
returnThing = statement.has(conceptType, false);
} else {
dataLogger.warn("current row has column of type <boolean> with non-<boolean> value - skipping column");
dataLogger.warn(String.format("current row has column of type <boolean> for variable < %s > with non-<boolean> value - skipping column", conceptType));
}
break;
case "datetime":
Expand All @@ -406,7 +406,7 @@ public static Thing addAttributeOfColumnType(UnboundVariable statement,
returnThing = statement.has(conceptType, dateTime);
}
} catch (DateTimeException dateTimeException) {
dataLogger.warn("current row has column of type <datetime> with non-<ISO 8601 format> datetime value: ");
dataLogger.warn(String.format("current row has column of type <datetime> for variable < %s > with non-<ISO 8601 format> datetime value: ", conceptType));
dataLogger.warn(dateTimeException.getMessage());
}
break;
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/insert/GraknInserter.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package insert;

import grakn.client.GraknClient;
import grakn.client.GraknClient.Transaction;
import grakn.client.GraknClient.Session;
import grakn.client.Grakn;
import grakn.client.api.GraknClient;
import grakn.client.api.GraknSession;
import grakn.client.api.GraknTransaction;
import graql.lang.Graql;
import graql.lang.pattern.variable.ThingVariable;
import graql.lang.query.GraqlDefine;
Expand All @@ -18,10 +19,10 @@

public class GraknInserter {

private static final Logger appLogger = LogManager.getLogger("com.bayer.dt.grami");
private final String schemaPath;
private final String databaseName;
private final String graknURI;
private static final Logger appLogger = LogManager.getLogger("com.bayer.dt.grami");

public GraknInserter(String graknURI, String port, String schemaPath, String databaseName) {
this.schemaPath = schemaPath;
Expand All @@ -42,11 +43,11 @@ private void createDatabase(GraknClient client) {
}

private void defineToGrakn(String schemaAsString, GraknClient client) {
Session schemaSession = getSchemaSession(client);
GraknSession schemaSession = getSchemaSession(client);
GraqlDefine q = Graql.parseQuery(schemaAsString);


Transaction writeTransaction = schemaSession.transaction(Transaction.Type.WRITE);
GraknTransaction writeTransaction = schemaSession.transaction(GraknTransaction.Type.WRITE);
writeTransaction.query().define(q);
writeTransaction.commit();
writeTransaction.close();
Expand All @@ -55,7 +56,7 @@ private void defineToGrakn(String schemaAsString, GraknClient client) {
appLogger.info("Defined schema to database <" + databaseName + ">");
}

public void matchInsertThreadedInserting(HashMap<String, ArrayList<ArrayList<ThingVariable<?>>>> statements, Session session, int threads, int batchSize) throws InterruptedException {
public void matchInsertThreadedInserting(HashMap<String, ArrayList<ArrayList<ThingVariable<?>>>> statements, GraknSession session, int threads, int batchSize) throws InterruptedException {

AtomicInteger queryIndex = new AtomicInteger(0);
Thread[] ts = new Thread[threads];
Expand All @@ -66,7 +67,7 @@ public void matchInsertThreadedInserting(HashMap<String, ArrayList<ArrayList<Thi
ArrayList<ArrayList<ThingVariable<?>>> insertStatements = statements.get("insert");

while (queryIndex.get() < matchStatements.size()) {
try (Transaction tx = session.transaction(Transaction.Type.WRITE)) {
try (GraknTransaction tx = session.transaction(GraknTransaction.Type.WRITE)) {
int q;
for (int i = 0; i < batchSize && (q = queryIndex.getAndIncrement()) < matchStatements.size(); i++) {
ArrayList<ThingVariable<?>> rowMatchStatements = matchStatements.get(q);
Expand All @@ -90,15 +91,15 @@ public void matchInsertThreadedInserting(HashMap<String, ArrayList<ArrayList<Thi
}
}

public void insertThreadedInserting(ArrayList<ThingVariable<?>> statements, Session session, int threads, int batchSize) throws InterruptedException {
public void insertThreadedInserting(ArrayList<ThingVariable<?>> statements, GraknSession session, int threads, int batchSize) throws InterruptedException {

AtomicInteger queryIndex = new AtomicInteger(0);
Thread[] ts = new Thread[threads];

Runnable insertThread =
() -> {
while (queryIndex.get() < statements.size()) {
try (Transaction tx = session.transaction(Transaction.Type.WRITE)) {
try (GraknTransaction tx = session.transaction(GraknTransaction.Type.WRITE)) {
int q;
for (int i = 0; i < batchSize && (q = queryIndex.getAndIncrement()) < statements.size(); i++) {
GraqlInsert query = Graql.insert(statements.get(q));
Expand All @@ -120,16 +121,16 @@ public void insertThreadedInserting(ArrayList<ThingVariable<?>> statements, Sess
}

// Utility functions
public Session getDataSession(GraknClient client) {
return client.session(databaseName, Session.Type.DATA);
public GraknSession getDataSession(GraknClient client) {
return client.session(databaseName, GraknSession.Type.DATA);
}

public Session getSchemaSession(GraknClient client) {
return client.session(databaseName, Session.Type.SCHEMA);
public GraknSession getSchemaSession(GraknClient client) {
return client.session(databaseName, GraknSession.Type.SCHEMA);
}

public GraknClient getClient() {
return GraknClient.core(graknURI);
return Grakn.coreClient(graknURI);
}

private void deleteDatabaseIfExists(GraknClient client) {
Expand Down
Loading

0 comments on commit 8478839

Please sign in to comment.