diff --git a/build.gradle b/build.gradle index e37b550..9db4902 100644 --- a/build.gradle +++ b/build.gradle @@ -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() @@ -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' diff --git a/src/main/java/generator/GeneratorUtil.java b/src/main/java/generator/GeneratorUtil.java index 99c5c10..ad1cf80 100644 --- a/src/main/java/generator/GeneratorUtil.java +++ b/src/main/java/generator/GeneratorUtil.java @@ -243,7 +243,7 @@ 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 with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); dataLogger.warn(numberFormatException.getMessage()); } break; @@ -251,7 +251,7 @@ public static Thing addAttributeOfColumnType(Thing statement, try { statement = statement.has(conceptType, Double.parseDouble(cleanedValue)); } catch (NumberFormatException numberFormatException) { - dataLogger.warn("current row has column of type with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); dataLogger.warn(numberFormatException.getMessage()); } break; @@ -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 with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); } break; case "datetime": @@ -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 with non- datetime value: "); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- datetime value: ", conceptType)); dataLogger.warn(dateTimeException.getMessage()); } break; @@ -306,7 +306,7 @@ 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 with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); dataLogger.warn(numberFormatException.getMessage()); } break; @@ -314,7 +314,7 @@ public static Relation addAttributeOfColumnType(Relation statement, try { statement = statement.has(conceptType, Double.parseDouble(cleanedValue)); } catch (NumberFormatException numberFormatException) { - dataLogger.warn("current row has column of type with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); dataLogger.warn(numberFormatException.getMessage()); } break; @@ -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 with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); } break; case "datetime": @@ -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 with non- datetime value: "); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- datetime value: ", conceptType)); dataLogger.warn(dateTimeException.getMessage()); } break; @@ -371,7 +371,7 @@ 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 with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); dataLogger.warn(numberFormatException.getMessage()); } break; @@ -379,7 +379,7 @@ public static Thing addAttributeOfColumnType(UnboundVariable statement, try { returnThing = statement.has(conceptType, Double.parseDouble(cleanedValue)); } catch (NumberFormatException numberFormatException) { - dataLogger.warn("current row has column of type with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); dataLogger.warn(numberFormatException.getMessage()); } break; @@ -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 with non- value - skipping column"); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- value - skipping column", conceptType)); } break; case "datetime": @@ -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 with non- datetime value: "); + dataLogger.warn(String.format("current row has column of type for variable < %s > with non- datetime value: ", conceptType)); dataLogger.warn(dateTimeException.getMessage()); } break; diff --git a/src/main/java/insert/GraknInserter.java b/src/main/java/insert/GraknInserter.java index 8ef491f..eaa5d31 100644 --- a/src/main/java/insert/GraknInserter.java +++ b/src/main/java/insert/GraknInserter.java @@ -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; @@ -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; @@ -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(); @@ -55,7 +56,7 @@ private void defineToGrakn(String schemaAsString, GraknClient client) { appLogger.info("Defined schema to database <" + databaseName + ">"); } - public void matchInsertThreadedInserting(HashMap>>> statements, Session session, int threads, int batchSize) throws InterruptedException { + public void matchInsertThreadedInserting(HashMap>>> statements, GraknSession session, int threads, int batchSize) throws InterruptedException { AtomicInteger queryIndex = new AtomicInteger(0); Thread[] ts = new Thread[threads]; @@ -66,7 +67,7 @@ public void matchInsertThreadedInserting(HashMap>> 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> rowMatchStatements = matchStatements.get(q); @@ -90,7 +91,7 @@ public void matchInsertThreadedInserting(HashMap> statements, Session session, int threads, int batchSize) throws InterruptedException { + public void insertThreadedInserting(ArrayList> statements, GraknSession session, int threads, int batchSize) throws InterruptedException { AtomicInteger queryIndex = new AtomicInteger(0); Thread[] ts = new Thread[threads]; @@ -98,7 +99,7 @@ public void insertThreadedInserting(ArrayList> statements, Sess 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)); @@ -120,16 +121,16 @@ public void insertThreadedInserting(ArrayList> 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) { diff --git a/src/main/java/migrator/GraknMigrator.java b/src/main/java/migrator/GraknMigrator.java index d714ce1..03015da 100644 --- a/src/main/java/migrator/GraknMigrator.java +++ b/src/main/java/migrator/GraknMigrator.java @@ -4,8 +4,8 @@ import com.google.gson.reflect.TypeToken; import configuration.*; import generator.*; -import grakn.client.GraknClient; -import grakn.client.GraknClient.Session; +import grakn.client.api.GraknClient; +import grakn.client.api.GraknSession; import graql.lang.pattern.variable.ThingVariable; import loader.DataLoader; import insert.GraknInserter; @@ -63,7 +63,7 @@ public void migrate(boolean migrateEntities, boolean migrateRelations, boolean m appLogger.info("using existing DB and schema to continue previous migration..."); } - GraknClient.Session dataSession = graknInserter.getDataSession(client); + GraknSession dataSession = graknInserter.getDataSession(client); migrateThingsInOrder(dataSession, migrateEntities, migrateRelations, migrateRelationRelations, migrateAppendAttributes); dataSession.close(); @@ -71,11 +71,11 @@ public void migrate(boolean migrateEntities, boolean migrateRelations, boolean m appLogger.info("GraMi is finished migrating your stuff!"); } - private void migrateThingsInOrder(Session session, boolean migrateEntities, boolean migrateRelations, boolean migrateRelationRelations, boolean migrateAppendAttributes) throws IOException { + private void migrateThingsInOrder(GraknSession session, boolean migrateEntities, boolean migrateRelations, boolean migrateRelationRelations, boolean migrateAppendAttributes) throws IOException { - appLogger.info("migrating floating attributes..."); + appLogger.info("migrating independent attributes..."); getStatusAndMigrate(session, "attribute"); - appLogger.info("migration of floating attributes completed"); + appLogger.info("migration of independent attributes completed"); if (migrateEntities) { appLogger.info("migrating entities..."); @@ -96,26 +96,27 @@ private void migrateThingsInOrder(Session session, boolean migrateEntities, bool appLogger.info("migrating append-attribute..."); getStatusAndMigrate(session, "append-attribute"); appLogger.info("migration of append-attribute completed"); - } + } //TODO: relations with attributes have to come at end } - private void getStatusAndMigrate(Session session, String processorType) throws IOException { + private void getStatusAndMigrate(GraknSession session, String processorType) throws IOException { for (String dcEntryKey : dataConfig.keySet()) { DataConfigEntry dce = dataConfig.get(dcEntryKey); String currentProcessor = dce.getProcessor(); if(isOfProcessorType(currentProcessor, processorType)){ appLogger.info("migrating [" + dcEntryKey + "]..."); - if (migrationStatus != null && migrationStatus.get(dce.getDataPath()) != null) { - appLogger.info("previous migration status found for: [" + dcEntryKey + "]"); - if (!migrationStatus.get(dce.getDataPath()).isCompleted()) { - appLogger.info(dcEntryKey + " not completely migrated yet, rows already migrated: " + migrationStatus.get(dce.getDataPath()).getMigratedRows()); - getGeneratorAndInsert(session, dce, migrationStatus.get(dce.getDataPath()).getMigratedRows()); + String migrationStatusKey = dcEntryKey + "-" + dce.getDataPath(); + if (migrationStatus != null && migrationStatus.get(migrationStatusKey) != null) { + appLogger.info("previous migration status found for: [" + migrationStatusKey + "]"); + if (!migrationStatus.get(migrationStatusKey).isCompleted()) { + appLogger.info(migrationStatusKey + " not completely migrated yet, rows already migrated: " + migrationStatus.get(migrationStatusKey).getMigratedRows()); + getGeneratorAndInsert(session, dce, migrationStatus.get(migrationStatusKey).getMigratedRows(), migrationStatusKey); } else { - appLogger.info(dcEntryKey + " is already completely migrated - moving on..."); + appLogger.info(migrationStatusKey + " is already completely migrated - moving on..."); } } else { - appLogger.info("nothing previously migrated for [" + dcEntryKey + "] - starting with row 0"); - getGeneratorAndInsert(session, dce, 0); + appLogger.info("nothing previously migrated for [" + migrationStatusKey + "] - starting with row 0"); + getGeneratorAndInsert(session, dce, 0, migrationStatusKey); } } } @@ -130,15 +131,15 @@ private boolean isOfProcessorType(String key, String conceptType) { return false; } - private void getGeneratorAndInsert(Session session, DataConfigEntry dce, int skipRows) throws IOException { + private void getGeneratorAndInsert(GraknSession session, DataConfigEntry dce, int skipRows, String migrationStatusKey) throws IOException { // choose insert generator InsertGenerator gen = getProcessor(dce); - writeThingToGrakn(dce, gen, session, skipRows); - updateMigrationStatusIsCompleted(dce); + writeThingToGrakn(dce, gen, session, skipRows, migrationStatusKey); + updateMigrationStatusIsCompleted(migrationStatusKey); } - private void writeThingToGrakn(DataConfigEntry dce, InsertGenerator gen, Session session, int skipLines) { + private void writeThingToGrakn(DataConfigEntry dce, InsertGenerator gen, GraknSession session, int skipLines, String migrationStatusKey) { appLogger.info("inserting using " + dce.getThreads() + " threads" + " with thread commit size of " + dce.getBatchSize() + " rows"); @@ -171,7 +172,7 @@ private void writeThingToGrakn(DataConfigEntry dce, InsertGenerator gen, Session if (batchSizeCounter == dce.getBatchSize() * dce.getThreads()) { System.out.print("+"); System.out.flush(); - writeThing(dce, gen, session, rows, batchSizeCounter, header); + writeThing(dce, gen, session, rows, batchSizeCounter, header, migrationStatusKey); batchSizeCounter = 0; rows.clear(); } @@ -183,7 +184,7 @@ private void writeThingToGrakn(DataConfigEntry dce, InsertGenerator gen, Session } //insert the rest when loop exits with less than batch size if (!rows.isEmpty()) { - writeThing(dce, gen, session, rows, batchSizeCounter, header); + writeThing(dce, gen, session, rows, batchSizeCounter, header, migrationStatusKey); if (totalRecordCounter % 50000 != 0) { System.out.println(); } @@ -201,7 +202,7 @@ private void writeThingToGrakn(DataConfigEntry dce, InsertGenerator gen, Session - private void writeThing(DataConfigEntry dce, InsertGenerator gen, Session session, ArrayList rows, int lineCounter, String header) throws IOException { + private void writeThing(DataConfigEntry dce, InsertGenerator gen, GraknSession session, ArrayList rows, int lineCounter, String header, String migrationStatusKey) throws IOException { int threads = dce.getThreads(); try { if (isOfProcessorType(dce.getProcessor(), "entity")) { @@ -224,7 +225,7 @@ private void writeThing(DataConfigEntry dce, InsertGenerator gen, Session sessio } else { throw new IllegalArgumentException("the processor <" + dce.getProcessor() + "> is not known"); } - updateMigrationStatusMigratedRows(dce, lineCounter); + updateMigrationStatusMigratedRows(dce, lineCounter, migrationStatusKey); } catch (Exception ee) { ee.printStackTrace(); } @@ -245,22 +246,22 @@ private void initializeMigrationStatus() { } } - private void updateMigrationStatusMigratedRows(DataConfigEntry dce, int lineCounter) throws IOException { + private void updateMigrationStatusMigratedRows(DataConfigEntry dce, int lineCounter, String migrationStatusKey) throws IOException { try { ProcessorConfigEntry pce = getGenFromGenConfig(dce.getProcessor(), migrationConfig.getProcessorConfig()); Gson gson = new Gson(); Type MigrationStatusMapType = new TypeToken>(){}.getType(); if (migrationStatus != null) { - if (migrationStatus.get(dce.getDataPath()) != null) { //updating an existing entry - int updatedMigratedRows = migrationStatus.get(dce.getDataPath()).getMigratedRows() + lineCounter; - migrationStatus.get(dce.getDataPath()).setMigratedRows(updatedMigratedRows); + if (migrationStatus.get(migrationStatusKey) != null) { //updating an existing entry + int updatedMigratedRows = migrationStatus.get(migrationStatusKey).getMigratedRows() + lineCounter; + migrationStatus.get(migrationStatusKey).setMigratedRows(updatedMigratedRows); } else { // writing new entry - migrationStatus.put(dce.getDataPath(), new MigrationStatus(pce.getSchemaType(), false, lineCounter)); + migrationStatus.put(migrationStatusKey, new MigrationStatus(pce.getSchemaType(), false, lineCounter)); } } else { //writing very first entry (i.e. file was empty) migrationStatus = new HashMap<>(); - migrationStatus.put(dce.getDataPath(), new MigrationStatus(pce.getSchemaType(), false, lineCounter)); + migrationStatus.put(migrationStatusKey, new MigrationStatus(pce.getSchemaType(), false, lineCounter)); } // update file @@ -272,11 +273,11 @@ private void updateMigrationStatusMigratedRows(DataConfigEntry dce, int lineCoun } } - private void updateMigrationStatusIsCompleted(DataConfigEntry dce) throws IOException { + private void updateMigrationStatusIsCompleted(String migrationStatusKey) throws IOException { try { Gson gson = new Gson(); Type MigrationStatusMapType = new TypeToken>(){}.getType(); - migrationStatus.get(dce.getDataPath()).setCompleted(true); + migrationStatus.get(migrationStatusKey).setCompleted(true); FileWriter fw = new FileWriter(migrationStatePath); gson.toJson(migrationStatus, MigrationStatusMapType, fw); fw.flush(); diff --git a/src/main/java/migrator/SchemaUpdater.java b/src/main/java/migrator/SchemaUpdater.java index 31c8cc3..3630edd 100644 --- a/src/main/java/migrator/SchemaUpdater.java +++ b/src/main/java/migrator/SchemaUpdater.java @@ -1,7 +1,7 @@ package migrator; import configuration.SchemaUpdateConfig; -import grakn.client.GraknClient; +import grakn.client.api.GraknClient; import insert.GraknInserter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/test/java/generator/AttributeInsertGeneratorTest.java b/src/test/java/generator/AttributeInsertGeneratorTest.java index a5444da..4dfc5c7 100644 --- a/src/test/java/generator/AttributeInsertGeneratorTest.java +++ b/src/test/java/generator/AttributeInsertGeneratorTest.java @@ -31,10 +31,10 @@ public void graknAttributeQueryFromRowTest() { ArrayList> result = testAttributeInsertGenerator.graknAttributeInsert(rows, header); - String tc0 = "$a \"in_use\" isa is-in-use"; + String tc0 = "$a \"yes\" isa is-in-use"; Assert.assertEquals(tc0, result.get(0).toString()); - String tc1 = "$a \"not_in_use\" isa is-in-use"; + String tc1 = "$a \"no\" isa is-in-use"; Assert.assertEquals(tc1, result.get(1).toString()); Assert.assertEquals(2, result.size()); diff --git a/src/test/java/insert/GraknInserterTest.java b/src/test/java/insert/GraknInserterTest.java index 2575f3c..2dd9f8b 100644 --- a/src/test/java/insert/GraknInserterTest.java +++ b/src/test/java/insert/GraknInserterTest.java @@ -1,8 +1,8 @@ package insert; -import grakn.client.GraknClient; -import grakn.client.GraknClient.Session; -import grakn.client.GraknClient.Transaction; +import grakn.client.api.GraknClient; +import grakn.client.api.GraknSession; +import grakn.client.api.GraknTransaction; import graql.lang.Graql; import graql.lang.query.GraqlDelete; import graql.lang.query.GraqlInsert; @@ -32,13 +32,13 @@ public void reloadKeyspaceTest() { Assert.assertTrue(client.databases().contains(databaseName)); //ensure Keyspace contains schema - Session dataSession = gi.getDataSession(client); - Transaction read = dataSession.transaction(Transaction.Type.READ); + GraknSession dataSession = gi.getDataSession(client); + GraknTransaction read = dataSession.transaction(GraknTransaction.Type.READ); GraqlMatch.Limited mq = Graql.match(var("e").sub("entity")).get("e").limit(100); Assert.assertEquals(4, read.query().match(mq).count()); read.close(); - read = dataSession.transaction(Transaction.Type.READ); + read = dataSession.transaction(GraknTransaction.Type.READ); mq = Graql.match(var("e").type("entity1")).get("e").limit(100); Assert.assertEquals(1, read.query().match(mq).count()); read.close(); @@ -62,26 +62,26 @@ public void insertToGraknTest() { gi.cleanAndDefineSchemaToDatabase(client); //perform data entry - Session dataSession = gi.getDataSession(client); - Transaction write = dataSession.transaction(Transaction.Type.WRITE); + GraknSession dataSession = gi.getDataSession(client); + GraknTransaction write = dataSession.transaction(GraknTransaction.Type.WRITE); GraqlInsert insertQuery = Graql.insert(var("e").isa("entity1").has("entity1-id", "ide1")); write.query().insert(insertQuery); write.commit(); write.close(); //ensure graph contains our insert - Transaction read = dataSession.transaction(Transaction.Type.READ); + GraknTransaction read = dataSession.transaction(GraknTransaction.Type.READ); GraqlMatch.Limited getQuery = Graql.match(var("e").isa("entity1").has("entity1-id", "ide1")).get("e").limit(100); Assert.assertEquals(1, read.query().match(getQuery).count()); read.close(); - read = dataSession.transaction(Transaction.Type.READ); + read = dataSession.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("e").isa("entity1").has("entity1-id", "ide2")).limit(100); Assert.assertEquals(0, read.query().match(getQuery).count()); read.close(); //another test for our insert - read = dataSession.transaction(Transaction.Type.READ); + read = dataSession.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("e").isa("entity1").has("entity1-id", "ide1")).get("e").limit(100); read.query().match(getQuery).forEach( answers -> { answers.concepts().stream().forEach( entry -> { @@ -91,7 +91,7 @@ public void insertToGraknTest() { read.close(); //clean up: - Transaction delete = dataSession.transaction(Transaction.Type.WRITE); + GraknTransaction delete = dataSession.transaction(GraknTransaction.Type.WRITE); GraqlDelete delQuery = Graql.match( var("e").isa("entity1").has("entity1-id", "ide1") ).delete(var("e").isa("entity1")); diff --git a/src/test/java/migrator/MigrationTest.java b/src/test/java/migrator/MigrationTest.java index 134fb6c..5048961 100644 --- a/src/test/java/migrator/MigrationTest.java +++ b/src/test/java/migrator/MigrationTest.java @@ -1,9 +1,9 @@ package migrator; import configuration.MigrationConfig; -import grakn.client.GraknClient; -import grakn.client.GraknClient.Session; -import grakn.client.GraknClient.Transaction; +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.pattern.variable.ThingVariable.Thing; @@ -53,7 +53,7 @@ public void migratePhoneCallsTest() throws IOException { GraknInserter gi = new GraknInserter(graknURI.split(":")[0], graknURI.split(":")[1], asp, databaseName); GraknClient client = gi.getClient(); - Session session = gi.getDataSession(client); + GraknSession session = gi.getDataSession(client); testEntities(session); testRelations(session); testRelationWithRelations(session); @@ -64,45 +64,45 @@ public void migratePhoneCallsTest() throws IOException { client.close(); } - public void testEntities(Session session) { + public void testEntities(GraknSession session) { // query person by phone-number - Transaction read = session.transaction(Transaction.Type.READ); + GraknTransaction read = session.transaction(GraknTransaction.Type.READ); GraqlMatch getQuery = Graql.match(var("p").isa("person").has("phone-number", "+261 860 539 4754")).get("p").limit(1000); Assert.assertEquals(1, read.query().match(getQuery).count()); // query person by last name - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("p").isa("person").has("last-name", "Smith")).get("p").limit(1000); Assert.assertEquals(2, read.query().match(getQuery).count()); // query all entities of type person - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("c").isa("person")).get("c").limit(1000); Assert.assertEquals(32, read.query().match(getQuery).count()); // query all entites of type company - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("e").isa("company")).get("e").limit(1000); Assert.assertEquals(2, read.query().match(getQuery).count()); read.close(); } - public void testRelations(Session session) { + public void testRelations(GraknSession session) { // query call by duration - Transaction read = session.transaction(Transaction.Type.READ); + GraknTransaction read = session.transaction(GraknTransaction.Type.READ); GraqlMatch getQuery = Graql.match(var("c").isa("call").has("duration", 2851)).get("c").limit(1000); Assert.assertEquals(1, read.query().match(getQuery).count()); // query call by date - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("c").isa("call").has("started-at", getDT("2018-09-17T18:43:42"))).get("c").limit(1000); Assert.assertEquals(1, read.query().match(getQuery).count()); // query call by caller - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); Thing player = Graql.var("p").isa("person").has("phone-number", "+7 171 898 0853"); Relation relation = Graql.var("c").isa("call").toUnbound().rel("caller", "p"); ArrayList statements = new ArrayList<>(); @@ -113,7 +113,7 @@ public void testRelations(Session session) { Assert.assertEquals(14, read.query().match(getQuery).count()); // query call by callee - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); player = Graql.var("p").isa("person").has("phone-number", "+7 171 898 0853"); relation = Graql.var("c").isa("call").toUnbound().rel("callee", "p"); statements = new ArrayList<>(); @@ -123,7 +123,7 @@ public void testRelations(Session session) { Assert.assertEquals(4, read.query().match(getQuery).count()); // query call by caller & callee - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); Thing playerOne = Graql.var("p1").isa("person").has("phone-number", "+7 171 898 0853"); Thing playerTwo = Graql.var("p2").isa("person").has("phone-number", "+57 629 420 5680"); relation = Graql.var("c").isa("call").toUnbound().rel("caller", "p1").rel("callee", "p2"); @@ -137,10 +137,10 @@ public void testRelations(Session session) { read.close(); } - public void testRelationWithRelations(Session session) { + public void testRelationWithRelations(GraknSession session) { // query specific communication-channel and count the number of past calls (single past-call): - Transaction read = session.transaction(Transaction.Type.READ); + GraknTransaction read = session.transaction(GraknTransaction.Type.READ); Thing playerOne = Graql.var("p1").isa("person").has("phone-number", "+54 398 559 0423"); Thing playerTwo = Graql.var("p2").isa("person").has("phone-number", "+48 195 624 2025"); Relation relation = Graql.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call","x").isa("communication-channel"); @@ -154,7 +154,7 @@ public void testRelationWithRelations(Session session) { Assert.assertEquals(1, read.query().match(getQuery).count()); // query specific communication-channel and count the number of past calls (listSeparated past-calls: - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); playerOne = Graql.var("p1").isa("person").has("phone-number", "+263 498 495 0617"); playerTwo = Graql.var("p2").isa("person").has("phone-number", "+33 614 339 0298"); relation = Graql.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); @@ -168,7 +168,7 @@ public void testRelationWithRelations(Session session) { Assert.assertEquals(6, read.query().match(getQuery).count()); // make sure that this doesn't get inserted: - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); playerOne = Graql.var("p1").isa("person").has("phone-number", "+7 690 597 4443"); playerTwo = Graql.var("p2").isa("person").has("phone-number", "+54 398 559 9999"); relation = Graql.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); @@ -182,7 +182,7 @@ public void testRelationWithRelations(Session session) { Assert.assertEquals(0, read.query().match(getQuery).count()); // these are added by doing player matching for past calls: - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); playerOne = Graql.var("p1").isa("person").has("phone-number", "+81 308 988 7153"); playerTwo = Graql.var("p2").isa("person").has("phone-number", "+351 515 605 7915"); relation = Graql.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); @@ -195,7 +195,7 @@ public void testRelationWithRelations(Session session) { getQuery = Graql.match(statements).get("x").limit(1000); Assert.assertEquals(5, read.query().match(getQuery).count()); - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); playerOne = Graql.var("p1").isa("person").has("phone-number", "+7 171 898 0853"); playerTwo = Graql.var("p2").isa("person").has("phone-number", "+57 629 420 5680"); relation = Graql.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); @@ -209,7 +209,7 @@ public void testRelationWithRelations(Session session) { Assert.assertEquals(4, read.query().match(getQuery).count()); // these must not be found (come from player-matched past-call): - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); playerOne = Graql.var("p1").isa("person").has("phone-number", "+261 860 539 4754"); relation = Graql.var("c").rel("peer", "p1").rel("past-call", "x").isa("communication-channel"); statements = new ArrayList<>(); @@ -223,10 +223,10 @@ public void testRelationWithRelations(Session session) { read.close(); } - public void testAppendAttribute(Session session) { + public void testAppendAttribute(GraknSession session) { // Count number of total inserts - Transaction read = session.transaction(Transaction.Type.READ); + GraknTransaction read = session.transaction(GraknTransaction.Type.READ); GraqlMatch.Limited getQuery = Graql.match(var("p").isa("person").has("twitter-username", var("x"))).get("p").limit(1000); Assert.assertEquals(6, read.query().match(getQuery).count()); @@ -247,25 +247,25 @@ public void testAppendAttribute(Session session) { read.close(); } - public void testAttributes(Session session) { + public void testAttributes(GraknSession session) { - Transaction read = session.transaction(Transaction.Type.READ); + GraknTransaction read = session.transaction(GraknTransaction.Type.READ); GraqlMatch getQuery = Graql.match(var("a").isa("is-in-use")).get("a"); Assert.assertEquals(2, read.query().match(getQuery).count()); - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("a").eq("yes").isa("is-in-use")).get("a"); Assert.assertEquals(1, read.query().match(getQuery).count()); - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery = Graql.match(var("a").eq("no").isa("is-in-use")).get("a"); Assert.assertEquals(1, read.query().match(getQuery).count()); read.close(); } - public void testAttributeRelation(Session session) { + public void testAttributeRelation(GraknSession session) { - Transaction read = session.transaction(Transaction.Type.READ); + GraknTransaction read = session.transaction(GraknTransaction.Type.READ); GraqlMatch getQuery = Graql.match(var("a").isa("in-use")).get("a"); Assert.assertEquals(7, read.query().match(getQuery).count()); diff --git a/src/test/java/migrator/SchemaUpdaterTest.java b/src/test/java/migrator/SchemaUpdaterTest.java index cb0aaeb..23f3a57 100644 --- a/src/test/java/migrator/SchemaUpdaterTest.java +++ b/src/test/java/migrator/SchemaUpdaterTest.java @@ -2,9 +2,9 @@ import configuration.MigrationConfig; import configuration.SchemaUpdateConfig; -import grakn.client.GraknClient; -import grakn.client.GraknClient.Session; -import grakn.client.GraknClient.Transaction; +import grakn.client.api.GraknClient; +import grakn.client.api.GraknSession; +import grakn.client.api.GraknTransaction; import graql.lang.Graql; import graql.lang.query.GraqlMatch; import insert.GraknInserter; @@ -46,28 +46,28 @@ public void updateSchemaTest() throws IOException { private void postUpdateSchemaTests(GraknInserter gi) { GraknClient client = gi.getClient(); - Session session = gi.getDataSession(client); + GraknSession session = gi.getDataSession(client); // query attribute type - Transaction read = session.transaction(Transaction.Type.READ); + GraknTransaction read = session.transaction(GraknTransaction.Type.READ); GraqlMatch.Filtered getQuery = Graql.match(var("a").type("added-attribute")).get("a"); Assert.assertEquals(1, read.query().match(getQuery).count()); read.close(); // query entity type - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); GraqlMatch.Limited getQuery2 = Graql.match(var("a").type("added-entity")).get("a").limit(1000); Assert.assertEquals(1, read.query().match(getQuery2).count()); read.close(); // query relation type - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery2 = Graql.match(var("a").type("added-relation")).get("a").limit(1000); Assert.assertEquals(1, read.query().match(getQuery2).count()); read.close(); // query role type - read = session.transaction(Transaction.Type.READ); + read = session.transaction(GraknTransaction.Type.READ); getQuery2 = Graql.match(type("added-relation").relates(var("r"))).limit(1000); Assert.assertEquals(1, read.query().match(getQuery2).count()); read.close(); diff --git a/src/test/resources/genericTests/migrationStatus-test.json b/src/test/resources/genericTests/migrationStatus-test.json index 421f67b..21f8d94 100644 --- a/src/test/resources/genericTests/migrationStatus-test.json +++ b/src/test/resources/genericTests/migrationStatus-test.json @@ -1 +1 @@ -{"src/test/resources/genericTests/entity1-test-data.tsv":{"conceptName":"entity1","isCompleted":true,"migratedRows":32},"src/test/resources/genericTests/entity2-test-data.tsv":{"conceptName":"entity2","isCompleted":true,"migratedRows":12},"src/test/resources/genericTests/entity3-test-data.tsv":{"conceptName":"entity3","isCompleted":true,"migratedRows":12},"src/test/resources/genericTests/rel1-test-data.tsv":{"conceptName":"rel1","isCompleted":true,"migratedRows":44}} \ No newline at end of file +{"entity3-src/test/resources/genericTests/entity3-test-data.tsv":{"conceptName":"entity3","isCompleted":true,"migratedRows":12},"entity2-src/test/resources/genericTests/entity2-test-data.tsv":{"conceptName":"entity2","isCompleted":true,"migratedRows":12},"rel1-src/test/resources/genericTests/rel1-test-data.tsv":{"conceptName":"rel1","isCompleted":true,"migratedRows":44},"entity1-src/test/resources/genericTests/entity1-test-data.tsv":{"conceptName":"entity1","isCompleted":true,"migratedRows":32}} \ No newline at end of file diff --git a/src/test/resources/phone-calls/call.csv b/src/test/resources/phone-calls/call.csv index d287842..fe86398 100644 --- a/src/test/resources/phone-calls/call.csv +++ b/src/test/resources/phone-calls/call.csv @@ -1,21 +1,21 @@ caller_id,callee_id,started_at,duration +54 398 559 0423,+48 195 624 2025,2018-09-16T22:24:19,122 -+54 398 559 0423,+48 195 624 2025,2018-09-17T22:24:19,122 -+54 398 559 0423,+48 195 624 2025,2018-09-18T22:24:19,122 -+54 398 559 0423,+48 195 624 2025,2018-09-19T22:24:19,122 -+54 398 559 0423,+48 195 624 2025,2018-09-20T22:24:19,122 ++54 398 559 0423,+48 195 624 2025,2018-09-17T22:24:19,123 ++54 398 559 0423,+48 195 624 2025,2018-09-18T22:24:19,124 ++54 398 559 0423,+48 195 624 2025,2018-09-19T22:24:19,125 ++54 398 559 0423,+48 195 624 2025,2018-09-20T22:24:19,126 +263 498 495 0617,+48 195 624 2025,2018-09-18T01:34:48,514 +81 308 988 7153,+33 614 339 0298,2018-09-21T20:21:17,120 +263 498 495 0617,+33 614 339 0298,2018-09-11T22:10:34,144 -+263 498 495 0617,+33 614 339 0298,2018-09-12T22:10:34,144 -+263 498 495 0617,+33 614 339 0298,2018-09-13T22:10:34,144 -+263 498 495 0617,+33 614 339 0298,2018-09-14T22:10:34,144 -+263 498 495 0617,+33 614 339 0298,2018-09-15T22:10:34,144 -+263 498 495 0617,+33 614 339 0298,2018-09-16T22:10:34,144 ++263 498 495 0617,+33 614 339 0298,2018-09-12T22:10:34,145 ++263 498 495 0617,+33 614 339 0298,2018-09-13T22:10:34,146 ++263 498 495 0617,+33 614 339 0298,2018-09-14T22:10:34,147 ++263 498 495 0617,+33 614 339 0298,2018-09-15T22:10:34,148 ++263 498 495 0617,+33 614 339 0298,2018-09-16T22:10:34,149 +54 398 559 0423,+7 552 196 4096,2018-09-25T20:24:59,556 +81 308 988 7153,+351 515 605 7915,2018-09-23T22:23:25,336 -+81 308 988 7153,+351 515 605 7915,2018-09-24T22:23:25,336 -+81 308 988 7153,+351 515 605 7915,2018-09-25T22:23:25,336 ++81 308 988 7153,+351 515 605 7915,2018-09-24T22:23:25,332 ++81 308 988 7153,+351 515 605 7915,2018-09-25T22:23:25,331 +261 860 539 4754,+351 272 414 6570,2018-09-26T05:34:19,405 +62 107 530 7500,+263 498 495 0617,2018-09-25T22:58:02,5665 +54 398 559 0423,+86 892 682 0628,2018-09-23T08:55:18,822 diff --git a/src/test/resources/phone-calls/migrationStatus.json b/src/test/resources/phone-calls/migrationStatus.json index d649d61..c05578e 100644 --- a/src/test/resources/phone-calls/migrationStatus.json +++ b/src/test/resources/phone-calls/migrationStatus.json @@ -1 +1 @@ -{"src/test/resources/phone-calls/is-in-use.csv":{"conceptName":"is-in-use","isCompleted":true,"migratedRows":2},"src/test/resources/phone-calls/person.csv":{"conceptName":"person","isCompleted":true,"migratedRows":35},"src/test/resources/phone-calls/append-call-rating.csv":{"conceptName":"call","isCompleted":true,"migratedRows":7},"src/test/resources/phone-calls/call.csv":{"conceptName":"call","isCompleted":true,"migratedRows":218},"src/test/resources/phone-calls/in-use.csv":{"conceptName":"in-use","isCompleted":true,"migratedRows":8},"src/test/resources/phone-calls/communication-channel.csv":{"conceptName":"communication-channel","isCompleted":true,"migratedRows":7},"src/test/resources/phone-calls/append-fb-preprocessed.csv":{"conceptName":"person","isCompleted":true,"migratedRows":5},"src/test/resources/phone-calls/company.csv":{"conceptName":"company","isCompleted":true,"migratedRows":2},"src/test/resources/phone-calls/communication-channel-pm.csv":{"conceptName":"communication-channel","isCompleted":true,"migratedRows":6},"src/test/resources/phone-calls/append-twitter.csv":{"conceptName":"person","isCompleted":true,"migratedRows":10},"src/test/resources/phone-calls/contract.csv":{"conceptName":"contract","isCompleted":true,"migratedRows":12}} \ No newline at end of file +{"append-pp-fakebook-src/test/resources/phone-calls/append-fb-preprocessed.csv":{"conceptName":"person","isCompleted":true,"migratedRows":5},"person-src/test/resources/phone-calls/person.csv":{"conceptName":"person","isCompleted":true,"migratedRows":35},"in-use-src/test/resources/phone-calls/in-use.csv":{"conceptName":"in-use","isCompleted":true,"migratedRows":8},"company-src/test/resources/phone-calls/company.csv":{"conceptName":"company","isCompleted":true,"migratedRows":2},"calls-src/test/resources/phone-calls/call.csv":{"conceptName":"call","isCompleted":true,"migratedRows":218},"contract-src/test/resources/phone-calls/contract.csv":{"conceptName":"contract","isCompleted":true,"migratedRows":12},"is-in-use-src/test/resources/phone-calls/is-in-use.csv":{"conceptName":"is-in-use","isCompleted":true,"migratedRows":2},"communication-channel-pm-src/test/resources/phone-calls/communication-channel-pm.csv":{"conceptName":"communication-channel","isCompleted":true,"migratedRows":6},"append-twitter-src/test/resources/phone-calls/append-twitter.csv":{"conceptName":"person","isCompleted":true,"migratedRows":10},"communication-channel-src/test/resources/phone-calls/communication-channel.csv":{"conceptName":"communication-channel","isCompleted":true,"migratedRows":7},"append-call-rating-src/test/resources/phone-calls/append-call-rating.csv":{"conceptName":"call","isCompleted":true,"migratedRows":7}} \ No newline at end of file