From 1ffae118b1236f55f36e1128638500b9dfa4c1d9 Mon Sep 17 00:00:00 2001 From: Joshua Send Date: Fri, 21 Oct 2022 13:51:08 +0100 Subject: [PATCH] Safe match inserts (#67) ## What is the goal of this PR? We validate that match-inserts only match 1 answer before doing inserts. This is disableable with a new flag `--allowMultiInserts` ## What are the changes implemented in this PR? * Fix a bunch of tests that relied on `toString()` for equality checks on TypeQL insert queries * Verify that match-inserts only receive 1 `match` answer before doing inserts. We rewrite `match-insert` with constraints into a `match` using IIDs or Labels to do avoid doing the complex `match` multiple times --- .DS_Store | Bin 0 -> 6148 bytes build.gradle | 2 +- .../typedb/osi/loader/cli/LoadOptions.java | 3 + .../generator/AppendAttributeGenerator.java | 23 +- ...AppendAttributeOrInsertThingGenerator.java | 34 +- .../loader/generator/AttributeGenerator.java | 5 +- .../osi/loader/generator/EntityGenerator.java | 13 +- .../osi/loader/generator/Generator.java | 2 +- .../loader/generator/RelationGenerator.java | 22 +- .../typedb/osi/loader/io/FileLogger.java | 24 ++ .../osi/loader/loader/AsyncLoaderWorker.java | 13 +- .../osi/loader/loader/TypeDBLoader.java | 2 +- .../typedb/osi/loader/util/TypeDBUtil.java | 48 ++- .../AppendAttributeGeneratorTest.java | 95 ++--- ...ndAttributeOrInsertThingGeneratorTest.java | 41 +-- .../generator/AttributeGeneratorTest.java | 13 +- .../loader/generator/EntityGeneratorTest.java | 313 ++++++++-------- .../generator/RelationGeneratorTest.java | 335 +++++++++--------- .../osi/loader/loader/TypeDBLoaderTest.java | 3 +- 19 files changed, 550 insertions(+), 441 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1a91d6b86f296cf5a5c406990fd5f41e04228515 GIT binary patch literal 6148 zcmeHKv2GJV6r9C&xB!Jkg`yx`l?qVu1Lz2*MUjk9O2={JShD31NJDi}DhgUk@)fiZ zQG(Kjbkvd3A<-ZTq$u-tH@>$yo6-WbPuiWkeQ$5(#&^3u0A_iovjo%uBy57!TkOV! z zOXj|{K3_aNdJ^V4f6Q-fsIuVd2t_B!?o)ShJ}*J zRe>I4g`RD!p@Tj)v>x;F*UCuGs6y-c_~7oz_s2?)sw(tMuF`tU>JQOVqdz@r*}$6C z0xZaKtg>3iesgyBII}u}ibBKq3e68JI{r3)mma<7X#UDJK3M)yR`c(j9W4HIKGdKp z3jXmGn!oZk6aE=Kl_M9m0^t1odR}YT-~IaO;j2S=K7(uMCu35L)*-tZqk`Aeu^uR> z&2)>5=KkF~z2f%sG;28<@Fl76O)K2pA-O#*!pIXHhz|TS4#@hDvI%A$bBA{6U}rx8 zh*b{T;Bj3Jh^fcSWA2a{hH+DgZmRL07{*QKcAI-c41FBD_hIiA{b zn9O19qXW@_(1D6Ot;_!ZZ1VSiI4Pb*2ciT2l>?^QXf~F4OMY)H-JI;TDO-z8Lh5pd mb_zSc9oqxhitn-6U@nydV&*Y-$Pq^TBVcWaU36fo4qO7a?BHDh literal 0 HcmV?d00001 diff --git a/build.gradle b/build.gradle index 96ea498..7b2b337 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'com.vaticle.typedb-osi' -version '1.4.2' +version '1.5.0' repositories { mavenCentral() diff --git a/src/main/java/com/vaticle/typedb/osi/loader/cli/LoadOptions.java b/src/main/java/com/vaticle/typedb/osi/loader/cli/LoadOptions.java index c45495d..84f2b2b 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/cli/LoadOptions.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/cli/LoadOptions.java @@ -38,6 +38,9 @@ public class LoadOptions { @CommandLine.Option(names = {"-ls", "--loadSchema"}, description = "optional - reload schema when continuing a migration (ignored when clean migration)", defaultValue = "false") public boolean loadSchema; + @CommandLine.Option(names = {"-mi", "--allowMultiInsert"}, description = "Allow match-inserts to match multiple answers and insert for each.", defaultValue = "false") + public boolean multiInsert; + public static LoadOptions parse(String[] args) { CommandLine commandLine = new CommandLine(new TypeDBLoaderCLI()) .addSubcommand("load", new LoadOptions()); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java index c059d3a..a88ca6a 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java @@ -17,10 +17,12 @@ package com.vaticle.typedb.osi.loader.generator; import com.vaticle.typedb.client.api.TypeDBTransaction; +import com.vaticle.typedb.client.api.answer.ConceptMap; import com.vaticle.typedb.client.common.exception.TypeDBClientException; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; +import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; @@ -33,6 +35,9 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; + +import static com.vaticle.typedb.osi.loader.util.TypeDBUtil.safeInsert; public class AppendAttributeGenerator implements Generator { private static final Logger dataLogger = LogManager.getLogger("com.vaticle.typedb.osi.loader.error"); @@ -48,8 +53,8 @@ public AppendAttributeGenerator(String filePath, Configuration.Generator.AppendA this.fileSeparator = fileSeparator; } - public void write(TypeDBTransaction tx, - String[] row) { + @Override + public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) { String fileName = FilenameUtils.getName(filePath); String fileNoExtension = FilenameUtils.removeExtension(fileName); String originalRow = String.join(Character.toString(fileSeparator), row); @@ -59,18 +64,24 @@ public void write(TypeDBTransaction tx, dataLogger.error("Malformed Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_malformed.log" + ">"); } - TypeQLInsert statement = generateMatchInsertStatement(row); + TypeQLInsert query = generateMatchInsertStatement(row); - if (appendAttributeInsertStatementValid(statement)) { + if (appendAttributeInsertStatementValid(query)) { try { - tx.query().insert(statement); + Iterator answers = TypeDBUtil.executeMatch(tx, query); + if (!answers.hasNext()) { + FileLogger.getLogger().logNoMatches(fileName, originalRow); + dataLogger.error("Match-insert failed - File <" + filePath + "> row <" + originalRow + "> generates query <" + query + "> which matched no answers."); + } else { + safeInsert(tx, query, answers, allowMultiInsert, filePath, originalRow, dataLogger); + } } catch (TypeDBClientException typeDBClientException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } } else { FileLogger.getLogger().logInvalid(fileName, originalRow); - dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + statement.toString().replace("\n", " ") + ">"); + dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + query.toString().replace("\n", " ") + ">"); } } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java index 15f6914..d4c682d 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java @@ -22,6 +22,7 @@ import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; +import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; @@ -34,8 +35,11 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.stream.Stream; +import static com.vaticle.typedb.osi.loader.util.TypeDBUtil.safeInsert; + public class AppendAttributeOrInsertThingGenerator implements Generator { private static final Logger dataLogger = LogManager.getLogger("com.vaticle.typedb.osi.loader.error"); private final String filePath; @@ -50,8 +54,8 @@ public AppendAttributeOrInsertThingGenerator(String filePath, Configuration.Gene this.fileSeparator = fileSeparator; } - public void write(TypeDBTransaction tx, - String[] row) { + @Override + public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) { String fileName = FilenameUtils.getName(filePath); String fileNoExtension = FilenameUtils.removeExtension(fileName); String originalRow = String.join(Character.toString(fileSeparator), row); @@ -61,30 +65,32 @@ public void write(TypeDBTransaction tx, dataLogger.error("Malformed Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_malformed.log" + ">"); } - TypeQLInsert appendStatement = generateMatchInsertStatement(row); - TypeQLInsert insertStatement = generateThingInsertStatement(row); + TypeQLInsert appendQuery = generateMatchInsertStatement(row); + TypeQLInsert insertQuery = generateThingInsertStatement(row); - if (appendAttributeInsertStatementValid(appendStatement)) { + if (appendAttributeInsertStatementValid(appendQuery)) { try { - final Stream insertedStream = tx.query().insert(appendStatement); - if (insertedStream.count() == 0) { - if (thingInsertStatementValid(insertStatement)) { - tx.query().insert(insertStatement); + Iterator answers = TypeDBUtil.executeMatch(tx, appendQuery); + if (!answers.hasNext()) { + if (thingInsertStatementValid(insertQuery)) { + tx.query().insert(insertQuery); } else { FileLogger.getLogger().logInvalid(fileName, originalRow); - dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + insertStatement.toString().replace("\n", " ") + ">"); + dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + insertQuery.toString().replace("\n", " ") + ">"); } + } else { + safeInsert(tx, appendQuery, answers, allowMultiInsert, filePath, originalRow, dataLogger); } } catch (TypeDBClientException typeDBClientException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } } else { - if (thingInsertStatementValid(insertStatement)) { - tx.query().insert(insertStatement); + if (thingInsertStatementValid(insertQuery)) { + tx.query().insert(insertQuery); } else { FileLogger.getLogger().logInvalid(fileName, originalRow); - dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statements: <" + appendStatement.toString().replace("\n", " ") + "> and <" + insertStatement.toString().replace("\n", " ") + ">"); + dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statements: <" + appendQuery.toString().replace("\n", " ") + "> and <" + insertQuery.toString().replace("\n", " ") + ">"); } } } @@ -149,7 +155,7 @@ public boolean appendAttributeInsertStatementValid(TypeQLInsert insert) { if (insert == null) return false; if (!insert.toString().contains("isa " + appendOrInsertConfiguration.getMatch().getType())) return false; for (Configuration.Definition.Attribute ownershipThingGetter : appendOrInsertConfiguration.getMatch().getOwnerships()) { - if (!insert.toString().contains(", has " + ownershipThingGetter.getAttribute())) return false; + if (!insert.toString().contains("has " + ownershipThingGetter.getAttribute())) return false; } if (appendOrInsertConfiguration.getInsert().getRequiredOwnerships() != null) { for (Configuration.Definition.Attribute attribute : appendOrInsertConfiguration.getInsert().getRequiredOwnerships()) { diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java index 375195f..5fd11fa 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java @@ -47,7 +47,8 @@ public AttributeGenerator(String filePath, Configuration.Generator.Attribute att this.fileSeparator = fileSeparator; } - public void write(TypeDBTransaction tx, String[] row) { + @Override + public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) { String fileName = FilenameUtils.getName(filePath); String fileNoExtension = FilenameUtils.removeExtension(fileName); @@ -62,7 +63,7 @@ public void write(TypeDBTransaction tx, String[] row) { if (isValid(statement)) { try { tx.query().insert(statement); - } catch (TypeDBClientException graknClientException) { + } catch (TypeDBClientException clientException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java index 5028e09..2a7a858 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java @@ -21,6 +21,7 @@ import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; +import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.pattern.variable.ThingVariable; @@ -45,8 +46,8 @@ public EntityGenerator(String filePath, Configuration.Generator.Entity entityCon this.fileSeparator = fileSeparator; } - public void write(TypeDBTransaction tx, - String[] row) { + @Override + public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) { String fileName = FilenameUtils.getName(filePath); String fileNoExtension = FilenameUtils.removeExtension(fileName); String originalRow = String.join(Character.toString(fileSeparator), row); @@ -56,17 +57,17 @@ public void write(TypeDBTransaction tx, dataLogger.error("Malformed Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_malformed.log" + ">"); } - TypeQLInsert statement = generateThingInsertStatement(row); - if (valid(statement)) { + TypeQLInsert query = generateThingInsertStatement(row); + if (valid(query)) { try { - tx.query().insert(statement); + tx.query().insert(query); } catch (TypeDBClientException typeDBClientException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } } else { FileLogger.getLogger().logInvalid(fileName, originalRow); - dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + statement.toString().replace("\n", " ") + ">"); + dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + query.toString().replace("\n", " ") + ">"); } } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java index a0c3333..b8ae391 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java @@ -19,6 +19,6 @@ import com.vaticle.typedb.client.api.TypeDBTransaction; public interface Generator { - void write(TypeDBTransaction tx, String[] row); + void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert); char getFileSeparator(); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java index 91d2865..89cb070 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java @@ -17,10 +17,12 @@ package com.vaticle.typedb.osi.loader.generator; import com.vaticle.typedb.client.api.TypeDBTransaction; +import com.vaticle.typedb.client.api.answer.ConceptMap; import com.vaticle.typedb.client.common.exception.TypeDBClientException; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; +import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; @@ -33,8 +35,10 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import static com.vaticle.typedb.osi.loader.util.GeneratorUtil.constrainThingWithHasAttributes; +import static com.vaticle.typedb.osi.loader.util.TypeDBUtil.safeInsert; public class RelationGenerator implements Generator { private static final Logger dataLogger = LogManager.getLogger("com.vaticle.typedb.osi.loader.error"); @@ -50,8 +54,8 @@ public RelationGenerator(String filePath, Configuration.Generator.Relation relat this.fileSeparator = fileSeparator; } - public void write(TypeDBTransaction tx, - String[] row) { + @Override + public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) { String fileName = FilenameUtils.getName(filePath); String fileNoExtension = FilenameUtils.removeExtension(fileName); String originalRow = String.join(Character.toString(fileSeparator), row); @@ -61,18 +65,24 @@ public void write(TypeDBTransaction tx, dataLogger.error("Malformed Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_malformed.log" + ">"); } - TypeQLInsert statement = generateMatchInsertStatement(row); + TypeQLInsert query = generateMatchInsertStatement(row); - if (relationInsertStatementValid(statement)) { + if (relationInsertStatementValid(query)) { try { - tx.query().insert(statement); + Iterator answers = TypeDBUtil.executeMatch(tx, query); + if (!answers.hasNext()) { + FileLogger.getLogger().logNoMatches(fileName, originalRow); + dataLogger.error("Match-insert failed - File <" + filePath + "> row <" + originalRow + "> generates query <" + query + "> which matched no answers."); + } else { + safeInsert(tx, query, answers, allowMultiInsert, filePath, originalRow, dataLogger); + } } catch (TypeDBClientException typeDBClientException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } } else { FileLogger.getLogger().logInvalid(fileName, originalRow); - dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + statement.toString().replace("\n", " ") + ">"); + dataLogger.error("Invalid Row detected in <" + filePath + "> - written to <" + fileNoExtension + "_invalid.log" + "> - invalid Statement: <" + query.toString().replace("\n", " ") + ">"); } } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/io/FileLogger.java b/src/main/java/com/vaticle/typedb/osi/loader/io/FileLogger.java index 4b95939..a0f7ed1 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/io/FileLogger.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/io/FileLogger.java @@ -82,6 +82,30 @@ public synchronized void logUnavailable(String sourceFile, String errorString) { } } + public void logNoMatches(String sourceFile, String row) { + try { + FileWriter fw = new FileWriter(directoryString + "/" + FilenameUtils.removeExtension(sourceFile) + "_no_matches.log", true); + fw.append(row.replace("null", "")); + fw.append("\n"); + fw.flush(); + fw.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + + public void logTooManyMatches(String sourceFile, String row) { + try { + FileWriter fw = new FileWriter(directoryString + "/" + FilenameUtils.removeExtension(sourceFile) + "_too_many_matches.log", true); + fw.append(row.replace("null", "")); + fw.append("\n"); + fw.flush(); + fw.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + public synchronized void logColumnWarnings(String sourceFile, String errorString) { try { FileWriter fw = new FileWriter(directoryString + "/" + FilenameUtils.removeExtension(sourceFile) + "_column_type.log", true); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java b/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java index ce3c58d..6c9265e 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java @@ -21,6 +21,7 @@ import com.vaticle.typedb.client.api.TypeDBTransaction; import com.vaticle.typedb.common.collection.Either; import com.vaticle.typedb.common.concurrent.NamedThreadFactory; +import com.vaticle.typedb.osi.loader.cli.LoadOptions; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.generator.AppendAttributeGenerator; import com.vaticle.typedb.osi.loader.generator.AppendAttributeOrInsertThingGenerator; @@ -52,23 +53,25 @@ public class AsyncLoaderWorker { private static final DecimalFormat countFormat = new DecimalFormat("#,###"); private static final DecimalFormat decimalFormat = new DecimalFormat("#,###.00"); + private final Configuration dc; + private final LoadOptions loadOptions; private final ExecutorService executor; private final int threads; private final String databaseName; private final AtomicBoolean hasError; private final int batchGroup; - private final Configuration dc; private Status status; private enum Status {OK, ERROR} - public AsyncLoaderWorker(Configuration dc, String databaseName) { + public AsyncLoaderWorker(Configuration dc, LoadOptions loadOptions) { this.dc = dc; + this.loadOptions = loadOptions; this.threads = dc.getGlobalConfig().getParallelisation(); - this.databaseName = databaseName; + this.databaseName = loadOptions.databaseName; this.hasError = new AtomicBoolean(false); this.batchGroup = 1; - this.executor = Executors.newFixedThreadPool(threads, new NamedThreadFactory(databaseName)); + this.executor = Executors.newFixedThreadPool(threads, new NamedThreadFactory(this.databaseName)); this.status = Status.OK; } @@ -379,7 +382,7 @@ private CompletableFuture asyncWrite(int id, try (TypeDBTransaction tx = session.transaction(TypeDBTransaction.Type.WRITE)) { rows.forEach(csv -> { Util.debug("async-writer-{}: {}", id, csv); - gen.write(tx, csv); + gen.write(tx, csv, loadOptions.multiInsert); }); tx.commit(); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java b/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java index d94f80d..b391b20 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java @@ -87,7 +87,7 @@ public void load() { Runtime.getRuntime().addShutdownHook( NamedThreadFactory.create(AsyncLoaderWorker.class, "shutdown").newThread(client::close) ); - asyncLoaderWorker = new AsyncLoaderWorker(dc, options.databaseName); + asyncLoaderWorker = new AsyncLoaderWorker(dc, options); asyncLoaderWorker.run(client); } finally { if (asyncLoaderWorker != null) asyncLoaderWorker.close(); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java b/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java index d4b52ae..ede63d4 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java @@ -20,8 +20,19 @@ import com.vaticle.typedb.client.api.TypeDBClient; import com.vaticle.typedb.client.api.TypeDBSession; import com.vaticle.typedb.client.api.TypeDBTransaction; +import com.vaticle.typedb.client.api.answer.ConceptMap; +import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typeql.lang.TypeQL; +import com.vaticle.typeql.lang.pattern.variable.BoundVariable; +import com.vaticle.typeql.lang.pattern.variable.ThingVariable; import com.vaticle.typeql.lang.query.TypeQLDefine; +import com.vaticle.typeql.lang.query.TypeQLInsert; +import org.apache.commons.io.FilenameUtils; +import org.apache.logging.log4j.Logger; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import static com.vaticle.typedb.osi.loader.util.Util.loadSchemaFromFile; @@ -59,7 +70,7 @@ public static void cleanAndDefineSchemaToDatabase(TypeDBClient client, String da loadAndDefineSchema(client, databaseName, schemaPath); } - private static void defineToGrakn(TypeDBClient client, String databaseName, String schemaAsString) { + private static void defineToTypeDB(TypeDBClient client, String databaseName, String schemaAsString) { TypeDBSession schemaSession = getSchemaSession(client, databaseName); TypeQLDefine q = TypeQL.parseQuery(schemaAsString); @@ -75,7 +86,40 @@ private static void defineToGrakn(TypeDBClient client, String databaseName, Stri public static void loadAndDefineSchema(TypeDBClient client, String databaseName, String schemaPath) { String schema = loadSchemaFromFile(schemaPath); - defineToGrakn(client, databaseName, schema); + defineToTypeDB(client, databaseName, schema); + } + + public static Iterator executeMatch(TypeDBTransaction tx, TypeQLInsert query) { + if (!query.match().isPresent()) throw new RuntimeException("Expected TypeQL 'match' to be present"); + return tx.query().match(query.match().get()).iterator(); } + public static void safeInsert(TypeDBTransaction tx, TypeQLInsert query, Iterator matches, boolean allowMultiInsert, String filePath, String row, Logger dataLogger) { + assert query.match().isPresent(); + String fileName = FilenameUtils.getName(filePath); + ConceptMap answer = matches.next(); + if (!allowMultiInsert && matches.hasNext()) { + FileLogger.getLogger().logTooManyMatches(fileName, row); + dataLogger.error("Match-insert skipped - File <" + filePath + "> row <" + row + "> generates query <" + query + "> which matched more than 1 answer."); + } else { + tx.query().insert(TypeDBUtil.replaceMatchWithAnswer(query, answer)); + while (matches.hasNext()) { + answer = matches.next(); + tx.query().insert(TypeDBUtil.replaceMatchWithAnswer(query, answer)); + } + } + } + + public static TypeQLInsert replaceMatchWithAnswer(TypeQLInsert query, ConceptMap ans) { + assert query.match().isPresent(); + List> insertVars = query.asInsert().variables(); + List matchVars = new ArrayList<>(); + ans.map().forEach((var, concept) -> { + if (concept.isThing()) matchVars.add(TypeQL.var(var).iid(concept.asThing().getIID())); + else if (concept.asType().getLabel().scope().isPresent()) { + matchVars.add(TypeQL.var(var).type(concept.asType().getLabel().scope().get(), concept.asType().getLabel().name())); + } else matchVars.add(TypeQL.var(var).type(concept.asType().getLabel().name())); + }); + return TypeQL.match(matchVars).insert(insertVars); + } } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java index 5cf4634..efc3759 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java @@ -21,6 +21,7 @@ import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; +import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.junit.Assert; import org.junit.Test; @@ -72,61 +73,61 @@ private void testTwitter(Configuration dc, ArrayList appendKeys) throws Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match $thing isa person, has phone-number \"+7 171 898 0853\";\n" + - "insert $thing has twitter-username \"@jojo\", has nick-name \"another\";"; - Assert.assertEquals(tmp, statement.toString()); + TypeQLInsert tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+7 171 898 0853\";\n" + + "insert $thing has twitter-username \"@jojo\", has nick-name \"another\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person, has phone-number \"+263 498 495 0617\";\n" + - "insert $thing has twitter-username \"@hui\", has twitter-username \"@bui\", has nick-name \"yetanoter\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+263 498 495 0617\";\n" + + "insert $thing has twitter-username \"@hui\", has twitter-username \"@bui\", has nick-name \"yetanoter\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person, has phone-number \"+370 351 224 5176\";\n" + - "insert $thing has twitter-username \"@lalulix\", has nick-name \"one more\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+370 351 224 5176\";\n" + + "insert $thing has twitter-username \"@lalulix\", has nick-name \"one more\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person, has phone-number \"+81 308 988 7153\";\n" + - "insert $thing has twitter-username \"@go34\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+81 308 988 7153\";\n" + + "insert $thing has twitter-username \"@go34\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person, has phone-number \"+54 398 559 0423\";\n" + - "insert $thing has twitter-username \"@hadaaa\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+54 398 559 0423\";\n" + + "insert $thing has twitter-username \"@hadaaa\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person, has phone-number \"+7 690 597 4443\";\n" + - "insert $thing has nick-name \"not inserted\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+7 690 597 4443\";\n" + + "insert $thing has nick-name \"not inserted\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person, has phone-number \"+63 815 962 6097\";\n" + - "insert $thing has twitter-username \"@kuka\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+63 815 962 6097\";\n" + + "insert $thing has twitter-username \"@kuka\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person;\n" + - "insert $thing has twitter-username \"@notinserted\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person;\n" + + "insert $thing has twitter-username \"@notinserted\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); } @@ -139,29 +140,29 @@ private void testFakebook(Configuration dc, ArrayList appendKeys) throws Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match $thing isa person, has phone-number \"+36 318 105 5629\";\n" + - "insert $thing has fakebook-link \"fakebook.com/personOne\";"; - Assert.assertEquals(tmp, statement.toString()); + TypeQLInsert tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+36 318 105 5629\";\n" + + "insert $thing has fakebook-link \"fakebook.com/personOne\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); iterator.next(); iterator.next(); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person, has phone-number \"+62 533 266 3426\";\n" + - "insert $thing has fakebook-link \"insertedWithoutAppliedRegex\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+62 533 266 3426\";\n" + + "insert $thing has fakebook-link \"insertedWithoutAppliedRegex\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa person;\n" + - "insert $thing has fakebook-link \"@notinserted\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person;\n" + + "insert $thing has fakebook-link \"@notinserted\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); } @@ -173,9 +174,9 @@ private void testCallAppend(Configuration dc, ArrayList appendKeys) thro Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match $thing isa call, has started-at 2018-09-19T01:00:38;\n" + - "insert $thing has call-rating 5;"; - Assert.assertEquals(tmp, statement.toString()); + TypeQLInsert tmp = TypeQL.parseQuery("match $thing isa call, has started-at 2018-09-19T01:00:38;\n" + + "insert $thing has call-rating 5;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); iterator.next(); @@ -184,14 +185,14 @@ private void testCallAppend(Configuration dc, ArrayList appendKeys) thro iterator.next(); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $thing isa call;\n" + - "insert $thing has call-rating 4;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa call;\n" + + "insert $thing has call-rating 4;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); } } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java index 337e37d..330dcaf 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java @@ -22,6 +22,7 @@ import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; +import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.junit.Assert; import org.junit.Test; @@ -70,37 +71,37 @@ private void testPerson(Configuration dc, ArrayList appendKeys) throws I String[] row = Util.parseCSV(iterator.next()); TypeQLInsert statement = gen.generateMatchInsertStatement(row); - String tmp = "match $thing isa person, has phone-number \"+7 171 898 0853\";\n" + - "insert $thing has first-name \"Melli\", has last-name \"Winchcum\", has city \"London\", has age 55, has nick-name \"Mel\";"; - Assert.assertEquals(tmp, statement.toString()); + TypeQLInsert tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+7 171 898 0853\";\n" + + "insert $thing has first-name \"Melli\", has last-name \"Winchcum\", has city \"London\", has age 55, has nick-name \"Mel\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateThingInsertStatement(row); - tmp = "insert $e isa person, has phone-number \"+7 171 898 0853\", has first-name \"Melli\", has last-name \"Winchcum\", has city \"London\", has age 55, has nick-name \"Mel\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+7 171 898 0853\", has first-name \"Melli\", has last-name \"Winchcum\", has city \"London\", has age 55, has nick-name \"Mel\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.thingInsertStatementValid(statement)); row = Util.parseCSV(iterator.next()); statement = gen.generateMatchInsertStatement(row); - tmp = "match $thing isa person;\n" + - "insert $thing has first-name \"Sakura\", has city \"Fire Village\", has age 13;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person;\n" + + "insert $thing has first-name \"Sakura\", has city \"Fire Village\", has age 13;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateThingInsertStatement(row); - tmp = "insert $e isa person, has first-name \"Sakura\", has city \"Fire Village\", has age 13;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Sakura\", has city \"Fire Village\", has age 13;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.thingInsertStatementValid(statement)); iterator.next(); row = Util.parseCSV(iterator.next()); statement = gen.generateMatchInsertStatement(row); - tmp = "match $thing isa person, has phone-number \"+62 107 666 3334\";\n" + - "insert $thing has first-name \"Sasuke\", has city \"Fire Village\", has age 13;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+62 107 666 3334\";\n" + + "insert $thing has first-name \"Sasuke\", has city \"Fire Village\", has age 13;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateThingInsertStatement(row); - tmp = "insert $e isa person, has phone-number \"+62 107 666 3334\", has first-name \"Sasuke\", has city \"Fire Village\", has age 13;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+62 107 666 3334\", has first-name \"Sasuke\", has city \"Fire Village\", has age 13;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.thingInsertStatementValid(statement)); iterator.next(); @@ -108,13 +109,13 @@ private void testPerson(Configuration dc, ArrayList appendKeys) throws I row = Util.parseCSV(iterator.next()); statement = gen.generateMatchInsertStatement(row); - tmp = "match $thing isa person, has phone-number \"+62 107 321 3333\";\n" + - "insert $thing has first-name \"Missing\", has last-name \"Age\", has city \"notinsertcity\", has nick-name \"notinsertnickname\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $thing isa person, has phone-number \"+62 107 321 3333\";\n" + + "insert $thing has first-name \"Missing\", has last-name \"Age\", has city \"notinsertcity\", has nick-name \"notinsertnickname\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.appendAttributeInsertStatementValid(statement)); statement = gen.generateThingInsertStatement(row); - tmp = "insert $e isa person, has phone-number \"+62 107 321 3333\", has first-name \"Missing\", has last-name \"Age\", has city \"notinsertcity\", has nick-name \"notinsertnickname\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+62 107 321 3333\", has first-name \"Missing\", has last-name \"Age\", has city \"notinsertcity\", has nick-name \"notinsertnickname\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.thingInsertStatementValid(statement)); diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java index 39f247e..08cc6ba 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java @@ -21,6 +21,7 @@ import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; +import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.junit.Assert; import org.junit.Test; @@ -58,13 +59,13 @@ public void generateInsertStatementsTest() throws IOException { String[] row = Util.parseCSV(iterator.next()); List insertStatements = gen.generateInsertStatements(row); - String tmp = "insert $a \"yes\" isa is-in-use;"; - Assert.assertEquals(tmp, insertStatements.get(0).toString()); + TypeQLInsert tmp = TypeQL.parseQuery("insert $a \"yes\" isa is-in-use;").asInsert(); + Assert.assertEquals(tmp, insertStatements.get(0)); row = Util.parseCSV(iterator.next()); insertStatements = gen.generateInsertStatements(row); - tmp = "insert $a \"no\" isa is-in-use;"; - Assert.assertEquals(tmp, insertStatements.get(0).toString()); + tmp = TypeQL.parseQuery("insert $a \"no\" isa is-in-use;").asInsert(); + Assert.assertEquals(tmp, insertStatements.get(0)); try { Util.parseCSV(iterator.next()); @@ -74,7 +75,7 @@ public void generateInsertStatementsTest() throws IOException { row = Util.parseCSV(iterator.next()); insertStatements = gen.generateInsertStatements(row); - tmp = "insert $a \"5\" isa is-in-use;"; - Assert.assertEquals(tmp, insertStatements.get(0).toString()); + tmp = TypeQL.parseQuery("insert $a \"5\" isa is-in-use;").asInsert(); + Assert.assertEquals(tmp, insertStatements.get(0)); } } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java index 2002563..96c9360 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java @@ -21,6 +21,7 @@ import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; +import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.junit.Assert; import org.junit.Test; @@ -60,65 +61,65 @@ public void genericEntityTest() throws IOException { Objects.requireNonNullElseGet(dc.getEntities().get(entityKeys.get(0)).getConfig().getSeparator(), () -> dc.getGlobalConfig().getSeparator())); Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); - String tmp = "insert $e isa entity1, has entity1-id \"entity1id0\", has entity1-name \"entity1name0\", has entity1-exp \"entity1id0exp0\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + TypeQLInsert tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id0\", has entity1-name \"entity1name0\", has entity1-exp \"entity1id0exp0\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id1\", has entity1-name \"entity1name1\", has entity1-exp \"entity1id1exp11\", has entity1-exp \"entity1id1exp12\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id1\", has entity1-name \"entity1name1\", has entity1-exp \"entity1id1exp11\", has entity1-exp \"entity1id1exp12\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id2\", has entity1-name \"entity1name2\", has entity1-exp \"entity1id2exp21\", has entity1-exp \"entity1id2exp22\", has entity1-exp \"entity1id2exp23\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id2\", has entity1-name \"entity1name2\", has entity1-exp \"entity1id2exp21\", has entity1-exp \"entity1id2exp22\", has entity1-exp \"entity1id2exp23\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id3\", has entity1-name \"entity1name3\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id3\", has entity1-name \"entity1name3\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id4\", has entity1-name \"entity1name4\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id4\", has entity1-name \"entity1name4\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id5\", has entity1-name \"entity1name5\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id5\", has entity1-name \"entity1name5\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id6\", has entity1-name \"entity1name6\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id6\", has entity1-name \"entity1name6\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id7\", has entity1-name \"entity1name7\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id7\", has entity1-name \"entity1name7\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id8\", has entity1-name \"entity1name8\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id8\", has entity1-name \"entity1name8\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id9\", has entity1-name \"entity1name9\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id9\", has entity1-name \"entity1name9\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id10\", has entity1-name \"entity1name10\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id10\", has entity1-name \"entity1name10\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id11\", has entity1-name \"entity1name11\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id11\", has entity1-name \"entity1name11\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id12\", has entity1-name \"entity1name12\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id12\", has entity1-name \"entity1name12\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id13\", has entity1-name \"entity1name13\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id13\", has entity1-name \"entity1name13\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id14\", has entity1-name \"entity1name14\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id14\", has entity1-name \"entity1name14\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id15\", has entity1-name \"entity1name15\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id15\", has entity1-name \"entity1name15\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id16\", has entity1-name \"entity1name16\", has entity1-name \"entity1name16-2\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id16\", has entity1-name \"entity1name16\", has entity1-name \"entity1name16-2\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id17\", has entity1-name \"entity1name17\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id17\", has entity1-name \"entity1name17\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id18\", has entity1-name \"entity1name18\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id18\", has entity1-name \"entity1name18\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity1, has entity1-id \"entity1id19\", has entity1-name \"entity1name19\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity1, has entity1-id \"entity1id19\", has entity1-name \"entity1name19\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); dp = new File("src/test/resources/generic/entity2.tsv").getAbsolutePath(); @@ -126,38 +127,38 @@ public void genericEntityTest() throws IOException { Objects.requireNonNullElseGet(dc.getEntities().get(entityKeys.get(1)).getConfig().getSeparator(), () -> dc.getGlobalConfig().getSeparator())); iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); - tmp = "insert $e isa entity2, has entity2-id \"entity2id0\", has entity2-bool true, has entity2-double 0.0;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id0\", has entity2-bool true, has entity2-double 0.0;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id1\", has entity2-bool false, has entity2-double 1.1, has entity2-double 11.11;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id1\", has entity2-bool false, has entity2-double 1.1, has entity2-double 11.11;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id2\", has entity2-bool true, has entity2-double 2.2;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id2\", has entity2-bool true, has entity2-double 2.2;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id3\", has entity2-bool false, has entity2-double -3.3;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id3\", has entity2-bool false, has entity2-double -3.3;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id4\", has entity2-double 4.0;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id4\", has entity2-double 4.0;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id5\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id5\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id6\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id6\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id7\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id7\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id8\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id8\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id9\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id9\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity2, has entity2-id \"entity2id10\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity2, has entity2-id \"entity2id10\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); dp = new File("src/test/resources/generic/entity3.tsv").getAbsolutePath(); @@ -165,38 +166,38 @@ public void genericEntityTest() throws IOException { Objects.requireNonNullElseGet(dc.getEntities().get(entityKeys.get(2)).getConfig().getSeparator(), () -> dc.getGlobalConfig().getSeparator())); iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); - tmp = "insert $e isa entity3, has entity3-id \"entity3id0\", has entity3-int 0;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id0\", has entity3-int 0;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id1\", has entity3-int 1, has entity3-int 11;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id1\", has entity3-int 1, has entity3-int 11;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id2\", has entity3-int 2;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id2\", has entity3-int 2;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id3\", has entity3-int -3;"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id3\", has entity3-int -3;").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id4\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id4\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id5\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id5\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id6\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id6\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id7\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id7\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id8\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id8\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id9\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id9\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); - tmp = "insert $e isa entity3, has entity3-id \"entity3id10\";"; - Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next())).toString()); + tmp = TypeQL.parseQuery("insert $e isa entity3, has entity3-id \"entity3id10\";").asInsert(); + Assert.assertEquals(tmp, gen.generateThingInsertStatement(Util.parseTSV(iterator.next()))); } @Test @@ -225,183 +226,183 @@ public void phoneCallsPersonTest() throws IOException { Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "insert $e isa person, has first-name \"Melli\", has last-name \"Winchcum\", has phone-number \"+7 171 898 0853\", has city \"London\", has age 55;"; - Assert.assertEquals(tmp, statement.toString()); + TypeQLInsert tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Melli\", has last-name \"Winchcum\", has phone-number \"+7 171 898 0853\", has city \"London\", has age 55;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Celinda\", has last-name \"Bonick\", has phone-number \"+370 351 224 5176\", has city \"London\", has age 52;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Celinda\", has last-name \"Bonick\", has phone-number \"+370 351 224 5176\", has city \"London\", has age 52;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Chryste\", has last-name \"Lilywhite\", has phone-number \"+81 308 988 7153\", has city \"London\", has age 66;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Chryste\", has last-name \"Lilywhite\", has phone-number \"+81 308 988 7153\", has city \"London\", has age 66;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"D'arcy\", has last-name \"Byfford\", has phone-number \"+54 398 559 0423\", has city \"London\", has age 19, has nick-name \"D\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"D'arcy\", has last-name \"Byfford\", has phone-number \"+54 398 559 0423\", has city \"London\", has age 19, has nick-name \"D\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Xylina\", has last-name \"D'Alesco\", has phone-number \"+7 690 597 4443\", has city \"Cambridge\", has age 51;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Xylina\", has last-name \"D'Alesco\", has phone-number \"+7 690 597 4443\", has city \"Cambridge\", has age 51;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Roldan\", has last-name \"Cometti\", has phone-number \"+263 498 495 0617\", has city \"Oxford\", has age 59, has nick-name \"Rolly\", has nick-name \"Rolli\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Roldan\", has last-name \"Cometti\", has phone-number \"+263 498 495 0617\", has city \"Oxford\", has age 59, has nick-name \"Rolly\", has nick-name \"Rolli\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Cob\", has last-name \"Lafflin\", has phone-number \"+63 815 962 6097\", has city \"Cambridge\", has age 56;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Cob\", has last-name \"Lafflin\", has phone-number \"+63 815 962 6097\", has city \"Cambridge\", has age 56;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Olag\", has last-name \"Heakey\", has phone-number \"+81 746 154 2598\", has city \"London\", has age 45;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Olag\", has last-name \"Heakey\", has phone-number \"+81 746 154 2598\", has city \"London\", has age 45;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Mandie\", has last-name \"Assender\", has phone-number \"+261 860 539 4754\", has city \"London\", has age 18;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Mandie\", has last-name \"Assender\", has phone-number \"+261 860 539 4754\", has city \"London\", has age 18;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Elenore\", has last-name \"Stokey\", has phone-number \"+62 107 530 7500\", has city \"Oxford\", has age 35;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Elenore\", has last-name \"Stokey\", has phone-number \"+62 107 530 7500\", has city \"Oxford\", has age 35;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+86 921 547 9004\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+86 921 547 9004\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+48 894 777 5173\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+48 894 777 5173\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+86 922 760 0418\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+86 922 760 0418\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+33 614 339 0298\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+33 614 339 0298\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+30 419 575 7546\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+30 419 575 7546\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+7 414 625 3019\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+7 414 625 3019\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+57 629 420 5680\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+57 629 420 5680\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+351 515 605 7915\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+351 515 605 7915\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+36 318 105 5629\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+36 318 105 5629\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+63 808 497 1769\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+63 808 497 1769\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+62 533 266 3426\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+62 533 266 3426\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+351 272 414 6570\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+351 272 414 6570\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+86 825 153 5518\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+86 825 153 5518\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+86 202 257 8619\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+86 202 257 8619\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+27 117 258 4149\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+27 117 258 4149\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+48 697 447 6933\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+48 697 447 6933\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+48 195 624 2025\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+48 195 624 2025\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+1 254 875 4647\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+1 254 875 4647\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+7 552 196 4096\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+7 552 196 4096\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has phone-number \"+86 892 682 0628\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has phone-number \"+86 892 682 0628\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"John\", has last-name \"Smith\", has phone-number \"+62 999 888 7777\", has city \"London\", has age 43, has nick-name \"Jack\", has nick-name \"J\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"John\", has last-name \"Smith\", has phone-number \"+62 999 888 7777\", has city \"London\", has age 43, has nick-name \"Jack\", has nick-name \"J\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has first-name \"Jane\", has last-name \"Smith\", has phone-number \"+62 999 888 7778\", has city \"London\", has age 43;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has first-name \"Jane\", has last-name \"Smith\", has phone-number \"+62 999 888 7778\", has city \"London\", has age 43;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has age 23;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has age 23;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person, has age 23;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person, has age 23;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.valid(statement)); statement = gen.generateThingInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $e isa person;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $e isa person;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.valid(statement)); } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java index d82f673..cd5673f 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java @@ -22,6 +22,7 @@ import com.vaticle.typedb.osi.loader.util.QueryUtilTest; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; +import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.junit.Assert; import org.junit.Test; @@ -67,194 +68,194 @@ public void genericRelationTest() throws IOException { Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - String tmp = "match\n" + + TypeQLInsert tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att0\", has relAt-1 \"explosion0\", has relAt-2 \"opt0\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att0\", has relAt-1 \"explosion0\", has relAt-2 \"opt0\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att1\", has relAt-1 \"explosion1\", has relAt-1 \"explo1\", has relAt-2 \"opt1\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att1\", has relAt-1 \"explosion1\", has relAt-1 \"explo1\", has relAt-2 \"opt1\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att2\", has relAt-2 \"opt2\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att2\", has relAt-2 \"opt2\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att3\", has relAt-2 \"opt3\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att3\", has relAt-2 \"opt3\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att4\", has relAt-2 \"opt4\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att4\", has relAt-2 \"opt4\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att5\", has relAt-2 \"opt5\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att5\", has relAt-2 \"opt5\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att6\", has relAt-2 \"opt6\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att6\", has relAt-2 \"opt6\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att7\", has relAt-2 \"opt7\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att7\", has relAt-2 \"opt7\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att8\", has relAt-2 \"opt8\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att8\", has relAt-2 \"opt8\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att9\", has relAt-2 \"opt9\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att9\", has relAt-2 \"opt9\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att10\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att10\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att19\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att19\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att20\", has relAt-2 \"opt20\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att20\", has relAt-2 \"opt20\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att21\", has relAt-1 \"explosion21\", has relAt-2 \"optional21\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att21\", has relAt-1 \"explosion21\", has relAt-2 \"optional21\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att22\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att22\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-2 \"opt25\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-2 \"opt25\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-1 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-two: $player-0, player-optional: $player-1) isa rel1, has relAt-1 \"att34\", has relAt-2 \"opt33\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-two: $player-0, player-optional: $player-1) isa rel1, has relAt-1 \"att34\", has relAt-2 \"opt33\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\";\n" + "$player-1 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-optional: $player-1) isa rel1, has relAt-1 \"att37\", has relAt-2 \"opt36\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-optional: $player-1) isa rel1, has relAt-1 \"att37\", has relAt-2 \"opt36\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\", has entity1-id \"entity1id2\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-2 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att39\", has relAt-2 \"opt39\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1, player-optional: $player-2) isa rel1, has relAt-1 \"att39\", has relAt-2 \"opt39\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity1, has entity1-id \"entity1id1\", has entity1-id \"entity1id2\";\n" + "$player-1 isa entity2, has entity2-id \"entity2id1\";\n" + - "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att40\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-one: $player-0, player-two: $player-1) isa rel1, has relAt-1 \"att40\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseTSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa entity2, has entity2-id \"entity2id1\";\n" + "$player-1 isa entity3, has entity3-id \"entity3id1\";\n" + - "insert $rel (player-two: $player-0, player-optional: $player-1) isa rel1, has relAt-1 \"att41\", has relAt-2 \"opt41\";"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (player-two: $player-0, player-optional: $player-1) isa rel1, has relAt-1 \"att41\", has relAt-2 \"opt41\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); } @@ -305,11 +306,11 @@ private void testContracts(Configuration dc, ArrayList relationKeys) thr Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match\n" + + TypeQLInsert tmp = TypeQL.parseQuery("match\n" + "$player-0 isa company, has name \"Telecom\";\n" + "$player-1 isa person, has phone-number \"+7 171 898 0853\";\n" + - "insert $rel (provider: $player-0, customer: $player-1) isa contract;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (provider: $player-0, customer: $player-1) isa contract;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); for (int i = 0; i < 7; i++) { @@ -317,22 +318,22 @@ private void testContracts(Configuration dc, ArrayList relationKeys) thr } statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); iterator.next(); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 isa person, has phone-number \"+261 860 539 4754\";\n" + - "insert $rel (customer: $player-0) isa contract;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 isa person, has phone-number \"+261 860 539 4754\";\n" + + "insert $rel (customer: $player-0) isa contract;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 isa company, has name \"Telecom\";\n" + - "insert $rel (provider: $player-0) isa contract;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 isa company, has name \"Telecom\";\n" + + "insert $rel (provider: $player-0) isa contract;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); for (int i = 0; i < 3; i++) { @@ -340,16 +341,16 @@ private void testContracts(Configuration dc, ArrayList relationKeys) thr } statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa company, has name \"Telecom\";\n" + "$player-1 isa person, has phone-number \"+62 107 530 7500\", has phone-number \"+261 860 539 4754\";\n" + - "insert $rel (provider: $player-0, customer: $player-1) isa contract;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (provider: $player-0, customer: $player-1) isa contract;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); } @@ -362,11 +363,11 @@ private void testCalls(Configuration dc, ArrayList relationKeys) throws Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match\n" + + TypeQLInsert tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+54 398 559 0423\";\n" + "$player-1 isa person, has phone-number \"+48 195 624 2025\";\n" + - "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-16T22:24:19, has duration 122;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-16T22:24:19, has duration 122;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); for (int i = 0; i < 112; i++) { @@ -374,11 +375,11 @@ private void testCalls(Configuration dc, ArrayList relationKeys) throws } statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+63 815 962 6097\";\n" + "$player-1 isa person, has phone-number \"+263 498 495 0617\";\n" + - "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-19T23:16:49;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-19T23:16:49;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); for (int i = 0; i < 98; i++) { @@ -386,44 +387,44 @@ private void testCalls(Configuration dc, ArrayList relationKeys) throws } statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+63 815 962 6097\";\n" + "$player-1 isa person, has phone-number \"+7 552 196 4096\";\n" + - "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-23T01:14:56;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-23T01:14:56;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+63 815 962 6097\";\n" + "$player-1 isa person, has phone-number \"+7 552 196 4096\";\n" + - "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-23T01:14:56;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (caller: $player-0, callee: $player-1) isa call, has started-at 2018-09-23T01:14:56;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+63 815 962 6097\";\n" + "$player-1 isa person, has phone-number \"+7 552 196 4096\";\n" + - "insert $rel (caller: $player-0, callee: $player-1) isa call, has duration 53;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (caller: $player-0, callee: $player-1) isa call, has duration 53;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 isa person, has phone-number \"+63 815 962 6097\";\n" + - "insert $rel (caller: $player-0) isa call, has started-at 2018-09-23T01:14:56, has duration 53;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 isa person, has phone-number \"+63 815 962 6097\";\n" + + "insert $rel (caller: $player-0) isa call, has started-at 2018-09-23T01:14:56, has duration 53;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 isa person, has phone-number \"+7 552 196 4096\";\n" + - "insert $rel (callee: $player-0) isa call, has started-at 2018-09-23T01:14:56, has duration 53;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 isa person, has phone-number \"+7 552 196 4096\";\n" + + "insert $rel (callee: $player-0) isa call, has started-at 2018-09-23T01:14:56, has duration 53;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); } @@ -435,11 +436,11 @@ private void testInUse(Configuration dc, ArrayList relationKeys) throws Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match\n" + + TypeQLInsert tmp = TypeQL.parseQuery("match\n" + "$player-0 \"yes\" isa is-in-use;\n" + "$player-1 \"+7 171 898 0853\" isa phone-number;\n" + - "insert $rel (status: $player-0, account: $player-1) isa in-use;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (status: $player-0, account: $player-1) isa in-use;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); for (int i = 0; i < 4; i++) { @@ -447,8 +448,8 @@ private void testInUse(Configuration dc, ArrayList relationKeys) throws } statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); for (int i = 0; i < 2; i++) { @@ -456,9 +457,9 @@ private void testInUse(Configuration dc, ArrayList relationKeys) throws } statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 \"+62 107 530 7500\" isa phone-number;\n" + - "insert $rel (account: $player-0) isa in-use;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 \"+62 107 530 7500\" isa phone-number;\n" + + "insert $rel (account: $player-0) isa in-use;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); @@ -472,91 +473,91 @@ private void testCommunicationChannel(Configuration dc, ArrayList relati Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match\n" + + TypeQLInsert tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+54 398 559 0423\";\n" + "$player-1 isa person, has phone-number \"+48 195 624 2025\";\n" + "$player-2 isa call, has started-at 2018-09-16T22:24:19;\n" + - "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+263 498 495 0617\";\n" + "$player-1 isa person, has phone-number \"+33 614 339 0298\";\n" + "$player-2 isa call, has started-at 2018-09-11T22:10:34, has started-at 2018-09-12T22:10:34, has started-at 2018-09-13T22:10:34, has started-at 2018-09-14T22:10:34, has started-at 2018-09-15T22:10:34, has started-at 2018-09-16T22:10:34;\n" + - "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+263 498 495 0617\";\n" + "$player-1 isa person, has phone-number \"+33 614 339 0298\";\n" + "$player-2 isa call, has started-at 2018-09-11T22:10:34;\n" + - "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+370 351 224 5176\";\n" + "$player-1 isa person, has phone-number \"+62 533 266 3426\";\n" + "$player-2 isa call, has started-at 2018-09-15T12:12:59;\n" + - "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+62 533 266 3426\";\n" + "$player-1 isa call, has started-at 2018-09-15T12:12:59;\n" + - "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+370 351 224 5176\";\n" + "$player-1 isa call, has started-at 2018-09-15T12:12:59;\n" + - "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 isa call, has started-at 2018-09-15T12:12:59;\n" + - "insert $rel (past-call: $player-0) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 isa call, has started-at 2018-09-15T12:12:59;\n" + + "insert $rel (past-call: $player-0) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+7 690 597 4443\";\n" + "$player-1 isa person, has phone-number \"+54 398 559 9999\";\n" + - "insert $rel (peer: $player-0, peer: $player-1) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, peer: $player-1) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 isa person, has phone-number \"+7 690 597 4443\";\n" + - "insert $rel (peer: $player-0) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 isa person, has phone-number \"+7 690 597 4443\";\n" + + "insert $rel (peer: $player-0) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 isa person, has phone-number \"+54 398 559 9999\";\n" + - "insert $rel (peer: $player-0) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 isa person, has phone-number \"+54 398 559 9999\";\n" + + "insert $rel (peer: $player-0) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); } @@ -569,60 +570,60 @@ private void testCommunicationChannelPM(Configuration dc, ArrayList rela Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); TypeQLInsert statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - String tmp = "match\n" + + TypeQLInsert tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+81 308 988 7153\";\n" + "$player-1 isa person, has phone-number \"+351 515 605 7915\";\n" + "$player-2-0 isa person, has phone-number \"+81 308 988 7153\";\n" + "$player-2-1 isa person, has phone-number \"+351 515 605 7915\";\n" + "$player-2 (caller: $player-2-0, callee: $player-2-1) isa call;\n" + - "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+7 171 898 0853\";\n" + "$player-1 isa person, has phone-number \"+57 629 420 5680\";\n" + "$player-2-0 isa person, has phone-number \"+7 171 898 0853\";\n" + "$player-2-1 isa person, has phone-number \"+57 629 420 5680\";\n" + "$player-2 (caller: $player-2-0, callee: $player-2-1) isa call;\n" + - "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, peer: $player-1, past-call: $player-2) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertTrue(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+261 860 539 4754\";\n" + "$player-1-0 isa person, has phone-number \"+261 860 539 4754\";\n" + "$player-1 (caller: $player-1-0, callee: $player-1-1) isa call;\n" + - "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 (caller: $player-0-0, callee: $player-0-1) isa call;\n" + - "insert $rel (past-call: $player-0) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 (caller: $player-0-0, callee: $player-0-1) isa call;\n" + + "insert $rel (past-call: $player-0) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match $player-0 (caller: $player-0-0, callee: $player-0-1) isa call;\n" + - "insert $rel (past-call: $player-0) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("match $player-0 (caller: $player-0-0, callee: $player-0-1) isa call;\n" + + "insert $rel (past-call: $player-0) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "insert $null isa null, has null \"null\";"; - Assert.assertEquals(tmp, statement.toString()); + tmp = TypeQL.parseQuery("insert $null isa null, has null \"null\";").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); statement = gen.generateMatchInsertStatement(Util.parseCSV(iterator.next())); - tmp = "match\n" + + tmp = TypeQL.parseQuery("match\n" + "$player-0 isa person, has phone-number \"+261 860 539 4754\";\n" + "$player-1-1 isa person, has phone-number \"+261 860 539 4754\";\n" + "$player-1 (caller: $player-1-0, callee: $player-1-1) isa call;\n" + - "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;"; - Assert.assertEquals(tmp, statement.toString()); + "insert $rel (peer: $player-0, past-call: $player-1) isa communication-channel;").asInsert(); + Assert.assertEquals(tmp, statement); Assert.assertFalse(gen.relationInsertStatementValid(statement)); } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java b/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java index 8f23774..4c998b9 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java @@ -63,7 +63,8 @@ public void loadPhoneCallsTest() { "-c", dcPath, "-db", databaseName, "-tdb", typeDBUri, - "-cm" + "-cm", + "--allowMultiInsert" // TODO we shouldn't be using this to make the tests pass... }; TypeDBLoader typeDBLoader = new TypeDBLoader(LoadOptions.parse(args)); typeDBLoader.load();